From: Ketmar Dark Date: Thu, 7 Apr 2016 03:25:22 +0000 (+0300) Subject: NPOT *REALLY* fixed this time; also, added menu option X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=b93d2d75ccf3cdfb28b1f143d29a0e451ac08735;p=d2df-sdl.git NPOT *REALLY* fixed this time; also, added menu option --- diff --git a/src/engine/e_textures.pas b/src/engine/e_textures.pas index af38f3c..e7bcbcf 100644 --- a/src/engine/e_textures.pas +++ b/src/engine/e_textures.pas @@ -18,10 +18,9 @@ type end; var - fUseMipmaps: Boolean = False; TEXTUREFILTER: Integer = GL_NEAREST; -function CreateTexture(var tex: GLTexture; Width, Height, Format: Word; pData: Pointer ): Boolean; +function CreateTexture(var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer ): Boolean; // Standard set of images loading functions function LoadTexture( Filename: String; var Texture: GLTexture; @@ -38,7 +37,7 @@ function LoadTextureMemEx( pData: Pointer; var Texture: GLTexture; implementation -uses BinEditor; +uses BinEditor, g_options; function AlignP2 (n: Word): Word; @@ -69,23 +68,30 @@ type end; // This is auxiliary function that creates OpenGL texture from raw image data -function CreateTexture (var tex: GLTexture; Width, Height, Format: Word; pData: Pointer): Boolean; +function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer): Boolean; var Texture: GLuint; begin tex.width := Width; tex.height := Height; - tex.glwidth := AlignP2(Width); - tex.glheight := AlignP2(Height); - if (tex.glwidth = tex.glwidth) and (tex.glheight = tex.height) then + if glLegacyNPOT then begin - tex.u := 1; - tex.v := 1; + tex.glwidth := AlignP2(Width); + tex.glheight := AlignP2(Height); end else begin - tex.u := (tex.width+0.0)/(tex.glwidth+0.0); - tex.v := (tex.height+0.0)/(tex.height+0.0); + tex.glwidth := Width; + tex.glheight := Height; + end; + tex.u := 1; + tex.v := 1; + if tex.glwidth <> tex.width then tex.u := (tex.width+0.0)/(tex.glwidth+0.0); + if tex.glheight <> tex.height then tex.v := (tex.height+0.0)/(tex.glheight+0.0); + + if (tex.glwidth <> tex.width) or (tex.glheight <> tex.height) then + begin + e_WriteLog(Format('NPOT: orig is %ux%u; gl is %ux%u; u=%f; v=%f', [Width, Height, tex.glwidth, tex.glheight, tex.u, tex.v]), MSG_NOTIFY); end; glGenTextures(1, @Texture); @@ -113,15 +119,15 @@ begin glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TEXTUREFILTER); // create empty texture - if Format = GL_RGBA then + if aFormat = GL_RGBA then begin glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.glwidth, tex.glheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, tex.glheight-Height, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData); end else begin glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.glwidth, tex.glheight, 0, GL_RGB, GL_UNSIGNED_BYTE, nil); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, tex.glheight-Height, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData); end; // the following is ok too @@ -131,7 +137,7 @@ begin { if (tex.glwidth = tex.glwidth) and (tex.glheight = tex.height) then // easy case - if Format = GL_RGBA then + if aFormat = GL_RGBA then begin glTexImage2D(GL_TEXTURE_2D, 0, 4, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pData); end diff --git a/src/game/g_language.pas b/src/game/g_language.pas index b1513f1..dbeb7d0 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -222,6 +222,7 @@ type I_MENU_VIDEO_BPP, I_MENU_VIDEO_VSYNC, I_MENU_VIDEO_FILTER_SKY, + I_MENU_VIDEO_LEGACY_COMPATIBLE, I_MENU_VIDEO_NEED_RESTART, I_MENU_RESOLUTION_SELECT, @@ -1000,6 +1001,8 @@ const 'Âåðò. ñèíõðîíèçàöèÿ:'), ('MENU VIDEO FILTER SKY', 'Anisotropic sky', 'Ôèëüòðàöèÿ íåáà:'), + ('MENU VIDEO LEGACY COMPATIBLE', 'Compatibility with NPOT textures:', + 'Ñîâìåñòèìîñòü ñ NPOT-òåêñòóðàìè:'), ('MENU VIDEO NEED RESTART', 'Video settings will be changed after game restart.', 'Äàííûå íàñòðîéêè âèäåî âñòóïÿò â ñèëó ïîñëå ïåðåçàïóñêà èãðû.'), diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 5c0452e..0ac3606 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -49,6 +49,7 @@ begin gBPP := 32; gVSync := TGUISwitch(menu.GetControl('swVSync')).ItemIndex = 0; gTextureFilter := TGUISwitch(menu.GetControl('swTextureFilter')).ItemIndex = 0; + glLegacyNPOT := not (TGUISwitch(menu.GetControl('swLegacyNPOT')).ItemIndex = 0); menu := TGUIMenu(g_GUI_GetWindow('OptionsSoundMenu').GetControl('mOptionsSoundMenu')); @@ -214,6 +215,9 @@ begin with TGUISwitch(menu.GetControl('swVSync')) do if gVSync then ItemIndex := 0 else ItemIndex := 1; + with TGUISwitch(menu.GetControl('swLegacyNPOT')) do + if not glLegacyNPOT then ItemIndex := 0 else ItemIndex := 1; + menu := TGUIMenu(g_GUI_GetWindow('OptionsSoundMenu').GetControl('mOptionsSoundMenu')); TGUIScroll(menu.GetControl('scSoundLevel')).Value := Round(gSoundLevel/16); @@ -2333,6 +2337,12 @@ begin AddItem(_lc[I_MENU_YES]); AddItem(_lc[I_MENU_NO]); end; + with AddSwitch(_lc[I_MENU_VIDEO_LEGACY_COMPATIBLE]) do + begin + Name := 'swLegacyNPOT'; + AddItem(_lc[I_MENU_NO]); + AddItem(_lc[I_MENU_YES]); + end; AddSpace(); AddText(_lc[I_MENU_VIDEO_NEED_RESTART], Round(gScreenWidth*0.6)); ReAlign(); diff --git a/src/game/g_options.pas b/src/game/g_options.pas index fab3028..f6ffc77 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -52,6 +52,7 @@ var gFullscreen: Boolean = False; gWinMaximized: Boolean = False; gVSync: Boolean = False; + glLegacyNPOT: Boolean = False; gTextureFilter: Boolean = True; gNoSound: Boolean = False; gSoundLevel: Byte = 75; @@ -207,7 +208,7 @@ begin gBPP := 32; gVSync := False; gTextureFilter := True; - fUseMipmaps := False; + glLegacyNPOT := False; Exit; end; @@ -232,7 +233,7 @@ begin gFreq := config.ReadInt('Video', 'Freq', 0); gVSync := config.ReadBool('Video', 'VSync', True); gTextureFilter := config.ReadBool('Video', 'TextureFilter', True); - fUseMipmaps := config.ReadBool('Video', 'LegacyCompatible', False); + glLegacyNPOT := config.ReadBool('Video', 'LegacyCompatible', False); gNoSound := config.ReadBool('Sound', 'NoSound', False); gSoundLevel := Min(config.ReadInt('Sound', 'SoundLevel', 75), 255); @@ -441,7 +442,7 @@ begin config.WriteInt('Video', 'BPP', gBPP); config.WriteBool('Video', 'VSync', gVSync); config.WriteBool('Video', 'TextureFilter', gTextureFilter); - config.WriteBool('Video', 'LegacyCompatible', fUseMipmaps); + config.WriteBool('Video', 'LegacyCompatible', glLegacyNPOT); config.WriteBool('Sound', 'NoSound', gNoSound); config.WriteInt('Sound', 'SoundLevel', gSoundLevel);