X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Frenders%2Fopengl%2Fr_textures.pas;h=56d2656c8c17e0e556e70e8525fc06e7e718537e;hb=d0374fd617aa1703e4aa31b8ff3b0f5228636021;hp=34b5b9e7027c8863ad32a0777d22297047fb5dc2;hpb=203d8922aa34a34fb63e312691c711c419c34ae1;p=d2df-sdl.git diff --git a/src/game/renders/opengl/r_textures.pas b/src/game/renders/opengl/r_textures.pas index 34b5b9e..56d2656 100644 --- a/src/game/renders/opengl/r_textures.pas +++ b/src/game/renders/opengl/r_textures.pas @@ -18,11 +18,7 @@ unit r_textures; interface uses - {$IFDEF USE_GLES1} - GLES11, - {$ELSE} - GL, GLEXT, - {$ENDIF} + {$I ../../../nogl/noGLuses.inc} g_base, g_animations, // TRectHW, TAnimInfo utils, r_atlas, r_fonts @@ -139,6 +135,8 @@ interface function r_Textures_LoadFontFromFile (const filename: AnsiString; constref f: TFontInfo; font2enc: TConvProc; log: Boolean = true): TGLFont; + procedure r_Textures_GL_Bind (id: GLuint); + implementation uses @@ -154,6 +152,16 @@ implementation r_GL_RepeatOpt: Boolean; maxTileSize: Integer; atl, ratl: array of TGLAtlas; + currentTexture2D: GLuint; + + procedure r_Textures_GL_Bind (id: GLuint); + begin + if id <> currentTexture2D then + begin + glBindTexture(GL_TEXTURE_2D, id); + currentTexture2D := id; + end + end; (* --------- TGLAtlasNode --------- *) @@ -185,9 +193,9 @@ implementation ASSERT(n.l + x + w - 1 <= n.r); ASSERT(n.t + y + h - 1 <= n.b); ASSERT(n.id > 0); - glBindTexture(GL_TEXTURE_2D, n.id); + r_Textures_GL_Bind(n.id); glTexSubImage2D(GL_TEXTURE_2D, 0, n.l + x, n.t + y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data); - glBindTexture(GL_TEXTURE_2D, 0); + r_Textures_GL_Bind(0); end; (* --------- TGLAtlas --------- *) @@ -221,13 +229,13 @@ implementation glGenTextures(1, @id); if id <> 0 then begin - glBindTexture(GL_TEXTURE_2D, id); + r_Textures_GL_Bind(id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil); - glBindTexture(GL_TEXTURE_2D, 0); + r_Textures_GL_Bind(0); end; result := id end; @@ -457,7 +465,8 @@ implementation begin // auto, max possible reccomended by driver glGetIntegerv(GL_MAX_TEXTURE_SIZE, @size); - if size < 1 then size := 64; + size := size div 2; (* hack: on some devices max size may produce invalid texture *) + if size < 64 then size := 64; (* at least 64x64 are guarantied by specification *) end else begin @@ -472,8 +481,9 @@ implementation procedure r_Textures_Initialize; begin + currentTexture2D := 0; maxTileSize := r_Textures_GetMaxHardwareSize(); - e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize]); + e_LogWritefln('Texture Tile Size: %s', [maxTileSize]); end; procedure r_Textures_Finalize; @@ -483,9 +493,12 @@ implementation begin for i := 0 to High(atl) do begin - glDeleteTextures(1, @atl[i].id); - atl[i].id := 0; - r_Common_FreeAndNil(atl[i]); + if atl[i] <> nil then + begin + glDeleteTextures(1, @atl[i].id); + atl[i].id := 0; + r_Common_FreeAndNil(atl[i]); + end; end; end; SetLength(atl, 0); @@ -494,9 +507,12 @@ implementation begin for i := 0 to High(ratl) do begin - glDeleteTextures(1, @ratl[i].id); - ratl[i].id := 0; - r_Common_FreeAndNil(ratl[i]); + if ratl[i] <> nil then + begin + glDeleteTextures(1, @ratl[i].id); + ratl[i].id := 0; + r_Common_FreeAndNil(ratl[i]); + end; end; end; SetLength(ratl, 0); @@ -635,7 +651,7 @@ implementation end; end; - function r_Textures_LoadTextFromMemory (data: Pointer; size: LongInt; var txt: TAnimTextInfo): Boolean; + function r_Textures_LoadTextFromMemory (data: Pointer; size: LongInt; var text: TAnimTextInfo): Boolean; var cfg: TConfig; begin result := false; @@ -644,15 +660,23 @@ implementation cfg := TConfig.CreateMem(data, size); if cfg <> nil then begin - txt.name := cfg.ReadStr('', 'resource', ''); - txt.w := MAX(0, cfg.ReadInt('', 'framewidth', 0)); - txt.h := MAX(0, cfg.ReadInt('', 'frameheight', 0)); - txt.anim.loop := true; - txt.anim.delay := MAX(0, cfg.ReadInt('', 'waitcount', 0)); - txt.anim.frames := MAX(0, cfg.ReadInt('', 'framecount', 0)); - txt.anim.back := cfg.ReadBool('', 'backanim', false); + text.name := cfg.ReadStr('', 'resource', ''); + text.w := cfg.ReadInt('', 'framewidth', 0); + text.h := cfg.ReadInt('', 'frameheight', 0); + text.anim.loop := true; + text.anim.delay := cfg.ReadInt('', 'waitcount', 0); + text.anim.frames := cfg.ReadInt('', 'framecount', 0); + text.anim.back := cfg.ReadBool('', 'backanim', false); + if text.w <= 0 then e_LogWritefln('Warning: bad animation width %s for %s', [text.w, text.name]); + if text.h <= 0 then e_LogWritefln('Warning: bad animation height %s for %s', [text.h, text.name]); + if text.anim.delay <= 0 then e_LogWritefln('Warning: bad animation delay %s for %s', [text.anim.delay, text.name]); + if text.anim.frames <= 0 then e_LogWritefln('Warning: bad animation frame count %s for %s', [text.anim.frames, text.name]); + text.w := MAX(0, text.w); + text.h := MAX(0, text.h); + text.anim.delay := MAX(1, text.anim.delay); + text.anim.frames := MAX(1, text.anim.frames); cfg.Free; - result := (txt.name <> '') and (txt.w > 0) and (txt.h > 0) and (txt.anim.delay > 0) and (txt.anim.frames > 0); + result := (text.name <> '') and (text.w > 0) and (text.h > 0) and (text.anim.delay > 0) and (text.anim.frames > 0); end; end; end;