From: DeaDDooMER Date: Wed, 9 Jun 2021 12:52:24 +0000 (+0300) Subject: render: completely remove opengl calls form game code X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=9615ae96661aed9886424c75479d322f555627a6;p=d2df-sdl.git render: completely remove opengl calls form game code --- diff --git a/src/engine/e_texture.pas b/src/engine/e_texture.pas index 3e578c8..58ae4cd 100644 --- a/src/engine/e_texture.pas +++ b/src/engine/e_texture.pas @@ -36,18 +36,17 @@ type var e_DummyTextures: Boolean = False; - TEXTUREFILTER: Integer = GL_NEAREST; -function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer): Boolean; +function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer; filter: Boolean = False): Boolean; // Standard set of images loading functions -function LoadTexture (Filename: String; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil): Boolean; -function LoadTextureEx (Filename: String; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil): Boolean; -function LoadTextureMem (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil): Boolean; -function LoadTextureMemEx (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTexture (Filename: String; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; +function LoadTextureEx (Filename: String; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; +function LoadTextureMem (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; +function LoadTextureMemEx (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; // `img` must be valid! -function LoadTextureImg (var img: TImageData; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTextureImg (var img: TImageData; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; implementation @@ -70,12 +69,13 @@ end; // This is auxiliary function that creates OpenGL texture from raw image data -function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer): Boolean; +function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer; filter: Boolean = False): Boolean; var Texture: GLuint; fmt: GLenum; //buf: PByte; //f, c: Integer; + TEXTUREFILTER: Integer; begin tex.width := Width; tex.height := Height; @@ -125,6 +125,8 @@ begin GL_LINEAR_MIPMAP_LINEAR - BiLinear Mipmapped texture } + if filter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST; + // for GL_TEXTURE_MAG_FILTER only first two can be used glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TEXTUREFILTER); // for GL_TEXTURE_MIN_FILTER all of the above can be used @@ -170,7 +172,7 @@ begin end; // `img` must be valid! -function LoadTextureImg (var img: TImageData; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTextureImg (var img: TImageData; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; var image, ii: PByte; width, height: Integer; @@ -209,7 +211,7 @@ begin ii^ := clr.a; Inc(ii); end; end; - CreateTexture(Texture, width, height, GL_RGBA, image); + CreateTexture(Texture, width, height, GL_RGBA, image, filter); result := true; finally FreeMem(image); @@ -217,7 +219,7 @@ begin end; -function LoadTextureMem (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTextureMem (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; var //image, ii: PByte; //width, height: Integer; @@ -238,14 +240,14 @@ begin exit; end; try - result := LoadTextureImg(img, Texture, pWidth, pHeight, Fmt); + result := LoadTextureImg(img, Texture, pWidth, pHeight, Fmt, filter); finally FreeImage(img); end; end; -function LoadTextureMemEx (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTextureMemEx (pData: Pointer; dataSize: LongInt; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; var image, ii: PByte; //width, height: Integer; @@ -291,7 +293,7 @@ begin ii^ := clr.a; Inc(ii); end; end; - CreateTexture(Texture, fWidth, fHeight, GL_RGBA, image); + CreateTexture(Texture, fWidth, fHeight, GL_RGBA, image, filter); result := true; finally FreeMem(image); @@ -302,7 +304,7 @@ begin end; -function LoadTexture (filename: AnsiString; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTexture (filename: AnsiString; var Texture: GLTexture; var pWidth, pHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; var fs: TStream; img: Pointer; @@ -330,7 +332,7 @@ begin GetMem(img, imageSize); try fs.readBuffer(img^, imageSize); - result := LoadTextureMem(img, imageSize, Texture, pWidth, pHeight, Fmt); + result := LoadTextureMem(img, imageSize, Texture, pWidth, pHeight, Fmt, filter); finally FreeMem(img); end; @@ -340,7 +342,7 @@ begin end; -function LoadTextureEx (filename: AnsiString; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil): Boolean; +function LoadTextureEx (filename: AnsiString; var Texture: GLTexture; fX, fY, fWidth, fHeight: Word; Fmt: PWord=nil; filter: Boolean = False): Boolean; var fs: TStream; img: Pointer; @@ -366,7 +368,7 @@ begin GetMem(img, imageSize); try fs.readBuffer(img^, imageSize); - result := LoadTextureMemEx(img, imageSize, Texture, fX, fY, fWidth, fHeight, Fmt); + result := LoadTextureMemEx(img, imageSize, Texture, fX, fY, fWidth, fHeight, Fmt, filter); finally FreeMem(img); end; diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index b18fae8..4a8a26b 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -34,8 +34,6 @@ uses geom in '../shared/geom.pas', math, -{$INCLUDE ../nogl/noGLuses.inc} - {$IFDEF USE_MINIUPNPC} miniupnpc in '../lib/miniupnpc/miniupnpc.pas', {$ENDIF} diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 5d40930..058726b 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -433,7 +433,6 @@ function gPause (): Boolean; inline; implementation uses -{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, {$ENDIF} @@ -835,10 +834,8 @@ begin MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', ''); if MegaWAD.endpic <> '' then begin - TEXTUREFILTER := GL_LINEAR; s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD); - g_Texture_CreateWADEx('TEXTURE_endpic', s); - TEXTUREFILTER := GL_NEAREST; + g_Texture_CreateWADEx('TEXTURE_endpic', s, gTextureFilter); end; MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ'); if MegaWAD.endmus <> '' then @@ -1108,12 +1105,10 @@ begin sfsGCDisable(); // temporary disable removing of temporary volumes try - TEXTUREFILTER := GL_LINEAR; - g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE'); - g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER'); - g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN'); - g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU'); - TEXTUREFILTER := GL_NEAREST; + g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE', gTextureFilter); + g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER', gTextureFilter); + g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN', gTextureFilter); + g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU', gTextureFilter); LoadStdFont('STDTXT', 'STDFONT', gStdFont); LoadFont('MENUTXT', 'MENUFONT', gMenuFont); diff --git a/src/game/g_main.pas b/src/game/g_main.pas index a9c986e..3da02c2 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -53,7 +53,6 @@ var implementation uses -{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, sdlcarcass, fui_ctls, fui_wadread, fui_style, fui_gfx_gl, {$ENDIF} diff --git a/src/game/g_map.pas b/src/game/g_map.pas index a6e1dab..5044657 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -246,7 +246,6 @@ var implementation uses - {$INCLUDE ../nogl/noGLuses.inc} e_input, g_main, e_log, e_texture, e_res, g_items, g_gfx, g_console, g_weapons, g_game, g_sound, e_sound, CONFIG, g_options, g_triggers, g_player, @@ -2203,16 +2202,11 @@ begin begin e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, TMsgType.Notify); g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False); - if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST; - try - s := e_GetResourcePath(WadDirs, gMapInfo.SkyName, g_ExtractWadName(Res)); - if g_Texture_CreateWAD(BackID, s) then - g_Game_SetupScreenSize - else - g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s])) - finally - TEXTUREFILTER := GL_NEAREST; - end; + s := e_GetResourcePath(WadDirs, gMapInfo.SkyName, g_ExtractWadName(Res)); + if g_Texture_CreateWAD(BackID, s, gTextureFilter) then + g_Game_SetupScreenSize + else + g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s])) end; // Çàãðóçêà ìóçûêè diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index 6417fa9..773260f 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -85,9 +85,9 @@ type end; -function g_Texture_CreateWAD (var ID: LongWord; const Resource: AnsiString): Boolean; +function g_Texture_CreateWAD (var ID: LongWord; const Resource: AnsiString; filterHint: Boolean = False): Boolean; function g_Texture_CreateFile (var ID: LongWord; const FileName: AnsiString): Boolean; -function g_Texture_CreateWADEx (const textureName, Resource: AnsiString): Boolean; +function g_Texture_CreateWADEx (const textureName, Resource: AnsiString; filterHint: Boolean = False): Boolean; function g_Texture_CreateFileEx (const textureName, FileName: AnsiString): Boolean; function g_Texture_Get (const textureName: AnsiString; var ID: LongWord): Boolean; function g_Texture_GetSize (const textureName: AnsiString; var w, h: Integer): Boolean; overload; @@ -112,13 +112,10 @@ procedure g_Frames_DeleteAll (); procedure DumpTextureNames (); -function g_Texture_Light (): Integer; - implementation uses - {$INCLUDE ../nogl/noGLuses.inc} g_game, e_log, g_basic, g_console, wadreader, g_language, utils, xstreams; @@ -205,7 +202,7 @@ end; // ////////////////////////////////////////////////////////////////////////// // -function g_Texture_CreateWAD (var ID: LongWord; const Resource: AnsiString): Boolean; +function g_Texture_CreateWAD (var ID: LongWord; const Resource: AnsiString; filterHint: Boolean = False): Boolean; var WAD: TWADFile; FileName: AnsiString; @@ -220,7 +217,7 @@ begin if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then begin - if e_CreateTextureMem(TextureData, ResourceLength, ID) then + if e_CreateTextureMem(TextureData, ResourceLength, ID, filterHint) then result := true; FreeMem(TextureData) end @@ -244,7 +241,7 @@ begin end; -function g_Texture_CreateWADEx (const textureName, Resource: AnsiString): Boolean; +function g_Texture_CreateWADEx (const textureName, Resource: AnsiString; filterHint: Boolean = False): Boolean; var WAD: TWADFile; FileName: AnsiString; @@ -261,7 +258,7 @@ begin if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then begin - result := e_CreateTextureMem(TextureData, ResourceLength, texturesArray[find_id].ID); + result := e_CreateTextureMem(TextureData, ResourceLength, texturesArray[find_id].ID, filterHint); if result then begin e_GetTextureSize(texturesArray[find_id].ID, @texturesArray[find_id].width, @texturesArray[find_id].height); @@ -910,66 +907,4 @@ begin mRevert := utils.readBool(st); end; - -// ////////////////////////////////////////////////////////////////////////// // -var - ltexid: GLuint = 0; - -function g_Texture_Light (): Integer; -const - Radius: Integer = 128; -var - tex, tpp: PByte; - x, y, a: Integer; - dist: Double; -begin - if ltexid = 0 then - begin - GetMem(tex, (Radius*2)*(Radius*2)*4); - tpp := tex; - for y := 0 to Radius*2-1 do - begin - for x := 0 to Radius*2-1 do - begin - dist := 1.0-sqrt((x-Radius)*(x-Radius)+(y-Radius)*(y-Radius))/Radius; - if (dist < 0) then - begin - tpp^ := 0; Inc(tpp); - tpp^ := 0; Inc(tpp); - tpp^ := 0; Inc(tpp); - tpp^ := 0; Inc(tpp); - end - else - begin - //tc.setPixel(x, y, Color(cast(int)(dist*255), cast(int)(dist*255), cast(int)(dist*255))); - if (dist > 0.5) then dist := 0.5; - a := round(dist*255); - if (a < 0) then a := 0 else if (a > 255) then a := 255; - tpp^ := 255; Inc(tpp); - tpp^ := 255; Inc(tpp); - tpp^ := 255; Inc(tpp); - tpp^ := Byte(a); Inc(tpp); - end; - end; - end; - - glGenTextures(1, @ltexid); - //if (tid == 0) assert(0, "VGL: can't create screen texture"); - - glBindTexture(GL_TEXTURE_2D, ltexid); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - //GLfloat[4] bclr = 0.0; - //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Radius*2, Radius*2, 0, GL_RGBA{gltt}, GL_UNSIGNED_BYTE, tex); - end; - - result := ltexid; -end; - - end. diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index 6260d48..8acd51b 100644 --- a/src/game/opengl/r_game.pas +++ b/src/game/opengl/r_game.pas @@ -1028,6 +1028,65 @@ begin e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a); end; +// ////////////////////////////////////////////////////////////////////////// // +var + ltexid: GLuint = 0; + +function g_Texture_Light (): Integer; +const + Radius: Integer = 128; +var + tex, tpp: PByte; + x, y, a: Integer; + dist: Double; +begin + if ltexid = 0 then + begin + GetMem(tex, (Radius*2)*(Radius*2)*4); + tpp := tex; + for y := 0 to Radius*2-1 do + begin + for x := 0 to Radius*2-1 do + begin + dist := 1.0-sqrt((x-Radius)*(x-Radius)+(y-Radius)*(y-Radius))/Radius; + if (dist < 0) then + begin + tpp^ := 0; Inc(tpp); + tpp^ := 0; Inc(tpp); + tpp^ := 0; Inc(tpp); + tpp^ := 0; Inc(tpp); + end + else + begin + //tc.setPixel(x, y, Color(cast(int)(dist*255), cast(int)(dist*255), cast(int)(dist*255))); + if (dist > 0.5) then dist := 0.5; + a := round(dist*255); + if (a < 0) then a := 0 else if (a > 255) then a := 255; + tpp^ := 255; Inc(tpp); + tpp^ := 255; Inc(tpp); + tpp^ := 255; Inc(tpp); + tpp^ := Byte(a); Inc(tpp); + end; + end; + end; + + glGenTextures(1, @ltexid); + //if (tid == 0) assert(0, "VGL: can't create screen texture"); + + glBindTexture(GL_TEXTURE_2D, ltexid); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + //GLfloat[4] bclr = 0.0; + //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Radius*2, Radius*2, 0, GL_RGBA{gltt}, GL_UNSIGNED_BYTE, tex); + end; + + result := ltexid; +end; // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this! //FIXME: broken for splitscreen mode diff --git a/src/game/opengl/r_graphics.pas b/src/game/opengl/r_graphics.pas index f7b7fd3..cb568b4 100644 --- a/src/game/opengl/r_graphics.pas +++ b/src/game/opengl/r_graphics.pas @@ -66,8 +66,8 @@ procedure e_DarkenQuadWH (x, y, w, h: Integer; a: Integer); function e_CreateTextureImg (var img: TImageData; var ID: DWORD): Boolean; function e_CreateTexture(FileName: string; var ID: DWORD): Boolean; function e_CreateTextureEx(FileName: string; var ID: DWORD; fX, fY, fWidth, fHeight: Word): Boolean; -function e_CreateTextureMem(pData: Pointer; dataSize: LongInt; var ID: DWORD): Boolean; -function e_CreateTextureMemEx(pData: Pointer; dataSize: LongInt; var ID: DWORD; fX, fY, fWidth, fHeight: Word): Boolean; +function e_CreateTextureMem(pData: Pointer; dataSize: LongInt; var ID: DWORD; filter: Boolean = False): Boolean; +function e_CreateTextureMemEx(pData: Pointer; dataSize: LongInt; var ID: DWORD; fX, fY, fWidth, fHeight: Word; filter: Boolean = False): Boolean; procedure e_GetTextureSize(ID: DWORD; Width, Height: PWord); procedure e_DeleteTexture(ID: DWORD); procedure e_RemoveAllTextures(); @@ -293,7 +293,7 @@ begin Result := True; end; -function e_CreateTextureMem(pData: Pointer; dataSize: LongInt; var ID: DWORD): Boolean; +function e_CreateTextureMem(pData: Pointer; dataSize: LongInt; var ID: DWORD; filter: Boolean = False): Boolean; var find_id: DWORD; fmt: Word; @@ -302,14 +302,14 @@ begin find_id := FindTexture; - if not LoadTextureMem(pData, dataSize, e_Textures[find_id].tx, e_Textures[find_id].tx.Width, e_Textures[find_id].tx.Height, @fmt) then exit; + if not LoadTextureMem(pData, dataSize, e_Textures[find_id].tx, e_Textures[find_id].tx.Width, e_Textures[find_id].tx.Height, @fmt, filter) then exit; id := find_id; Result := True; end; -function e_CreateTextureMemEx(pData: Pointer; dataSize: LongInt; var ID: DWORD; fX, fY, fWidth, fHeight: Word): Boolean; +function e_CreateTextureMemEx(pData: Pointer; dataSize: LongInt; var ID: DWORD; fX, fY, fWidth, fHeight: Word; filter: Boolean = False): Boolean; var find_id: DWORD; fmt: Word; @@ -318,7 +318,7 @@ begin find_id := FindTexture(); - if not LoadTextureMemEx(pData, dataSize, e_Textures[find_id].tx, fX, fY, fWidth, fHeight, @fmt) then exit; + if not LoadTextureMemEx(pData, dataSize, e_Textures[find_id].tx, fX, fY, fWidth, fHeight, @fmt, filter) then exit; ID := find_id;