WIP: OpenGL water refraction

tries to replicate the effect from software renderer
this is quite a mess, but finally feel like pushing this since i finally figured out the depth testing stuff
this still has some issues:
-map geometry in front of skybox water will just draw over it completely (not super sure how to fix this other than deferring water rendering after rendering both skybox and normal scene)
-translucent geometry is not included in refraction (and may draw in front of it?), software also suffers from this in certain cases, i just hope its not that visible

this really needs a cleanup at some point
and due to how this is setup for floor and ceiling planes this also costs quite a lot of gpu time (atleast on the cpu side this costs barely anything)
This commit is contained in:
alufolie91 committed 2026-07-14 09:46:19 +02:00
1 parent 3d0b3e9471
commit b85a4b3034
9 files changed
+380 -11

No files matched your search

+1
View File
@@ -192,6 +192,7 @@ enum
SHADER_SPRITE,
SHADER_MODEL,
SHADER_WATER,
SHADER_WATERREFRACT,
SHADER_FOG,
SHADER_SKY,
SHADER_PALETTE_POSTPROCESS,
+1
View File
@@ -39,6 +39,7 @@ void GL_EnableStencilTest(void);
void GL_DisableStencilTest(void);
void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags);
void GL_DrawWaterPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader);
void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray);
void GL_Draw2DLine(F2DCoord *v1, F2DCoord *v2, RGBA_t Color);
+160 -2
View File
@@ -103,6 +103,8 @@ static constexpr INT32 bsp_culling_distances[] = {
// Performance stats
ps_metric_t ps_hw_nodesorttime = {};
ps_metric_t ps_hw_nodedrawtime = {};
ps_metric_t ps_hw_waterdrawtime = {};
ps_metric_t ps_hw_spritesorttime = {};
ps_metric_t ps_hw_spritedrawtime = {};
@@ -724,14 +726,26 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
if (PolyFlags & PF_Fog)
shader = SHADER_FOG;
else if (cv_ripplewater.value && (PolyFlags & PF_Ripple))
{
shader = SHADER_WATER;
// handle water refraction
// this is not needed on opague water at all
// FIXME: this is ugly
if (alpha < 255)
{
shader = SHADER_WATERREFRACT;
GL_DrawWaterPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags|PF_ColorMapped, shader);
}
}
else
shader = SHADER_FLOOR;
PolyFlags |= PF_ColorMapped;
}
HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false);
if (shader != SHADER_WATERREFRACT)
HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false);
if (gl_maphashorizonlines && subsector && cv_glhorizonlines.value)
{
@@ -812,7 +826,10 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
horizonpts[4].y = gl_viewz;
// Draw
HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true);
if (shader == SHADER_WATERREFRACT)
GL_DrawWaterPolygon(&Surf, horizonpts, 6, PolyFlags, shader);
else
HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true);
}
}
}
@@ -4291,6 +4308,14 @@ static void HWR_RenderDrawNodes(void)
{
planeinfo_t *plane = &drawnode->u.plane;
// if its a water plane
// we draw them seperately before...
// this has to be done so both ceiling and floor can be included in the refraction part
if (cv_ripplewater.value && plane->alpha < 255 && plane->blend & PF_Ripple)
{
break;
}
// We aren't traversing the BSP tree, so make gl_frontsector null to avoid crashes.
gl_frontsector = NULL;
@@ -4337,6 +4362,128 @@ static void HWR_RenderDrawNodes(void)
drawnodes.clear(); // clear so our size is 0 again!
}
static void HWR_RenderRefractionWater(void)
{
// TODO: defer water plane render to happen after EVERYTHING
// otherwise skybox water cant capture the map geometry properly
// so the map may draw over the water plane in some cases
// see hadal trench
// didnt notice any other map besides this, yet.....
// all this bullshit
// just so either ceiling or floor planes can be captured in the opposite plane........
// sincerely im not sure if the performance tradeoff is worth it
// considering most water floors in a water fof with a ceiling (or vice versa) are mapping oversights
// but ig this is technically more "correct" (this all sucks massive ass regardless sned help)
// caveat with all of this is
// some translucent things behind water planes may not get the refraction...
// i have no clue how to ever fix that (maybe another pass with more depth compares? kinda wonder if we even need the whole drawnode thing in gl anyways)
// but it seems like software also suffers from this in some cases
static std::vector<gl_drawnode_t> waterdrawnodes;
const size_t numdrawnodes = drawnodes.size();
// no drawnodes...
if (!numdrawnodes)
return;
waterdrawnodes.reserve(DRAWNODES_INIT_SIZE/2); // surely there will be less water than other stuff, right?
// go through our drawnodes to pull out the water
// HWR_RenderDrawNodes will skip those
// we do this before since trying to capture
// anything translucent in the refraction is utter arse pain
for (size_t w = 0; w < numdrawnodes; w++)
{
gl_drawnode_t *drawnode = &drawnodes[w];
// gotta be a plane duh
if (drawnode->type != DRAWNODE_PLANE)
continue;
planeinfo_t *plane = &drawnode->u.plane;
// this only applies to translucent water with ripple effect!
if (plane->alpha < 255 && plane->blend & PF_Ripple)
{
waterdrawnodes.push_back(drawnodes[w]);
}
}
const size_t numwaterdrawnodes = waterdrawnodes.size();
// no water....
if (!numwaterdrawnodes)
return;
// split floor and ceiling planes of the water fofs
// otherwise the floor might not be visible to the ceiling plane or the other way around
auto waterisfloor = [](const gl_drawnode_t &node) FUNCINLINE
{
return !node.u.plane.isceiling;
};
// stable_partition will move everything the predicate returns true for to the beginning preserving relative order (phew....)
// this is kinda lazy but i dont give a fuck honestly
auto watersplitend = std::stable_partition(waterdrawnodes.begin(), waterdrawnodes.end(), waterisfloor);
// we "could" capture the screen for each plane instead (that would also fix the dumbass sky probably), but man :chaobaba: that even kills my 3080 lmao
// not sure if we *really* need to sort those?
// then again this sorts them relative to the viewheight
// this should mostly mean ceiling above floor
// but this might not always be true?
// tho this shouldnt cost much really
// the below is much worse
qs22j(waterdrawnodes.data(), numwaterdrawnodes, sizeof(gl_drawnode_t), CompareDrawNodePlanes);
// dont want copying screen contents twice
// that shit is kinda costly
boolean floorwater = (watersplitend != waterdrawnodes.begin());
boolean ceilingwater = (watersplitend != waterdrawnodes.end());
// FIXME: i am not sure if we should draw the floor or ceiling planes first
// i am also not sure if that even matters?
// finally draw the wöter
if (floorwater)
{
// gladly we do not need fbos for this...
GL_CopyMainFramebufferTexture();
// floor water
for (auto it = waterdrawnodes.begin(); it != watersplitend; ++it)
{
planeinfo_t *plane = &it->u.plane;
gl_frontsector = NULL;
if (!(plane->blend & PF_NoTexture))
HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling));
HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel,
plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap);
}
}
if (ceilingwater)
{
GL_CopyMainFramebufferTexture();
// ceiling water
for (auto it = watersplitend; it != waterdrawnodes.end(); ++it)
{
planeinfo_t *plane = &it->u.plane;
gl_frontsector = NULL;
if (!(plane->blend & PF_NoTexture))
HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling));
HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel,
plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap);
}
}
waterdrawnodes.clear();
}
// --------------------------------------------------------------------------
// Draw all vissprites
// --------------------------------------------------------------------------
@@ -5622,6 +5769,17 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool
ps_numdrawnodes.value.i = 0;
ps_hw_nodesorttime.value.p = 0;
ps_hw_nodedrawtime.value.p = 0;
ps_hw_waterdrawtime.value.p = 0;
// thisll be a good mess making this toggable
if (cv_ripplewater.value)
{
// should we not do this during portal render?
// wonder how bad the perf will be....
PS_START_TIMING(ps_hw_waterdrawtime);
HWR_RenderRefractionWater();
PS_STOP_TIMING(ps_hw_waterdrawtime);
}
HWR_RenderDrawNodes();
+1
View File
@@ -68,6 +68,7 @@ enum
// Performance stats
extern ps_metric_t ps_hw_nodesorttime;
extern ps_metric_t ps_hw_nodedrawtime;
extern ps_metric_t ps_hw_waterdrawtime;
extern ps_metric_t ps_hw_spritesorttime;
extern ps_metric_t ps_hw_spritedrawtime;
+3
View File
@@ -41,6 +41,9 @@ static struct {
// Water shader
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_WATER_FRAGMENT_SHADER},
// Water refraction shader
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_WATERREFRACT_FRAGMENT_SHADER},
// Fog shader
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_FOG_FRAGMENT_SHADER},
+106
View File
@@ -322,6 +322,112 @@
"}\n" \
"#endif\0"
// water refraction stuff
// what a mess....
//FIXME: add proper scaling instead of 0.05 (this seems to actually work out tho?)
// mix the uhh scene texture with the uhh water plane or smth
// alpha is handled in a dogshit way, and i have no idea why i gotta mix the lighttable shit with it
// but this matches up pretty perfectly somehow
// this is probably complete shit but i dont care
// got the idea for depth testing from https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-refraction.html
#define GLSL_WATERREFRACT_TEXEL \
"float water_z = (gl_FragCoord.z / gl_FragCoord.w) / 2.0;\n" \
"float a = -pi * (water_z * freq) + (leveltime * speed);\n" \
"float sdistort = sin(a) * amp;\n" \
"float cdistort = cos(a) * amp;\n" \
"vec2 uv = gl_FragCoord.xy / scr_resolution;\n" \
"vec2 scene_uv = uv + vec2(sdistort, cdistort) * 0.05;\n" \
"float scenedepth = texture2D(scene_depth_tex, scene_uv).r;\n" \
"vec4 watersurface = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" \
"vec4 scene;\n" \
"vec4 texel;\n" \
"float refractalpha = 0.0;\n" \
"bool pixelinfront = scenedepth < gl_FragCoord.z;\n" \
"if (pixelinfront) {\n" \
"scene = watersurface;\n" \
"texel = watersurface;\n" \
"} else {\n" \
"refractalpha = (watersurface.a * poly_color.a);\n" \
"scene = texture2D(scene_tex, scene_uv);\n" \
"texel = mix(scene, watersurface, refractalpha);\n" \
"}\n"
// copy paste but needs to modify this for palrender stuff
// the refracted mix shouldnt have the actual alpha applied
// as we do this during the mix phase in GLSL_WATERREFRACT_TEXEL
#define GLSL_PALETTEWATER_RENDERING \
"float tex_pal_idx = texture3D(palette_lookup_tex, vec3((watersurface * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \
"float z = gl_FragCoord.z / gl_FragCoord.w;\n" \
"float light_y = clamp(floor(R_DoomColormap(lighting, z, gl_FragCoord.xy)), 0.0, 31.0);\n" \
"vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \
"vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \
"if (pixelinfront) {\n" \
"final_color.a = (texel.a * poly_color.a);\n" \
"} else {\n" \
"final_color = mix(scene, final_color, refractalpha);\n" \
"final_color.a = texel.a;\n" \
"}\n" \
"gl_FragColor = final_color;\n" \
// adjusted values to match software a little better
// original values
//"const float freq = 0.025;\n"
//"const float amp = 0.025;\n"
// adjusted values
//"const float freq = 0.03;\n"
//"const float amp = 0.018;\n"
// this shouldnt distort too much horizontally
// but needs a little more ripples
#define GLSL_WATERREFRACT_FRAGMENT_SHADER \
"#version 120\n" \
GLSL_FLOOR_FUDGES \
"const float freq = 0.03;\n" \
"const float amp = 0.018;\n" \
"const float speed = 2.0;\n" \
"const float pi = 3.14159;\n" \
"#ifdef SRB2_PALETTE_RENDERING\n" \
"uniform sampler2D tex;\n" \
"uniform sampler2D scene_tex;\n" \
"uniform sampler2D scene_depth_tex;\n" \
"uniform sampler3D palette_lookup_tex;\n" \
"uniform sampler2D lighttable_tex;\n" \
"uniform vec4 poly_color;\n" \
"uniform float lighting;\n" \
"uniform float leveltime;\n" \
GLSL_DOOM_COLORMAP \
"void main(void) {\n" \
GLSL_WATERREFRACT_TEXEL \
GLSL_PALETTEWATER_RENDERING \
"}\n" \
"#else\n" \
"uniform sampler2D tex;\n" \
"uniform sampler2D scene_tex;\n" \
"uniform sampler2D scene_depth_tex;\n" \
"uniform vec4 poly_color;\n" \
"uniform vec4 tint_color;\n" \
"uniform vec4 fade_color;\n" \
"uniform float lighting;\n" \
"uniform float fade_start;\n" \
"uniform float fade_end;\n" \
"uniform float leveltime;\n" \
GLSL_DOOM_COLORMAP \
GLSL_DOOM_LIGHT_EQUATION \
"void main(void) {\n" \
GLSL_WATERREFRACT_TEXEL \
"vec4 base_color = texel * poly_color;\n" \
"vec4 final_color = base_color;\n" \
GLSL_SOFTWARE_TINT_EQUATION \
GLSL_SOFTWARE_FADE_EQUATION \
"final_color.a = pixelinfront ? (texel.a * poly_color.a) : texel.a;\n" \
"gl_FragColor = final_color;\n" \
"}\n" \
"#endif\0"
//
// Fog block shader
//
+104 -9
View File
@@ -173,6 +173,15 @@ boolean supportstencil = false;
// can know when the textures aren't there, as textures are always considered resident in their virtual memory
static GLuint screenTextures[NUMSCREENTEXTURES] = {};
// for water refraction
enum
{
SCENE_TEX,
SCENE_DEPTHTEX,
NUMSCENETEXTURES
};
static GLuint sceneTextures[NUMSCENETEXTURES] = {};
#define byte2float(byte) (GLfloat)(byte / 255.0f)
// -----------------+
@@ -723,6 +732,9 @@ typedef enum
gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table
gluniform_lighttable_tex, // 2d texture containing a light table
gluniform_scene_tex,
gluniform_scene_depth_tex,
// misc.
gluniform_leveltime,
@@ -888,7 +900,7 @@ void SetupGLFunc4(void)
{ \
GL_MSG_Warning("failed to get OpenGL FBO function: %s\n", #func); \
GL_DBG_Printf("\nFBO: No framebuffer object support\n"); \
supportFBO = false; \
supportFBO = FBO_NONE; \
return; \
} \
@@ -2384,6 +2396,9 @@ static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i)
// misc.
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
shader->uniforms[gluniform_scene_tex] = GETUNI("scene_tex");
shader->uniforms[gluniform_scene_depth_tex] = GETUNI("scene_depth_tex");
#undef GETUNI
// set permanent uniform values
@@ -2401,6 +2416,9 @@ static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i)
UNIFORM_1(shader->uniforms[gluniform_palette_tex], 2, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_scene_tex], 4, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_scene_depth_tex], 5, pglUniform1i);
#ifdef USE_FBO_OGL
// supersampling crap
UNIFORM_2(shader->uniforms[gluniform_inv_supersamplefactor], InvSupersampleFactorX, InvSupersampleFactorY, pglUniform2f);
@@ -2487,6 +2505,33 @@ void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, F
Clamp2D(GL_TEXTURE_WRAP_T);
}
void GL_DrawWaterPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader)
{
GL_SetShader(HWR_GetShaderFromTarget(shader));
GL_PreparePolygon(pSurf, PolyFlags);
pglActiveTexture(GL_TEXTURE4);
pglBindTexture(GL_TEXTURE_2D, sceneTextures[SCENE_TEX]);
pglActiveTexture(GL_TEXTURE0);
pglActiveTexture(GL_TEXTURE5);
pglBindTexture(GL_TEXTURE_2D, sceneTextures[SCENE_DEPTHTEX]);
pglActiveTexture(GL_TEXTURE0);
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts);
if (PolyFlags & PF_RemoveYWrap)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (PolyFlags & PF_ForceWrapX)
Clamp2D(GL_TEXTURE_WRAP_S);
if (PolyFlags & PF_ForceWrapY)
Clamp2D(GL_TEXTURE_WRAP_T);
}
void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray)
{
GL_PreparePolygon(pSurf, PolyFlags);
@@ -3254,7 +3299,7 @@ void GL_SetTransform(FTransform *stransform)
#ifdef USE_FBO_OGL
static void GL_Framebuffer_DeleteAttachments(void)
{
if (!supportFBO || !framebufferobject.init)
if (supportFBO == FBO_NONE || !framebufferobject.init)
return;
// Unbind the framebuffer
@@ -3274,7 +3319,7 @@ static void GL_Framebuffer_DeleteAttachments(void)
static void GL_Framebuffer_Generate(void)
{
if (!supportFBO || framebufferobject.init || !UseScreenFBO())
if (supportFBO == FBO_NONE || framebufferobject.init || !UseScreenFBO())
return;
// Generate the framebuffer
@@ -3294,10 +3339,10 @@ static void GL_Framebuffer_Generate(void)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Clamp2D(GL_TEXTURE_WRAP_S);
Clamp2D(GL_TEXTURE_WRAP_T);
pglBindTexture(GL_TEXTURE_2D, 0);
// Attach the framebuffer texture to the framebuffer
pglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebufferobject.tex, 0);
pglBindTexture(GL_TEXTURE_2D, 0);
}
// Generate the renderbuffer
@@ -3339,7 +3384,7 @@ static void GL_Framebuffer_Generate(void)
// if this fails, dont retry it a gazillion times
// this wouldnt recover
supportFBO = false;
supportFBO = FBO_NONE;
pglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
return;
}
@@ -3352,7 +3397,7 @@ static void GL_Framebuffer_Generate(void)
void GL_Framebuffer_Unbind(void)
{
if (!supportFBO || !framebufferobject.init)
if (supportFBO == FBO_NONE || !framebufferobject.init)
return;
pglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
@@ -3361,13 +3406,13 @@ void GL_Framebuffer_Unbind(void)
void GL_Framebuffer_Enable(void)
{
if (!supportFBO || !UseScreenFBO())
if (supportFBO == FBO_NONE || !UseScreenFBO())
return;
GL_Framebuffer_Generate();
// failed
if (!supportFBO || !framebufferobject.init)
if (supportFBO == FBO_NONE || !framebufferobject.init)
return;
pglBindFramebuffer(GL_FRAMEBUFFER_EXT, framebufferobject.fboobj);
@@ -3376,7 +3421,7 @@ void GL_Framebuffer_Enable(void)
void GL_Framebuffer_Disable(void)
{
if (!supportFBO || !framebufferobject.init)
if (supportFBO == FBO_NONE || !framebufferobject.init)
return;
pglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
@@ -3391,6 +3436,52 @@ void GL_Framebuffer_Disable(void)
}
#endif
// faster than fbo blitting ig...
// just copies the whole framebuffer as a texture
void GL_CopyMainFramebufferTexture(void)
{
if (!sceneTextures[SCENE_TEX])
{
pglGenTextures(1, &sceneTextures[SCENE_TEX]);
pglBindTexture(GL_TEXTURE_2D, sceneTextures[SCENE_TEX]);
pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Clamp2D(GL_TEXTURE_WRAP_S);
Clamp2D(GL_TEXTURE_WRAP_T);
pglBindTexture(GL_TEXTURE_2D, 0);
}
if (!sceneTextures[SCENE_DEPTHTEX])
{
pglGenTextures(1, &sceneTextures[SCENE_DEPTHTEX]);
pglBindTexture(GL_TEXTURE_2D, sceneTextures[SCENE_DEPTHTEX]);
pglTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, screen_width, screen_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Clamp2D(GL_TEXTURE_WRAP_S);
Clamp2D(GL_TEXTURE_WRAP_T);
pglBindTexture(GL_TEXTURE_2D, 0);
}
// now copy the whole scene
pglBindTexture(GL_TEXTURE_2D, sceneTextures[SCENE_TEX]);
pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen_width, screen_height);
// not sure why, but this is needed
// otherwise bad things happen
tex_downloaded = sceneTextures[SCENE_TEX];
// and copy the depth from the scene
// we need this for depth testing within the shader
// so we can discard stuff in front of the water
// this aint reflections after all!
pglBindTexture(GL_TEXTURE_2D, sceneTextures[SCENE_DEPTHTEX]);
pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen_width, screen_height);
pglBindTexture(GL_TEXTURE_2D, 0);
}
static const float defaultscreenVerts[12] =
{
-1.0f, -1.0f, 1.0f,
@@ -3512,6 +3603,10 @@ void GL_FlushScreenTextures(void)
{
pglDeleteTextures(NUMSCREENTEXTURES, screenTextures);
memset(screenTextures, 0, sizeof(screenTextures));
// gotta wipe the scene textures for the water refraction stuff aswell
pglDeleteTextures(NUMSCENETEXTURES, sceneTextures);
memset(sceneTextures, 0, sizeof(sceneTextures));
}
void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags)
+2
View File
@@ -104,6 +104,8 @@ void GL_Framebuffer_Disable(void);
extern int supportFBO;
#endif
void GL_CopyMainFramebufferTexture(void);
// ==========================================================================
// GLOBAL
// ==========================================================================
+2
View File
@@ -98,6 +98,7 @@ perfstatrow_t rendertime_rows[] = {
{" sprdraw", " Sprite render: ", &ps_hw_spritedrawtime, PS_TIME|PS_LEVEL|PS_HW},
{" nodesrt", " Drwnode sort: ", &ps_hw_nodesorttime, PS_TIME|PS_LEVEL|PS_HW},
{" nodedrw", " Drwnode render:", &ps_hw_nodedrawtime, PS_TIME|PS_LEVEL|PS_HW},
{" wtrdrw", " Water render: ", &ps_hw_waterdrawtime, PS_TIME|PS_LEVEL|PS_HW},
{" other ", " Other: ", &ps_otherrendertime, PS_TIME|PS_LEVEL|PS_HW},
#endif
@@ -536,6 +537,7 @@ static void PS_UpdateFrameStats(void)
ps_skyboxtime.value.p +
ps_hw_nodesorttime.value.p +
ps_hw_nodedrawtime.value.p +
ps_hw_waterdrawtime.value.p +
ps_hw_spritesorttime.value.p +
ps_hw_spritedrawtime.value.p;