Results 1 to 10 of 11

Thread: OpenGL Texture Manager

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    OpenGL Texture Manager

    This is how it's defined on my latest engine:

    Code:
     TTexture = record
        name: string[12];
        sizeX, sizeY, values: word; // values 3 or 4
        index,format: cardinal; // GL_RGB or GL_RGBA
        Data: PByteArray; // size = sizeX*sizeY*values
      end;
      PTexture = ^TTexture;
    
      TTextureLoadOptions = set of (toMipMap, toAlphaColor,
        toKeepData, toAbsoluteSize, toColorKey);
    
      TTextureSet = class
        texture: array of TTexture;
        count, TextureQuality: integer;
        Options: TTextureLoadOptions;
        TransparentColor: TRGBTriple;
      private
        count2: integer;
        function Pow2Limit(var w,h: word; var sx,sy: single): boolean;
        procedure SetCount(n: integer);
      public
        constructor Create;
        destructor Destroy; override;
    // AddTexture creates new item, makes call to LoadTextureData which makes extension check and loads any format that is identified
        function AddTexture(name,filename: string; transparency: boolean = false): integer;
        procedure Clear;
        procedure Disable;
        procedure Enable;
        function IndexOf(name: string): integer;
        function LoadBMPDataFile(tex: PTexture; filename: string): boolean;
        function LoadBMPData(tex: PTexture; bmp: TBitmap): boolean;
        function LoadPNGData(tex: PTexture; filename: string): boolean;
        function LoadJPGData(tex: PTexture; filename: string): boolean;
        function LoadTextureData(tex: PTexture; filename: string): boolean;
        procedure RemoveTexture(n: integer);
        procedure ReloadTexture(n: integer; filename: string; transparency: boolean);
        procedure Restore(tex: PTexture);
        procedure SetTex(n: integer);
      end;
    Also because glBindTexture calls should be minimized as much as possible, this one is used every time (except forced when making displaylists):
    Code:
    implementation
    
    var lastTex: cardinal;
    
    procedure nxSetTex(t: cardinal; force: boolean);
    begin
      if (t<>lastTex) or force then begin
        glBindTexture(GL_TEXTURE_2D,t); 
        lastTex:=t;
      end;
    end;
    Last edited by SilverWarior; 07-05-2019 at 09:25 PM. Reason: Fixed CODE tags

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •