Merge remote-tracking branch 'gzdoom_upstream/master' into lightmath

# Conflicts:
#	src/gl/renderer/gl_postprocess.cpp
#	src/gl/renderer/gl_renderbuffers.cpp
#	src/gl/scene/gl_scene.cpp
This commit is contained in:
Magnus Norddahl 2016-09-02 02:40:44 +02:00
commit 5a0c61a2d5
37 changed files with 425 additions and 466 deletions

View file

@ -1115,6 +1115,7 @@ set( FASTMATH_SOURCES
gl/shaders/gl_bloomshader.cpp gl/shaders/gl_bloomshader.cpp
gl/shaders/gl_ambientshader.cpp gl/shaders/gl_ambientshader.cpp
gl/shaders/gl_blurshader.cpp gl/shaders/gl_blurshader.cpp
gl/shaders/gl_colormapshader.cpp
gl/shaders/gl_tonemapshader.cpp gl/shaders/gl_tonemapshader.cpp
gl/shaders/gl_lensshader.cpp gl/shaders/gl_lensshader.cpp
gl/system/gl_interface.cpp gl/system/gl_interface.cpp

View file

@ -66,40 +66,39 @@
void gl_PatchMenu() void gl_PatchMenu()
{ {
if (gl.glslversion == 0) // Radial fog and Doom lighting are not available without full shader support.
FOptionValues **opt = OptionValues.CheckKey("LightingModes");
if (opt != NULL)
{ {
// Radial fog and Doom lighting are not available without full shader support. for(int i = (*opt)->mValues.Size()-1; i>=0; i--)
FOptionValues **opt = OptionValues.CheckKey("LightingModes");
if (opt != NULL)
{ {
for(int i = (*opt)->mValues.Size()-1; i>=0; i--) // Delete 'Doom' lighting mode
if ((*opt)->mValues[i].Value == 2.0 || (*opt)->mValues[i].Value == 8.0)
{ {
// Delete 'Doom' lighting mode (*opt)->mValues.Delete(i);
if ((*opt)->mValues[i].Value == 2.0 || (*opt)->mValues[i].Value == 8.0)
{
(*opt)->mValues.Delete(i);
}
} }
} }
opt = OptionValues.CheckKey("FogMode");
if (opt != NULL)
{
for(int i = (*opt)->mValues.Size()-1; i>=0; i--)
{
// Delete 'Radial' fog mode
if ((*opt)->mValues[i].Value == 2.0)
{
(*opt)->mValues.Delete(i);
}
}
}
// disable features that don't work without shaders.
if (gl_lightmode == 2 || gl_lightmode == 8) gl_lightmode = 3;
if (gl_fogmode == 2) gl_fogmode = 1;
} }
opt = OptionValues.CheckKey("FogMode");
if (opt != NULL)
{
for(int i = (*opt)->mValues.Size()-1; i>=0; i--)
{
// Delete 'Radial' fog mode
if ((*opt)->mValues[i].Value == 2.0)
{
(*opt)->mValues.Delete(i);
}
}
}
// disable features that don't work without shaders.
if (gl_lightmode == 2 || gl_lightmode == 8) gl_lightmode = 3;
if (gl_fogmode == 2) gl_fogmode = 1;
// todo: remove more unsupported stuff like postprocessing options.
} }
@ -378,7 +377,7 @@ void FRenderState::DrawColormapOverlay()
//========================================================================== //==========================================================================
bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right, bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right,
float & scale, int desaturation, bool checkside, bool additive) float & scale, bool checkside, bool additive)
{ {
Vector fn, pos; Vector fn, pos;
@ -434,14 +433,6 @@ bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt,
{ {
gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendEquation(GL_FUNC_ADD);
} }
if (desaturation > 0 && gl.glslversion > 0) // no-shader excluded because no desaturated textures.
{
float gray = (r * 77 + g * 143 + b * 37) / 257;
r = (r*(32 - desaturation) + gray*desaturation) / 32;
g = (g*(32 - desaturation) + gray*desaturation) / 32;
b = (b*(32 - desaturation) + gray*desaturation) / 32;
}
gl_RenderState.SetColor(r, g, b); gl_RenderState.SetColor(r, g, b);
return true; return true;
} }
@ -491,11 +482,6 @@ bool GLWall::PutWallCompat(int passflag)
bool masked = passflag == 2 && gltexture->isMasked(); bool masked = passflag == 2 && gltexture->isMasked();
int list = list_indices[masked][foggy]; int list = list_indices[masked][foggy];
if (list == GLLDL_WALLS_PLAIN)
{
if (gltexture->tex->gl_info.Brightmap && gl.glslversion >= 0.f) list = GLLDL_WALLS_BRIGHT;
//if (flags & GLWF_GLOW) list = GLLDL_WALLS_BRIGHT;
}
gl_drawinfo->dldrawlists[list].AddWall(this); gl_drawinfo->dldrawlists[list].AddWall(this);
return true; return true;
@ -520,10 +506,6 @@ bool GLFlat::PutFlatCompat(bool fog)
int list = list_indices[masked][foggy]; int list = list_indices[masked][foggy];
if (list == GLLDL_FLATS_PLAIN)
{
if (gltexture->tex->gl_info.Brightmap && gl.glslversion >= 0.f) list = GLLDL_FLATS_BRIGHT;
}
gl_drawinfo->dldrawlists[list].AddFlat(this); gl_drawinfo->dldrawlists[list].AddFlat(this);
return true; return true;
} }
@ -612,7 +594,7 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass)
} }
p.Set(plane.plane); p.Set(plane.plane);
if (!gl_SetupLight(sub->sector->PortalGroup, p, light, nearPt, up, right, scale, CM_DEFAULT, false, pass != GLPASS_LIGHTTEX)) if (!gl_SetupLight(sub->sector->PortalGroup, p, light, nearPt, up, right, scale, false, pass != GLPASS_LIGHTTEX))
{ {
node = node->nextLight; node = node->nextLight;
continue; continue;
@ -692,7 +674,7 @@ bool GLWall::PrepareLight(ADynamicLight * light, int pass)
return false; return false;
} }
if (!gl_SetupLight(seg->frontsector->PortalGroup, p, light, nearPt, up, right, scale, CM_DEFAULT, true, pass != GLPASS_LIGHTTEX)) if (!gl_SetupLight(seg->frontsector->PortalGroup, p, light, nearPt, up, right, scale, true, pass != GLPASS_LIGHTTEX))
{ {
return false; return false;
} }
@ -798,9 +780,7 @@ void FGLRenderer::RenderMultipassStuff()
gl_RenderState.SetTextureMode(TM_MASK); gl_RenderState.SetTextureMode(TM_MASK);
gl_RenderState.EnableBrightmap(true); gl_RenderState.EnableBrightmap(true);
gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold);
gl_drawinfo->dldrawlists[GLLDL_WALLS_BRIGHT].DrawWalls(GLPASS_PLAIN);
gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_PLAIN); gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_PLAIN);
gl_drawinfo->dldrawlists[GLLDL_FLATS_BRIGHT].DrawFlats(GLPASS_PLAIN);
gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_PLAIN); gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_PLAIN);
// Part 3: The base of fogged surfaces, including the texture // Part 3: The base of fogged surfaces, including the texture
@ -823,10 +803,8 @@ void FGLRenderer::RenderMultipassStuff()
glDepthFunc(GL_EQUAL); glDepthFunc(GL_EQUAL);
if (glset.lightmode == 8) gl_RenderState.SetSoftLightLevel(255); if (glset.lightmode == 8) gl_RenderState.SetSoftLightLevel(255);
gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(GLPASS_LIGHTTEX); gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(GLPASS_LIGHTTEX);
gl_drawinfo->dldrawlists[GLLDL_WALLS_BRIGHT].DrawWalls(GLPASS_LIGHTTEX);
gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_LIGHTTEX); gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_LIGHTTEX);
gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(GLPASS_LIGHTTEX); gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(GLPASS_LIGHTTEX);
gl_drawinfo->dldrawlists[GLLDL_FLATS_BRIGHT].DrawFlats(GLPASS_LIGHTTEX);
gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_LIGHTTEX); gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_LIGHTTEX);
gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendEquation(GL_FUNC_ADD);
} }
@ -841,8 +819,6 @@ void FGLRenderer::RenderMultipassStuff()
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(GLPASS_TEXONLY); gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(GLPASS_TEXONLY);
gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(GLPASS_TEXONLY); gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(GLPASS_TEXONLY);
gl_drawinfo->dldrawlists[GLLDL_WALLS_BRIGHT].DrawWalls(GLPASS_TEXONLY);
gl_drawinfo->dldrawlists[GLLDL_FLATS_BRIGHT].DrawFlats(GLPASS_TEXONLY);
gl_RenderState.AlphaFunc(GL_GREATER, gl_mask_threshold); gl_RenderState.AlphaFunc(GL_GREATER, gl_mask_threshold);
gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_TEXONLY); gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_TEXONLY);
gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_TEXONLY); gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_TEXONLY);
@ -854,10 +830,8 @@ void FGLRenderer::RenderMultipassStuff()
if (gl_SetupLightTexture()) if (gl_SetupLightTexture())
{ {
gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(GLPASS_LIGHTTEX_ADDITIVE); gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(GLPASS_LIGHTTEX_ADDITIVE);
gl_drawinfo->dldrawlists[GLLDL_WALLS_BRIGHT].DrawWalls(GLPASS_LIGHTTEX_ADDITIVE);
gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_LIGHTTEX_ADDITIVE); gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(GLPASS_LIGHTTEX_ADDITIVE);
gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(GLPASS_LIGHTTEX_ADDITIVE); gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(GLPASS_LIGHTTEX_ADDITIVE);
gl_drawinfo->dldrawlists[GLLDL_FLATS_BRIGHT].DrawFlats(GLPASS_LIGHTTEX_ADDITIVE);
gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_LIGHTTEX_ADDITIVE); gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(GLPASS_LIGHTTEX_ADDITIVE);
gl_drawinfo->dldrawlists[GLLDL_WALLS_FOG].DrawWalls(GLPASS_LIGHTTEX_FOGGY); gl_drawinfo->dldrawlists[GLLDL_WALLS_FOG].DrawWalls(GLPASS_LIGHTTEX_FOGGY);
gl_drawinfo->dldrawlists[GLLDL_WALLS_FOGMASKED].DrawWalls(GLPASS_LIGHTTEX_FOGGY); gl_drawinfo->dldrawlists[GLLDL_WALLS_FOGMASKED].DrawWalls(GLPASS_LIGHTTEX_FOGGY);

View file

@ -75,7 +75,7 @@ FVertexBuffer::~FVertexBuffer()
void FSimpleVertexBuffer::BindVBO() void FSimpleVertexBuffer::BindVBO()
{ {
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FSimpleVertex), &VSiO->x); glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FSimpleVertex), &VSiO->x);
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSimpleVertex), &VSiO->u); glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSimpleVertex), &VSiO->u);
@ -100,7 +100,7 @@ void FSimpleVertexBuffer::EnableColorArray(bool on)
{ {
if (on) if (on)
{ {
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
glEnableVertexAttribArray(VATTR_COLOR); glEnableVertexAttribArray(VATTR_COLOR);
} }
@ -111,7 +111,7 @@ void FSimpleVertexBuffer::EnableColorArray(bool on)
} }
else else
{ {
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
glDisableVertexAttribArray(VATTR_COLOR); glDisableVertexAttribArray(VATTR_COLOR);
} }
@ -138,7 +138,7 @@ void FSimpleVertexBuffer::set(FSimpleVertex *verts, int count)
//========================================================================== //==========================================================================
FFlatVertexBuffer::FFlatVertexBuffer(int width, int height) FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
: FVertexBuffer(gl.buffermethod != BM_CLIENTARRAY) : FVertexBuffer(!gl.legacyMode)
{ {
switch (gl.buffermethod) switch (gl.buffermethod)
{ {
@ -162,7 +162,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
break; break;
} }
case BM_CLIENTARRAY: default:
{ {
map = new FFlatVertex[BUFFER_SIZE]; map = new FFlatVertex[BUFFER_SIZE];
DPrintf(DMSG_NOTIFY, "Using client array buffer\n"); DPrintf(DMSG_NOTIFY, "Using client array buffer\n");
@ -219,7 +219,7 @@ FFlatVertexBuffer::~FFlatVertexBuffer()
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
if (gl.buffermethod == BM_CLIENTARRAY) if (gl.legacyMode)
{ {
delete[] map; delete[] map;
} }
@ -230,19 +230,10 @@ FFlatVertexBuffer::~FFlatVertexBuffer()
void FFlatVertexBuffer::BindVBO() void FFlatVertexBuffer::BindVBO()
{ {
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
if (gl.buffermethod != BM_CLIENTARRAY) glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FFlatVertex), &VTO->x);
{ glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FFlatVertex), &VTO->u);
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FFlatVertex), &VTO->x);
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FFlatVertex), &VTO->u);
}
else
{
// If we cannot use a hardware buffer, use an old-style client array.
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FFlatVertex), &map->x);
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FFlatVertex), &map->u);
}
glEnableVertexAttribArray(VATTR_VERTEX); glEnableVertexAttribArray(VATTR_VERTEX);
glEnableVertexAttribArray(VATTR_TEXCOORD); glEnableVertexAttribArray(VATTR_TEXCOORD);
glDisableVertexAttribArray(VATTR_COLOR); glDisableVertexAttribArray(VATTR_COLOR);

View file

@ -105,7 +105,7 @@ void gl_FlushModels()
//=========================================================================== //===========================================================================
FModelVertexBuffer::FModelVertexBuffer(bool needindex, bool singleframe) FModelVertexBuffer::FModelVertexBuffer(bool needindex, bool singleframe)
: FVertexBuffer(singleframe || gl.glslversion > 0) : FVertexBuffer(singleframe || !gl.legacyMode)
{ {
vbo_ptr = nullptr; vbo_ptr = nullptr;
ibo_id = 0; ibo_id = 0;
@ -125,7 +125,7 @@ void FModelVertexBuffer::BindVBO()
{ {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
glEnableVertexAttribArray(VATTR_VERTEX); glEnableVertexAttribArray(VATTR_VERTEX);
glEnableVertexAttribArray(VATTR_TEXCOORD); glEnableVertexAttribArray(VATTR_TEXCOORD);
@ -170,7 +170,7 @@ FModelVertex *FModelVertexBuffer::LockVertexBuffer(unsigned int size)
{ {
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
glBufferData(GL_ARRAY_BUFFER, size * sizeof(FModelVertex), nullptr, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, size * sizeof(FModelVertex), nullptr, GL_STATIC_DRAW);
if (gl.version >= 3.0) if (!gl.legacyMode)
return (FModelVertex*)glMapBufferRange(GL_ARRAY_BUFFER, 0, size * sizeof(FModelVertex), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); return (FModelVertex*)glMapBufferRange(GL_ARRAY_BUFFER, 0, size * sizeof(FModelVertex), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
else else
return (FModelVertex*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); return (FModelVertex*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
@ -211,7 +211,7 @@ unsigned int *FModelVertexBuffer::LockIndexBuffer(unsigned int size)
{ {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(unsigned int), NULL, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(unsigned int), NULL, GL_STATIC_DRAW);
if (gl.version >= 3.0) if (!gl.legacyMode)
return (unsigned int*)glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, size * sizeof(unsigned int), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); return (unsigned int*)glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, size * sizeof(unsigned int), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
else else
return (unsigned int*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); return (unsigned int*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
@ -251,7 +251,7 @@ unsigned int FModelVertexBuffer::SetupFrame(unsigned int frame1, unsigned int fr
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
if (vbo_id > 0) if (vbo_id > 0)
{ {
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame1].x); glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame1].x);
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame1].u); glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FModelVertex), &VMO[frame1].u);

View file

@ -71,7 +71,7 @@ CUSTOM_CVAR(Bool, gl_enhanced_nightvision, true, CVAR_ARCHIVE|CVAR_NOINITCALL)
{ {
// The fixed colormap state needs to be reset because if this happens when // The fixed colormap state needs to be reset because if this happens when
// a shader is set to CM_LITE or CM_TORCH it won't register the change in behavior caused by this CVAR. // a shader is set to CM_LITE or CM_TORCH it won't register the change in behavior caused by this CVAR.
if (GLRenderer != NULL && GLRenderer->mShaderManager != NULL) if (GLRenderer != nullptr && GLRenderer->mShaderManager != nullptr)
{ {
GLRenderer->mShaderManager->ResetFixedColormap(); GLRenderer->mShaderManager->ResetFixedColormap();
} }

View file

@ -72,6 +72,7 @@
#include "gl/shaders/gl_bloomshader.h" #include "gl/shaders/gl_bloomshader.h"
#include "gl/shaders/gl_blurshader.h" #include "gl/shaders/gl_blurshader.h"
#include "gl/shaders/gl_tonemapshader.h" #include "gl/shaders/gl_tonemapshader.h"
#include "gl/shaders/gl_colormapshader.h"
#include "gl/shaders/gl_lensshader.h" #include "gl/shaders/gl_lensshader.h"
#include "gl/shaders/gl_presentshader.h" #include "gl/shaders/gl_presentshader.h"
#include "gl/renderer/gl_2ddrawer.h" #include "gl/renderer/gl_2ddrawer.h"
@ -135,10 +136,11 @@ void FGLRenderer::RenderScreenQuad()
void FGLRenderer::PostProcessScene() void FGLRenderer::PostProcessScene()
{ {
if (FGLRenderBuffers::IsEnabled()) mBuffers->BlitSceneToTexture(); mBuffers->BlitSceneToTexture();
AmbientOccludeScene(); AmbientOccludeScene();
BloomScene(); BloomScene();
TonemapScene(); TonemapScene();
ColormapScene();
LensDistortScene(); LensDistortScene();
} }
@ -240,7 +242,7 @@ void FGLRenderer::AmbientOccludeScene()
void FGLRenderer::BloomScene() void FGLRenderer::BloomScene()
{ {
// Only bloom things if enabled and no special fixed light mode is active // Only bloom things if enabled and no special fixed light mode is active
if (!gl_bloom || !FGLRenderBuffers::IsEnabled() || gl_fixedcolormap != CM_DEFAULT || gl_ssao_debug) if (!gl_bloom || gl_fixedcolormap != CM_DEFAULT || gl_ssao_debug)
return; return;
FGLDebug::PushGroup("BloomScene"); FGLDebug::PushGroup("BloomScene");
@ -326,7 +328,7 @@ void FGLRenderer::BloomScene()
void FGLRenderer::TonemapScene() void FGLRenderer::TonemapScene()
{ {
if (gl_tonemap == 0 || !FGLRenderBuffers::IsEnabled()) if (gl_tonemap == 0)
return; return;
FGLDebug::PushGroup("TonemapScene"); FGLDebug::PushGroup("TonemapScene");
@ -398,6 +400,38 @@ void FGLRenderer::ClearTonemapPalette()
mTonemapPalette = nullptr; mTonemapPalette = nullptr;
} }
//-----------------------------------------------------------------------------
//
// Colormap scene texture and place the result in the HUD/2D texture
//
//-----------------------------------------------------------------------------
void FGLRenderer::ColormapScene()
{
if (gl_fixedcolormap < CM_FIRSTSPECIALCOLORMAP || gl_fixedcolormap >= CM_MAXCOLORMAP)
return;
FGLDebug::PushGroup("ColormapScene");
FGLPostProcessState savedState;
mBuffers->BindNextFB();
mBuffers->BindCurrentTexture(0);
mColormapShader->Bind();
FSpecialColormap *scm = &SpecialColormaps[gl_fixedcolormap - CM_FIRSTSPECIALCOLORMAP];
float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0],
scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f };
mColormapShader->MapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f);
mColormapShader->MapRange.Set(m);
RenderScreenQuad();
mBuffers->NextTexture();
FGLDebug::PopGroup();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Apply lens distortion and place the result in the HUD/2D texture // Apply lens distortion and place the result in the HUD/2D texture
@ -406,7 +440,7 @@ void FGLRenderer::ClearTonemapPalette()
void FGLRenderer::LensDistortScene() void FGLRenderer::LensDistortScene()
{ {
if (gl_lens == 0 || !FGLRenderBuffers::IsEnabled()) if (gl_lens == 0)
return; return;
FGLDebug::PushGroup("LensDistortScene"); FGLDebug::PushGroup("LensDistortScene");

View file

@ -56,7 +56,14 @@
#include <random> #include <random>
CVAR(Int, gl_multisample, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CVAR(Int, gl_multisample, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
CVAR(Bool, gl_renderbuffers, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CUSTOM_CVAR(Bool, gl_renderbuffers, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
// this CVAR alters some fixed colormap related settings
if (GLRenderer != nullptr && GLRenderer->mShaderManager != nullptr)
{
//GLRenderer->mShaderManager->ResetFixedColormap();
}
}
//========================================================================== //==========================================================================
// //
@ -95,7 +102,6 @@ void FGLRenderBuffers::ClearScene()
DeleteFrameBuffer(mSceneFB); DeleteFrameBuffer(mSceneFB);
DeleteRenderBuffer(mSceneMSColor); DeleteRenderBuffer(mSceneMSColor);
DeleteRenderBuffer(mSceneMSDepthStencil); DeleteRenderBuffer(mSceneMSDepthStencil);
DeleteRenderBuffer(mSceneMSDepth);
DeleteRenderBuffer(mSceneMSStencil); DeleteRenderBuffer(mSceneMSStencil);
} }
@ -107,7 +113,6 @@ void FGLRenderBuffers::ClearPipeline()
DeleteTexture(mPipelineTexture[i]); DeleteTexture(mPipelineTexture[i]);
} }
DeleteTexture(mPipelineDepthStencil); DeleteTexture(mPipelineDepthStencil);
DeleteTexture(mPipelineDepth);
DeleteTexture(mPipelineStencil); DeleteTexture(mPipelineStencil);
} }
@ -233,25 +238,12 @@ void FGLRenderBuffers::CreateScene(int width, int height, int samples)
if (samples > 1) if (samples > 1)
{ {
mSceneMSColor = CreateRenderBuffer("SceneMSColor", GetHdrFormat(), samples, width, height); mSceneMSColor = CreateRenderBuffer("SceneMSColor", GetHdrFormat(), samples, width, height);
mSceneMSDepthStencil = CreateRenderBuffer("SceneMSDepthStencil", GL_DEPTH24_STENCIL8, samples, width, height);
if ((gl.flags & RFL_NO_DEPTHSTENCIL) != 0) mSceneFB = CreateFrameBuffer("SceneFB", mSceneMSColor, mSceneMSDepthStencil, true);
{
mSceneMSDepth = CreateRenderBuffer("SceneMSDepth", GL_DEPTH_COMPONENT24, samples, width, height);
mSceneMSStencil = CreateRenderBuffer("SceneMSStencil", GL_STENCIL_INDEX8, samples, width, height);
mSceneFB = CreateFrameBuffer("SceneFB", mSceneMSColor, mSceneMSDepth, mSceneMSStencil, true);
}
else
{
mSceneMSDepthStencil = CreateRenderBuffer("SceneMSDepthStencil", GL_DEPTH24_STENCIL8, samples, width, height);
mSceneFB = CreateFrameBuffer("SceneFB", mSceneMSColor, mSceneMSDepthStencil, true);
}
} }
else else
{ {
if ((gl.flags & RFL_NO_DEPTHSTENCIL) != 0) mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], mPipelineDepthStencil, false);
mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], mPipelineDepth, mPipelineStencil, false);
else
mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], mPipelineDepthStencil, false);
} }
} }
@ -265,23 +257,12 @@ void FGLRenderBuffers::CreatePipeline(int width, int height)
{ {
ClearPipeline(); ClearPipeline();
if ((gl.flags & RFL_NO_DEPTHSTENCIL) != 0) mPipelineDepthStencil = Create2DTexture("PipelineDepthStencil", GL_DEPTH24_STENCIL8, width, height);
{
mPipelineDepth = Create2DTexture("PipelineDepth", GL_DEPTH_COMPONENT24, width, height);
mPipelineStencil = Create2DTexture("PipelineStencil", GL_STENCIL_INDEX8, width, height);
}
else
{
mPipelineDepthStencil = Create2DTexture("PipelineDepthStencil", GL_DEPTH24_STENCIL8, width, height);
}
for (int i = 0; i < NumPipelineTextures; i++) for (int i = 0; i < NumPipelineTextures; i++)
{ {
mPipelineTexture[i] = Create2DTexture("PipelineTexture", GetHdrFormat(), width, height); mPipelineTexture[i] = Create2DTexture("PipelineTexture", GetHdrFormat(), width, height);
if ((gl.flags & RFL_NO_DEPTHSTENCIL) != 0) mPipelineFB[i] = CreateFrameBuffer("PipelineFB", mPipelineTexture[i], mPipelineDepthStencil, false);
mPipelineFB[i] = CreateFrameBuffer("PipelineFB", mPipelineTexture[i], mPipelineDepth, mPipelineStencil, false);
else
mPipelineFB[i] = CreateFrameBuffer("PipelineFB", mPipelineTexture[i], mPipelineDepthStencil, false);
} }
} }
@ -366,7 +347,7 @@ void FGLRenderBuffers::CreateAmbientOcclusion(int width, int height)
GLuint FGLRenderBuffers::GetHdrFormat() GLuint FGLRenderBuffers::GetHdrFormat()
{ {
return ((gl.flags & RFL_NO_RGBA16F) != 0) ? GL_RGBA8 : GL_RGBA16F; return GL_RGBA16F;
} }
//========================================================================== //==========================================================================
@ -606,10 +587,7 @@ void FGLRenderBuffers::BindSceneFB()
void FGLRenderBuffers::BindSceneDepthTexture(int index) void FGLRenderBuffers::BindSceneDepthTexture(int index)
{ {
glActiveTexture(GL_TEXTURE0 + index); glActiveTexture(GL_TEXTURE0 + index);
if ((gl.flags & RFL_NO_DEPTHSTENCIL) != 0) glBindTexture(GL_TEXTURE_2D, mPipelineDepthStencil);
glBindTexture(GL_TEXTURE_2D, mPipelineDepth);
else
glBindTexture(GL_TEXTURE_2D, mPipelineDepthStencil);
} }
//========================================================================== //==========================================================================
@ -677,7 +655,7 @@ void FGLRenderBuffers::BindOutputFB()
bool FGLRenderBuffers::IsEnabled() bool FGLRenderBuffers::IsEnabled()
{ {
return gl_renderbuffers && gl.glslversion != 0 && !FailedCreate; return gl_renderbuffers && !gl.legacyMode && !FailedCreate;
} }
bool FGLRenderBuffers::FailedCreate = false; bool FGLRenderBuffers::FailedCreate = false;

View file

@ -89,7 +89,6 @@ private:
// Buffers for the scene // Buffers for the scene
GLuint mSceneMSColor = 0; GLuint mSceneMSColor = 0;
GLuint mSceneMSDepthStencil = 0; GLuint mSceneMSDepthStencil = 0;
GLuint mSceneMSDepth = 0;
GLuint mSceneMSStencil = 0; GLuint mSceneMSStencil = 0;
GLuint mSceneFB = 0; GLuint mSceneFB = 0;
@ -97,7 +96,6 @@ private:
GLuint mPipelineTexture[NumPipelineTextures]; GLuint mPipelineTexture[NumPipelineTextures];
GLuint mPipelineFB[NumPipelineTextures]; GLuint mPipelineFB[NumPipelineTextures];
GLuint mPipelineDepthStencil = 0; GLuint mPipelineDepthStencil = 0;
GLuint mPipelineDepth = 0;
GLuint mPipelineStencil = 0; GLuint mPipelineStencil = 0;
// Back buffer frame buffer // Back buffer frame buffer

View file

@ -68,6 +68,7 @@
#include "gl/shaders/gl_bloomshader.h" #include "gl/shaders/gl_bloomshader.h"
#include "gl/shaders/gl_blurshader.h" #include "gl/shaders/gl_blurshader.h"
#include "gl/shaders/gl_tonemapshader.h" #include "gl/shaders/gl_tonemapshader.h"
#include "gl/shaders/gl_colormapshader.h"
#include "gl/shaders/gl_lensshader.h" #include "gl/shaders/gl_lensshader.h"
#include "gl/shaders/gl_presentshader.h" #include "gl/shaders/gl_presentshader.h"
#include "gl/textures/gl_texture.h" #include "gl/textures/gl_texture.h"
@ -98,21 +99,30 @@ CVAR(Bool, gl_scale_viewport, true, 0);
FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb) FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
{ {
framebuffer = fb; framebuffer = fb;
mClipPortal = NULL; mClipPortal = nullptr;
mCurrentPortal = NULL; mCurrentPortal = nullptr;
mMirrorCount = 0; mMirrorCount = 0;
mPlaneMirrorCount = 0; mPlaneMirrorCount = 0;
mLightCount = 0; mLightCount = 0;
mAngles = FRotator(0.f, 0.f, 0.f); mAngles = FRotator(0.f, 0.f, 0.f);
mViewVector = FVector2(0,0); mViewVector = FVector2(0,0);
mVBO = NULL; mVBO = nullptr;
mSkyVBO = NULL; mSkyVBO = nullptr;
gl_spriteindex = 0; gl_spriteindex = 0;
mShaderManager = NULL; mShaderManager = nullptr;
gllight = glpart2 = glpart = mirrortexture = NULL; gllight = glpart2 = glpart = mirrortexture = nullptr;
mLights = NULL; mLights = nullptr;
m2DDrawer = nullptr; m2DDrawer = nullptr;
mTonemapPalette = nullptr; mTonemapPalette = nullptr;
mBuffers = nullptr;
mPresentShader = nullptr;
mBloomExtractShader = nullptr;
mBloomCombineShader = nullptr;
mBlurShader = nullptr;
mTonemapShader = nullptr;
mTonemapPalette = nullptr;
mColormapShader = nullptr;
mLensShader = nullptr;
} }
void gl_LoadModels(); void gl_LoadModels();
@ -127,13 +137,14 @@ void FGLRenderer::Initialize(int width, int height)
mBloomCombineShader = new FBloomCombineShader(); mBloomCombineShader = new FBloomCombineShader();
mBlurShader = new FBlurShader(); mBlurShader = new FBlurShader();
mTonemapShader = new FTonemapShader(); mTonemapShader = new FTonemapShader();
mColormapShader = new FColormapShader();
mTonemapPalette = nullptr; mTonemapPalette = nullptr;
mLensShader = new FLensShader(); mLensShader = new FLensShader();
mPresentShader = new FPresentShader(); mPresentShader = new FPresentShader();
m2DDrawer = new F2DDrawer; m2DDrawer = new F2DDrawer;
// Only needed for the core profile, because someone decided it was a good idea to remove the default VAO. // needed for the core profile, because someone decided it was a good idea to remove the default VAO.
if (gl.buffermethod != BM_CLIENTARRAY) if (!gl.legacyMode)
{ {
glGenVertexArrays(1, &mVAOID); glGenVertexArrays(1, &mVAOID);
glBindVertexArray(mVAOID); glBindVertexArray(mVAOID);
@ -148,7 +159,7 @@ void FGLRenderer::Initialize(int width, int height)
mVBO = new FFlatVertexBuffer(width, height); mVBO = new FFlatVertexBuffer(width, height);
mSkyVBO = new FSkyVertexBuffer; mSkyVBO = new FSkyVertexBuffer;
if (gl.lightmethod != LM_SOFTWARE) mLights = new FLightBuffer(); if (!gl.legacyMode) mLights = new FLightBuffer();
else mLights = NULL; else mLights = NULL;
gl_RenderState.SetVertexBuffer(mVBO); gl_RenderState.SetVertexBuffer(mVBO);
mFBID = 0; mFBID = 0;
@ -189,6 +200,7 @@ FGLRenderer::~FGLRenderer()
if (mBlurShader) delete mBlurShader; if (mBlurShader) delete mBlurShader;
if (mTonemapShader) delete mTonemapShader; if (mTonemapShader) delete mTonemapShader;
if (mTonemapPalette) delete mTonemapPalette; if (mTonemapPalette) delete mTonemapPalette;
if (mColormapShader) delete mColormapShader;
if (mLensShader) delete mLensShader; if (mLensShader) delete mLensShader;
} }

View file

@ -25,6 +25,7 @@ class FBloomExtractShader;
class FBloomCombineShader; class FBloomCombineShader;
class FBlurShader; class FBlurShader;
class FTonemapShader; class FTonemapShader;
class FColormapShader;
class FLensShader; class FLensShader;
class FPresentShader; class FPresentShader;
class F2DDrawer; class F2DDrawer;
@ -97,6 +98,7 @@ public:
FBloomCombineShader *mBloomCombineShader; FBloomCombineShader *mBloomCombineShader;
FBlurShader *mBlurShader; FBlurShader *mBlurShader;
FTonemapShader *mTonemapShader; FTonemapShader *mTonemapShader;
FColormapShader *mColormapShader;
FHardwareTexture *mTonemapPalette; FHardwareTexture *mTonemapPalette;
FLensShader *mLensShader; FLensShader *mLensShader;
FPresentShader *mPresentShader; FPresentShader *mPresentShader;
@ -172,6 +174,7 @@ public:
void AmbientOccludeScene(); void AmbientOccludeScene();
void BloomScene(); void BloomScene();
void TonemapScene(); void TonemapScene();
void ColormapScene();
void BindTonemapPalette(int texunit); void BindTonemapPalette(int texunit);
void ClearTonemapPalette(); void ClearTonemapPalette();
void LensDistortScene(); void LensDistortScene();

View file

@ -49,6 +49,7 @@
#include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderstate.h"
#include "gl/renderer/gl_colormap.h" #include "gl/renderer/gl_colormap.h"
#include "gl/dynlights//gl_lightbuffer.h" #include "gl/dynlights//gl_lightbuffer.h"
#include "gl/renderer/gl_renderbuffers.h"
void gl_SetTextureMode(int type); void gl_SetTextureMode(int type);
@ -221,15 +222,24 @@ bool FRenderState::ApplyShader()
{ {
activeShader->muFixedColormap.Set(0); activeShader->muFixedColormap.Set(0);
} }
else if (mColormapState < CM_MAXCOLORMAP) else if (mColormapState > CM_DEFAULT && mColormapState < CM_MAXCOLORMAP)
{ {
FSpecialColormap *scm = &SpecialColormaps[gl_fixedcolormap - CM_FIRSTSPECIALCOLORMAP]; if (FGLRenderBuffers::IsEnabled())
float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0], {
scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f }; // When using postprocessing to apply the colormap, we must render the image fullbright here.
activeShader->muFixedColormap.Set(2);
activeShader->muColormapStart.Set(1, 1, 1, 1.f);
}
else
{
FSpecialColormap *scm = &SpecialColormaps[gl_fixedcolormap - CM_FIRSTSPECIALCOLORMAP];
float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0],
scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f };
activeShader->muFixedColormap.Set(1); activeShader->muFixedColormap.Set(1);
activeShader->muColormapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f); activeShader->muColormapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f);
activeShader->muColormapRange.Set(m); activeShader->muColormapRange.Set(m);
}
} }
else if (mColormapState == CM_FOGLAYER) else if (mColormapState == CM_FOGLAYER)
{ {
@ -315,7 +325,7 @@ void FRenderState::Apply()
else mVertexBuffer->BindVBO(); else mVertexBuffer->BindVBO();
mCurrentVertexBuffer = mVertexBuffer; mCurrentVertexBuffer = mVertexBuffer;
} }
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
ApplyShader(); ApplyShader();
} }
@ -352,7 +362,7 @@ void FRenderState::ApplyMatrices()
void FRenderState::ApplyLightIndex(int index) void FRenderState::ApplyLightIndex(int index)
{ {
if (gl.lightmethod != LM_SOFTWARE) if (!gl.legacyMode)
{ {
if (index > -1 && GLRenderer->mLights->GetBufferType() == GL_UNIFORM_BUFFER) if (index > -1 && GLRenderer->mLights->GetBufferType() == GL_UNIFORM_BUFFER)
{ {

View file

@ -113,7 +113,7 @@ public:
// Without shaders this translation must be applied to any texture. // Without shaders this translation must be applied to any texture.
if (alphatexture) if (alphatexture)
{ {
if (mat->tex->UseBasePalette() || gl.glslversion == 0) translation = TRANSLATION(TRANSLATION_Standard, 8); if (mat->tex->UseBasePalette() || gl.legacyMode) translation = TRANSLATION(TRANSLATION_Standard, 8);
} }
mEffectState = overrideshader >= 0? overrideshader : mat->mShaderIndex; mEffectState = overrideshader >= 0? overrideshader : mat->mShaderIndex;
mShaderTimer = mat->tex->gl_info.shaderspeed; mShaderTimer = mat->tex->gl_info.shaderspeed;

View file

@ -322,7 +322,7 @@ void GLDrawList::SortWallIntoPlane(SortNode * head,SortNode * sort)
AddWall(&w); AddWall(&w);
// Splitting is done in the shader with clip planes, if available // Splitting is done in the shader with clip planes, if available
if (gl.glslversion < 1.3f) if (gl.flags & RFL_NO_CLIP_PLANES)
{ {
GLWall * ws1; GLWall * ws1;
ws->vertcount = 0; // invalidate current vertices. ws->vertcount = 0; // invalidate current vertices.
@ -382,7 +382,7 @@ void GLDrawList::SortSpriteIntoPlane(SortNode * head,SortNode * sort)
AddSprite(&s); // add a copy to avoid reallocation issues. AddSprite(&s); // add a copy to avoid reallocation issues.
// Splitting is done in the shader with clip planes, if available // Splitting is done in the shader with clip planes, if available
if (gl.glslversion < 1.3f) if (gl.flags & RFL_NO_CLIP_PLANES)
{ {
GLSprite * ss1; GLSprite * ss1;
ss1=&sprites[sprites.Size()-1]; ss1=&sprites[sprites.Size()-1];
@ -476,9 +476,15 @@ void GLDrawList::SortWallIntoWall(SortNode * head,SortNode * sort)
ws1->glseg.x1=ws->glseg.x2=ix; ws1->glseg.x1=ws->glseg.x2=ix;
ws1->glseg.y1=ws->glseg.y2=iy; ws1->glseg.y1=ws->glseg.y2=iy;
ws1->glseg.fracleft = ws->glseg.fracright = ws->glseg.fracleft + r*(ws->glseg.fracright - ws->glseg.fracleft);
ws1->ztop[0]=ws->ztop[1]=izt; ws1->ztop[0]=ws->ztop[1]=izt;
ws1->zbottom[0]=ws->zbottom[1]=izb; ws1->zbottom[0]=ws->zbottom[1]=izb;
ws1->tcs[GLWall::LOLFT].u = ws1->tcs[GLWall::UPLFT].u = ws->tcs[GLWall::LORGT].u = ws->tcs[GLWall::UPRGT].u = iu; ws1->tcs[GLWall::LOLFT].u = ws1->tcs[GLWall::UPLFT].u = ws->tcs[GLWall::LORGT].u = ws->tcs[GLWall::UPRGT].u = iu;
if (gl.buffermethod == BM_DEFERRED)
{
ws->MakeVertices(false);
ws1->MakeVertices(false);
}
SortNode * sort2=SortNodes.GetNew(); SortNode * sort2=SortNodes.GetNew();
memset(sort2,0,sizeof(SortNode)); memset(sort2,0,sizeof(SortNode));
@ -805,17 +811,19 @@ void GLDrawList::DrawSorted()
if (!sorted) if (!sorted)
{ {
GLRenderer->mVBO->Map();
MakeSortList(); MakeSortList();
sorted=DoSort(SortNodes[SortNodeStart]); sorted=DoSort(SortNodes[SortNodeStart]);
GLRenderer->mVBO->Unmap();
} }
gl_RenderState.ClearClipSplit(); gl_RenderState.ClearClipSplit();
if (gl.glslversion >= 1.3f) if (!(gl.flags & RFL_NO_CLIP_PLANES))
{ {
glEnable(GL_CLIP_DISTANCE1); glEnable(GL_CLIP_DISTANCE1);
glEnable(GL_CLIP_DISTANCE2); glEnable(GL_CLIP_DISTANCE2);
} }
DoDrawSorted(sorted); DoDrawSorted(sorted);
if (gl.glslversion >= 1.3f) if (!(gl.flags & RFL_NO_CLIP_PLANES))
{ {
glDisable(GL_CLIP_DISTANCE1); glDisable(GL_CLIP_DISTANCE1);
glDisable(GL_CLIP_DISTANCE2); glDisable(GL_CLIP_DISTANCE2);
@ -994,7 +1002,7 @@ static FDrawInfoList di_list;
FDrawInfo::FDrawInfo() FDrawInfo::FDrawInfo()
{ {
next = NULL; next = NULL;
if (gl.lightmethod == LM_SOFTWARE) if (gl.legacyMode)
{ {
dldrawlists = new GLDrawList[GLLDL_TYPES]; dldrawlists = new GLDrawList[GLLDL_TYPES];
} }

View file

@ -30,11 +30,9 @@ enum DLDrawListType
{ {
// These are organized so that the various multipass rendering modes have to be set as few times as possible // These are organized so that the various multipass rendering modes have to be set as few times as possible
GLLDL_WALLS_PLAIN, // dynamic lights on normal walls GLLDL_WALLS_PLAIN, // dynamic lights on normal walls
GLLDL_WALLS_BRIGHT, // dynamic lights on brightmapped walls
GLLDL_WALLS_MASKED, // dynamic lights on masked midtextures GLLDL_WALLS_MASKED, // dynamic lights on masked midtextures
GLLDL_FLATS_PLAIN, // dynamic lights on normal flats GLLDL_FLATS_PLAIN, // dynamic lights on normal flats
GLLDL_FLATS_BRIGHT, // dynamic lights on brightmapped flats
GLLDL_FLATS_MASKED, // dynamic lights on masked flats GLLDL_FLATS_MASKED, // dynamic lights on masked flats
GLLDL_WALLS_FOG, // lights on fogged walls GLLDL_WALLS_FOG, // lights on fogged walls

View file

@ -430,7 +430,7 @@ void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIG
{ {
gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
gl_SetPlaneTextureRotation(&plane, gltexture); gl_SetPlaneTextureRotation(&plane, gltexture);
DrawSubsectors(pass, gl.lightmethod != LM_SOFTWARE, true); DrawSubsectors(pass, !gl.legacyMode, true);
gl_RenderState.EnableTextureMatrix(false); gl_RenderState.EnableTextureMatrix(false);
} }
if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -468,7 +468,7 @@ inline void GLFlat::PutFlat(bool fog)
{ {
Colormap.Clear(); Colormap.Clear();
} }
if (gl.lightmethod == LM_SOFTWARE) if (gl.legacyMode)
{ {
if (PutFlatCompat(fog)) return; if (PutFlatCompat(fog)) return;
} }

View file

@ -409,7 +409,7 @@ void FGLRenderer::RenderScene(int recursion)
// this is the only geometry type on which decals can possibly appear // this is the only geometry type on which decals can possibly appear
gl_drawinfo->drawlists[GLDL_PLAINWALLS].DrawDecals(); gl_drawinfo->drawlists[GLDL_PLAINWALLS].DrawDecals();
if (gl.lightmethod == LM_SOFTWARE) if (gl.legacyMode)
{ {
// also process the render lists with walls and dynamic lights // also process the render lists with walls and dynamic lights
gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawDecals(); gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawDecals();
@ -480,7 +480,6 @@ void FGLRenderer::RenderTranslucent()
// stencil, z-buffer and the projection matrix intact! // stencil, z-buffer and the projection matrix intact!
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
EXTERN_CVAR(Bool, gl_draw_sync)
void FGLRenderer::DrawScene(int drawmode) void FGLRenderer::DrawScene(int drawmode)
{ {
@ -502,14 +501,6 @@ void FGLRenderer::DrawScene(int drawmode)
} }
GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place. GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place.
// Up to this point in the main draw call no rendering is performed so we can wait
// with swapping the render buffer until now.
if (!gl_draw_sync && drawmode == DM_MAINVIEW)
{
All.Unclock();
static_cast<OpenGLFrameBuffer*>(screen)->Swap();
All.Clock();
}
RenderScene(recursion); RenderScene(recursion);
// Handle all portals after rendering the opaque objects but before // Handle all portals after rendering the opaque objects but before
@ -644,12 +635,14 @@ void FGLRenderer::DrawBlend(sector_t * viewsector)
V_AddBlend (player->BlendR, player->BlendG, player->BlendB, player->BlendA, blend); V_AddBlend (player->BlendR, player->BlendG, player->BlendB, player->BlendA, blend);
} }
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (blend[3]>0.0f) if (blend[3]>0.0f)
{ {
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_RenderState.SetColor(blend[0], blend[1], blend[2], blend[3]); gl_RenderState.SetColor(blend[0], blend[1], blend[2], blend[3]);
gl_FillScreen(); gl_FillScreen();
} }
gl_RenderState.ResetColor();
gl_RenderState.EnableTexture(true);
} }
@ -685,16 +678,19 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector)
{ {
DrawPlayerSprites (viewsector, false); DrawPlayerSprites (viewsector, false);
} }
int cm = gl_RenderState.GetFixedColormap(); if (gl.legacyMode)
{
int cm = gl_RenderState.GetFixedColormap();
gl_RenderState.SetFixedColormap(cm);
gl_RenderState.DrawColormapOverlay();
}
gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetFixedColormap(CM_DEFAULT);
gl_RenderState.SetSoftLightLevel(-1); gl_RenderState.SetSoftLightLevel(-1);
DrawTargeterSprites(); DrawTargeterSprites();
DrawBlend(viewsector); if (FGLRenderBuffers::IsEnabled())
if (gl.glslversion == 0.0)
{ {
gl_RenderState.SetFixedColormap(cm); DrawBlend(viewsector);
gl_RenderState.DrawColormapOverlay();
gl_RenderState.SetFixedColormap(CM_DEFAULT);
} }
// Restore standard rendering state // Restore standard rendering state
@ -855,7 +851,11 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
ProcessScene(toscreen); ProcessScene(toscreen);
if (mainview && toscreen) EndDrawScene(retval); // do not call this for camera textures. if (mainview && toscreen) EndDrawScene(retval); // do not call this for camera textures.
if (mainview) PostProcessScene(); if (mainview && FGLRenderBuffers::IsEnabled())
{
PostProcessScene();
DrawBlend(viewsector); // This should be done after postprocessing, not before.
}
mDrawingScene2D = false; mDrawingScene2D = false;
eye->TearDown(); eye->TearDown();
} }
@ -899,7 +899,7 @@ void FGLRenderer::RenderView (player_t* player)
P_FindParticleSubsectors (); P_FindParticleSubsectors ();
if (gl.lightmethod != LM_SOFTWARE) GLRenderer->mLights->Clear(); if (!gl.legacyMode) GLRenderer->mLights->Clear();
// NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below.
bool saved_niv = NoInterpolateView; bool saved_niv = NoInterpolateView;
@ -954,7 +954,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FILE *file, int width, int hei
SetFixedColormap(player); SetFixedColormap(player);
gl_RenderState.SetVertexBuffer(mVBO); gl_RenderState.SetVertexBuffer(mVBO);
GLRenderer->mVBO->Reset(); GLRenderer->mVBO->Reset();
if (gl.lightmethod != LM_SOFTWARE) GLRenderer->mLights->Clear(); if (!gl.legacyMode) GLRenderer->mLights->Clear();
// Check if there's some lights. If not some code can be skipped. // Check if there's some lights. If not some code can be skipped.
TThinkerIterator<ADynamicLight> it(STAT_DLIGHT); TThinkerIterator<ADynamicLight> it(STAT_DLIGHT);

View file

@ -87,7 +87,7 @@ FSkyVertexBuffer::~FSkyVertexBuffer()
void FSkyVertexBuffer::BindVBO() void FSkyVertexBuffer::BindVBO()
{ {
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
if (gl.glslversion > 0) if (!gl.legacyMode)
{ {
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->x); glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->x);
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->u); glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->u);
@ -321,7 +321,7 @@ void FSkyVertexBuffer::RenderDome(FMaterial *tex, int mode)
RenderRow(GL_TRIANGLE_FAN, rc); RenderRow(GL_TRIANGLE_FAN, rc);
gl_RenderState.EnableTexture(true); gl_RenderState.EnableTexture(true);
// The color array can only be activated now if this is drawn without shader // The color array can only be activated now if this is drawn without shader
if (gl.glslversion == 0) if (gl.legacyMode)
{ {
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
} }

View file

@ -870,7 +870,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
RenderStyle.CheckFuzz(); RenderStyle.CheckFuzz();
if (RenderStyle.BlendOp == STYLEOP_Fuzz) if (RenderStyle.BlendOp == STYLEOP_Fuzz)
{ {
if (gl_fuzztype != 0 && gl.glslversion > 0) if (gl_fuzztype != 0 && !gl.legacyMode)
{ {
// Todo: implement shader selection here // Todo: implement shader selection here
RenderStyle = LegacyRenderStyles[STYLE_Translucent]; RenderStyle = LegacyRenderStyles[STYLE_Translucent];

View file

@ -140,9 +140,8 @@ void GLWall::PutWall(bool translucent)
} }
else else
{ {
if (gl.lightmethod == LM_SOFTWARE && !translucent) if (gl.legacyMode && !translucent)
{ {
// This is not yet ready.
if (PutWallCompat(passflag[type])) return; if (PutWallCompat(passflag[type])) return;
} }

View file

@ -216,9 +216,8 @@ void GLWall::RenderWall(int textured)
} }
else if (vertcount == 0) else if (vertcount == 0)
{ {
// in case we get here without valid vertex data and no ability to create them now, // This should never happen but in case it actually does, use the quad drawer as fallback (without edge splitting.)
// use the quad drawer as fallback (without edge splitting.) // This way it at least gets drawn.
// This can only happen in one special situation, when a translucent line got split during sorting.
FQuadDrawer qd; FQuadDrawer qd;
qd.Set(0, glseg.x1, zbottom[0], glseg.y1, tcs[LOLFT].u, tcs[LOLFT].v); qd.Set(0, glseg.x1, zbottom[0], glseg.y1, tcs[LOLFT].u, tcs[LOLFT].v);
qd.Set(1, glseg.x1, ztop[0], glseg.y1, tcs[UPLFT].u, tcs[UPLFT].v); qd.Set(1, glseg.x1, ztop[0], glseg.y1, tcs[UPLFT].u, tcs[UPLFT].v);
@ -242,7 +241,7 @@ void GLWall::RenderFogBoundary()
{ {
if (gl_fogmode && gl_fixedcolormap == 0) if (gl_fogmode && gl_fixedcolormap == 0)
{ {
if (gl.glslversion > 0.f) if (!gl.legacyMode)
{ {
int rel = rellight + getExtraLight(); int rel = rellight + getExtraLight();
gl_SetFog(lightlevel, rel, &Colormap, false); gl_SetFog(lightlevel, rel, &Colormap, false);
@ -276,7 +275,7 @@ void GLWall::RenderMirrorSurface()
Vector v(glseg.y2-glseg.y1, 0 ,-glseg.x2+glseg.x1); Vector v(glseg.y2-glseg.y1, 0 ,-glseg.x2+glseg.x1);
v.Normalize(); v.Normalize();
if (gl.glslversion >= 0.f) if (!gl.legacyMode)
{ {
// we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is. // we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is.
tcs[LOLFT].u = tcs[LORGT].u = tcs[UPLFT].u = tcs[UPRGT].u = v.X(); tcs[LOLFT].u = tcs[LORGT].u = tcs[UPLFT].u = tcs[UPRGT].u = v.X();

View file

@ -87,20 +87,6 @@ void FBlurShader::Blur(FGLRenderer *renderer, float blurAmount, int sampleCount,
else else
setup->HorizontalShader->Bind(); setup->HorizontalShader->Bind();
if (gl.glslversion < 1.3)
{
if (vertical)
{
setup->VerticalScaleX.Set(1.0f / width);
setup->VerticalScaleY.Set(1.0f / height);
}
else
{
setup->HorizontalScaleX.Set(1.0f / width);
setup->HorizontalScaleY.Set(1.0f / height);
}
}
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, inputTexture); glBindTexture(GL_TEXTURE_2D, inputTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -156,14 +142,6 @@ FBlurShader::BlurSetup *FBlurShader::GetSetup(float blurAmount, int sampleCount)
blurSetup.HorizontalShader->Bind(); blurSetup.HorizontalShader->Bind();
glUniform1i(glGetUniformLocation(*blurSetup.HorizontalShader.get(), "SourceTexture"), 0); glUniform1i(glGetUniformLocation(*blurSetup.HorizontalShader.get(), "SourceTexture"), 0);
if (gl.glslversion < 1.3)
{
blurSetup.VerticalScaleX.Init(*blurSetup.VerticalShader.get(), "ScaleX");
blurSetup.VerticalScaleY.Init(*blurSetup.VerticalShader.get(), "ScaleY");
blurSetup.HorizontalScaleX.Init(*blurSetup.HorizontalShader.get(), "ScaleX");
blurSetup.HorizontalScaleY.Init(*blurSetup.HorizontalShader.get(), "ScaleY");
}
mBlurSetups.Push(blurSetup); mBlurSetups.Push(blurSetup);
return &mBlurSetups[mBlurSetups.Size() - 1]; return &mBlurSetups[mBlurSetups.Size() - 1];

View file

@ -0,0 +1,67 @@
/*
** gl_colormapshader.cpp
** Applies a fullscreen colormap to the scene
**
**---------------------------------------------------------------------------
** Copyright 2016 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
** 4. When not used as part of GZDoom or a GZDoom derivative, this code will be
** covered by the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation; either version 2.1 of the License, or (at
** your option) any later version.
** 5. Full disclosure of the entire project's source code, except for third
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#include "gl/system/gl_system.h"
#include "files.h"
#include "m_swap.h"
#include "v_video.h"
#include "gl/gl_functions.h"
#include "vectors.h"
#include "gl/system/gl_interface.h"
#include "gl/system/gl_framebuffer.h"
#include "gl/system/gl_cvars.h"
#include "gl/shaders/gl_colormapshader.h"
void FColormapShader::Bind()
{
auto &shader = mShader;
if (!shader)
{
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/colormap.fp", "", 330);
shader.SetFragDataLocation(0, "FragColor");
shader.Link("shaders/glsl/colormap");
shader.SetAttribLocation(0, "PositionInProjection");
MapStart.Init(shader, "uFixedColormapStart");
MapRange.Init(shader, "uFixedColormapRange");
}
shader.Bind();
}

View file

@ -0,0 +1,20 @@
#ifndef __GL_COLORMAPSHADER_H
#define __GL_COLORMAPSHADER_H
#include "gl_shaderprogram.h"
class FColormapShader
{
public:
void Bind();
FBufferedUniformSampler SceneTexture;
FUniform4f MapStart;
FUniform4f MapRange;
private:
FShaderProgram mShader;
};
#endif

View file

@ -91,40 +91,27 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
// //
FString vp_comb; FString vp_comb;
if (gl.lightmethod == LM_SOFTWARE) assert(GLRenderer->mLights != NULL);
// On the shader side there is no difference between LM_DEFERRED and LM_DIRECT, it only decides how the buffer is initialized.
unsigned int lightbuffertype = GLRenderer->mLights->GetBufferType();
unsigned int lightbuffersize = GLRenderer->mLights->GetBlockSize();
if (lightbuffertype == GL_UNIFORM_BUFFER)
{ {
if (gl.glslversion >= 1.3) // This differentiation is for some Intel drivers which fail on #extension, so use of #version 140 is necessary
if (gl.glslversion < 1.4f)
{ {
vp_comb = "#version 130\n"; vp_comb.Format("#version 130\n#extension GL_ARB_uniform_buffer_object : require\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize);
} }
else else
{ {
vp_comb = "#define GLSL12_COMPATIBLE\n"; vp_comb.Format("#version 140\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize);
} }
} }
else else
{ {
assert(GLRenderer->mLights != NULL); vp_comb = "#version 400 core\n#extension GL_ARB_shader_storage_buffer_object : require\n#define SHADER_STORAGE_LIGHTS\n";
// On the shader side there is no difference between LM_DEFERRED and LM_DIRECT, it only matters which buffer type is used by the light buffer.
unsigned int lightbuffertype = GLRenderer->mLights->GetBufferType();
unsigned int lightbuffersize = GLRenderer->mLights->GetBlockSize();
if (lightbuffertype == GL_UNIFORM_BUFFER)
{
// This differentiation is for some Intel drivers which fail on #extension, so use of #version 140 is necessary
if (gl.glslversion < 1.4f || gl.version < 3.1f)
{
vp_comb.Format("#version 130\n#extension GL_ARB_uniform_buffer_object : require\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize);
}
else
{
vp_comb.Format("#version 140\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize);
}
}
else
{
vp_comb = "#version 400 core\n#extension GL_ARB_shader_storage_buffer_object : require\n#define SHADER_STORAGE_LIGHTS\n";
}
} }
if (gl.buffermethod == BM_DEFERRED) if (gl.buffermethod == BM_DEFERRED)
{ {
vp_comb << "#define USE_QUAD_DRAWER\n"; vp_comb << "#define USE_QUAD_DRAWER\n";
@ -169,12 +156,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
} }
} }
if (gl.glslversion < 1.3) if (gl.flags & RFL_NO_CLIP_PLANES)
{
FShaderProgram::PatchVertShader(vp_comb);
FShaderProgram::PatchFragShader(fp_comb);
}
else if (gl.flags & RFL_NO_CLIP_PLANES)
{ {
// On ATI's GL3 drivers we have to disable gl_ClipDistance because it's hopelessly broken. // On ATI's GL3 drivers we have to disable gl_ClipDistance because it's hopelessly broken.
// This will cause some glitches and regressions but is the only way to avoid total display garbage. // This will cause some glitches and regressions but is the only way to avoid total display garbage.
@ -274,7 +256,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
texcoordmatrix_index = glGetUniformLocation(hShader, "uQuadTexCoords"); texcoordmatrix_index = glGetUniformLocation(hShader, "uQuadTexCoords");
quadmode_index = glGetUniformLocation(hShader, "uQuadMode"); quadmode_index = glGetUniformLocation(hShader, "uQuadMode");
if (LM_SOFTWARE != gl.lightmethod && !(gl.flags & RFL_SHADER_STORAGE_BUFFER)) if (!gl.legacyMode && !(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{ {
int tempindex = glGetUniformBlockIndex(hShader, "LightBufferUBO"); int tempindex = glGetUniformBlockIndex(hShader, "LightBufferUBO");
if (tempindex != -1) glUniformBlockBinding(hShader, tempindex, LIGHTBUF_BINDINGPOINT); if (tempindex != -1) glUniformBlockBinding(hShader, tempindex, LIGHTBUF_BINDINGPOINT);
@ -425,7 +407,7 @@ static const FEffectShader effectshaders[]=
FShaderManager::FShaderManager() FShaderManager::FShaderManager()
{ {
if (gl.glslversion > 0) CompileShaders(); if (!gl.legacyMode) CompileShaders();
} }
//========================================================================== //==========================================================================
@ -436,7 +418,7 @@ FShaderManager::FShaderManager()
FShaderManager::~FShaderManager() FShaderManager::~FShaderManager()
{ {
if (gl.glslversion > 0) Clean(); if (!gl.legacyMode) Clean();
} }
//========================================================================== //==========================================================================
@ -578,7 +560,7 @@ EXTERN_CVAR(Int, gl_fuzztype)
void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view) void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view)
{ {
if (gl.glslversion == 0) if (gl.legacyMode)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadMatrixf(proj->get()); glLoadMatrixf(proj->get());

View file

@ -240,24 +240,13 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const
if (defines) if (defines)
patchedCode << defines; patchedCode << defines;
if (gl.glslversion >= 1.3) // these settings are actually pointless but there seem to be some old ATI drivers that fail to compile the shader without setting the precision here.
{ patchedCode << "precision highp int;\n";
// these settings are actually pointless but there seem to be some old ATI drivers that fail to compile the shader without setting the precision here. patchedCode << "precision highp float;\n";
patchedCode << "precision highp int;\n";
patchedCode << "precision highp float;\n";
}
patchedCode << "#line 1\n"; patchedCode << "#line 1\n";
patchedCode << code; patchedCode << code;
if (gl.glslversion < 1.3)
{
if (type == Vertex)
PatchVertShader(patchedCode);
else if (type == Fragment)
PatchFragShader(patchedCode);
}
return patchedCode; return patchedCode;
} }
@ -268,36 +257,3 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const
// //
//========================================================================== //==========================================================================
void FShaderProgram::PatchCommon(FString &code)
{
code.Substitute("precision highp int;", "");
code.Substitute("precision highp float;", "");
}
void FShaderProgram::PatchVertShader(FString &code)
{
PatchCommon(code);
code.Substitute("in vec", "attribute vec");
code.Substitute("in float", "attribute float");
code.Substitute("out vec", "varying vec");
code.Substitute("out float", "varying float");
code.Substitute("gl_ClipDistance", "//");
}
void FShaderProgram::PatchFragShader(FString &code)
{
PatchCommon(code);
code.Substitute("out vec4 FragColor;", "");
code.Substitute("FragColor", "gl_FragColor");
code.Substitute("in vec", "varying vec");
// this patches the switch statement to if's.
code.Substitute("break;", "");
code.Substitute("switch (uFixedColormap)", "int i = uFixedColormap;");
code.Substitute("case 0:", "if (i == 0)");
code.Substitute("case 1:", "else if (i == 1)");
code.Substitute("case 2:", "else if (i == 2)");
code.Substitute("case 3:", "else if (i == 3)");
code.Substitute("case 4:", "else if (i == 4)");
code.Substitute("case 5:", "else if (i == 5)");
code.Substitute("texture(", "texture2D(");
}

View file

@ -26,16 +26,11 @@ public:
operator GLuint() const { return mProgram; } operator GLuint() const { return mProgram; }
explicit operator bool() const { return mProgram != 0; } explicit operator bool() const { return mProgram != 0; }
// Needed by FShader
static void PatchVertShader(FString &code);
static void PatchFragShader(FString &code);
private: private:
FShaderProgram(const FShaderProgram &) = delete; FShaderProgram(const FShaderProgram &) = delete;
FShaderProgram &operator=(const FShaderProgram &) = delete; FShaderProgram &operator=(const FShaderProgram &) = delete;
static FString PatchShader(ShaderType type, const FString &code, const char *defines, int maxGlslVersion); static FString PatchShader(ShaderType type, const FString &code, const char *defines, int maxGlslVersion);
static void PatchCommon(FString &code);
void CreateShader(ShaderType type); void CreateShader(ShaderType type);
FString GetShaderInfoLog(GLuint handle); FString GetShaderInfoLog(GLuint handle);

View file

@ -162,7 +162,7 @@ void OpenGLFrameBuffer::InitializeState()
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_DEPTH_CLAMP); glEnable(GL_DEPTH_CLAMP);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
if (gl.glslversion == 0) glEnable(GL_TEXTURE_2D); if (gl.legacyMode) glEnable(GL_TEXTURE_2D);
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -179,9 +179,6 @@ void OpenGLFrameBuffer::InitializeState()
// //
//========================================================================== //==========================================================================
// Testing only for now.
CVAR(Bool, gl_draw_sync, true, 0) //false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
void OpenGLFrameBuffer::Update() void OpenGLFrameBuffer::Update()
{ {
if (!CanUpdate()) if (!CanUpdate())
@ -197,10 +194,7 @@ void OpenGLFrameBuffer::Update()
GLRenderer->SetOutputViewport(nullptr); GLRenderer->SetOutputViewport(nullptr);
if (gl_draw_sync || !swapped) Swap();
{
Swap();
}
swapped = false; swapped = false;
Unlock(); Unlock();
CheckBench(); CheckBench();

View file

@ -154,10 +154,10 @@ void gl_LoadExtensions()
else Printf("Emulating OpenGL v %s\n", version); else Printf("Emulating OpenGL v %s\n", version);
} }
gl.version = strtod(version, NULL) + 0.01f; float gl_version = (float)strtod(version, NULL) + 0.01f;
// Don't even start if it's lower than 2.0 or no framebuffers are available // Don't even start if it's lower than 2.0 or no framebuffers are available (The framebuffer extension is needed for glGenerateMipmapsEXT!)
if ((gl.version < 2.0 || !CheckExtension("GL_EXT_framebuffer_object")) && gl.version < 3.0) if ((gl_version < 2.0f || !CheckExtension("GL_EXT_framebuffer_object")) && gl_version < 3.0f)
{ {
I_FatalError("Unsupported OpenGL version.\nAt least OpenGL 2.0 with framebuffer support is required to run " GAMENAME ".\n"); I_FatalError("Unsupported OpenGL version.\nAt least OpenGL 2.0 with framebuffer support is required to run " GAMENAME ".\n");
} }
@ -166,105 +166,86 @@ void gl_LoadExtensions()
gl.glslversion = strtod((char*)glGetString(GL_SHADING_LANGUAGE_VERSION), NULL) + 0.01f; gl.glslversion = strtod((char*)glGetString(GL_SHADING_LANGUAGE_VERSION), NULL) + 0.01f;
gl.vendorstring = (char*)glGetString(GL_VENDOR); gl.vendorstring = (char*)glGetString(GL_VENDOR);
gl.lightmethod = LM_SOFTWARE;
gl.buffermethod = BM_CLIENTARRAY;
if ((gl.version >= 3.3f || CheckExtension("GL_ARB_sampler_objects")) && !Args->CheckParm("-nosampler")) // first test for optional features
if (CheckExtension("GL_ARB_texture_compression")) gl.flags |= RFL_TEXTURE_COMPRESSION;
if (CheckExtension("GL_EXT_texture_compression_s3tc")) gl.flags |= RFL_TEXTURE_COMPRESSION_S3TC;
if ((gl_version >= 3.3f || CheckExtension("GL_ARB_sampler_objects")) && !Args->CheckParm("-nosampler"))
{ {
gl.flags |= RFL_SAMPLER_OBJECTS; gl.flags |= RFL_SAMPLER_OBJECTS;
} }
// Buffer lighting is only feasible with GLSL 1.3 and higher, even if 1.2 supports the extension. // The minimum requirement for the modern render path are GL 3.0 + uniform buffers
if (gl.version > 3.0f && (gl.version >= 3.3f || CheckExtension("GL_ARB_uniform_buffer_object"))) if (gl_version < 3.0f || (gl_version < 3.1f && !CheckExtension("GL_ARB_uniform_buffer_object")))
{ {
gl.lightmethod = LM_DEFERRED; gl.legacyMode = true;
gl.buffermethod = BM_DEFERRED; gl.lightmethod = LM_LEGACY;
} gl.buffermethod = BM_LEGACY;
if (CheckExtension("GL_ARB_texture_compression")) gl.flags |= RFL_TEXTURE_COMPRESSION;
if (CheckExtension("GL_EXT_texture_compression_s3tc")) gl.flags |= RFL_TEXTURE_COMPRESSION_S3TC;
if (Args->CheckParm("-noshader")/* || gl.glslversion < 1.2f*/)
{
gl.version = 2.11f;
gl.glslversion = 0; gl.glslversion = 0;
gl.lightmethod = LM_SOFTWARE;
gl.flags |= RFL_NO_CLIP_PLANES; gl.flags |= RFL_NO_CLIP_PLANES;
} }
else if (gl.version < 3.0f)
{
if (CheckExtension("GL_NV_GPU_shader4") || CheckExtension("GL_EXT_GPU_shader4")) gl.glslversion = 1.21f; // for pre-3.0 drivers that support capable hardware. Needed for Apple.
else
{
gl.buffermethod = BM_CLIENTARRAY;
gl.glslversion = 0;
}
if (!CheckExtension("GL_EXT_packed_float")) gl.flags |= RFL_NO_RGBA16F;
if (!CheckExtension("GL_EXT_packed_depth_stencil")) gl.flags |= RFL_NO_DEPTHSTENCIL;
gl.flags |= RFL_NO_CLIP_PLANES;
}
else if (gl.version < 4.f)
{
#ifdef _WIN32
if (strstr(gl.vendorstring, "ATI Tech"))
{
gl.flags |= RFL_NO_CLIP_PLANES; // gl_ClipDistance is horribly broken on ATI GL3 drivers for Windows.
}
#endif
}
else if (gl.version < 4.5f)
{
// don't use GL 4.x features when running in GL 3 emulation mode.
if (CheckExtension("GL_ARB_buffer_storage"))
{
// work around a problem with older AMD drivers: Their implementation of shader storage buffer objects is piss-poor and does not match uniform buffers even closely.
// Recent drivers, GL 4.4 don't have this problem, these can easily be recognized by also supporting the GL_ARB_buffer_storage extension.
if (CheckExtension("GL_ARB_shader_storage_buffer_object"))
{
// Shader storage buffer objects are broken on current Intel drivers.
if (strstr(gl.vendorstring, "Intel") == NULL)
{
gl.flags |= RFL_SHADER_STORAGE_BUFFER;
}
}
gl.flags |= RFL_BUFFER_STORAGE;
gl.lightmethod = LM_DIRECT;
gl.buffermethod = BM_PERSISTENT;
}
else
{
gl.version = 3.3f;
}
}
else else
{ {
// Assume that everything works without problems on GL 4.5 drivers where these things are core features. gl.legacyMode = false;
gl.flags |= RFL_SHADER_STORAGE_BUFFER | RFL_BUFFER_STORAGE; gl.lightmethod = LM_DEFERRED;
gl.lightmethod = LM_DIRECT; gl.buffermethod = BM_DEFERRED;
gl.buffermethod = BM_PERSISTENT; if (gl_version < 4.f)
} {
#ifdef _WIN32
if (strstr(gl.vendorstring, "ATI Tech"))
{
gl.flags |= RFL_NO_CLIP_PLANES; // gl_ClipDistance is horribly broken on ATI GL3 drivers for Windows.
}
#endif
}
else if (gl_version < 4.5f)
{
// don't use GL 4.x features when running a GL 3.x context.
if (CheckExtension("GL_ARB_buffer_storage"))
{
// work around a problem with older AMD drivers: Their implementation of shader storage buffer objects is piss-poor and does not match uniform buffers even closely.
// Recent drivers, GL 4.4 don't have this problem, these can easily be recognized by also supporting the GL_ARB_buffer_storage extension.
if (CheckExtension("GL_ARB_shader_storage_buffer_object"))
{
// Shader storage buffer objects are broken on current Intel drivers.
if (strstr(gl.vendorstring, "Intel") == NULL)
{
gl.flags |= RFL_SHADER_STORAGE_BUFFER;
}
}
gl.flags |= RFL_BUFFER_STORAGE;
gl.lightmethod = LM_DIRECT;
gl.buffermethod = BM_PERSISTENT;
}
}
else
{
// Assume that everything works without problems on GL 4.5 drivers where these things are core features.
gl.flags |= RFL_SHADER_STORAGE_BUFFER | RFL_BUFFER_STORAGE;
gl.lightmethod = LM_DIRECT;
gl.buffermethod = BM_PERSISTENT;
}
if (gl.version >= 4.3f || CheckExtension("GL_ARB_invalidate_subdata")) gl.flags |= RFL_INVALIDATE_BUFFER; if (gl_version >= 4.3f || CheckExtension("GL_ARB_invalidate_subdata")) gl.flags |= RFL_INVALIDATE_BUFFER;
if (gl.version >= 4.3f || CheckExtension("GL_KHR_debug")) gl.flags |= RFL_DEBUG; if (gl_version >= 4.3f || CheckExtension("GL_KHR_debug")) gl.flags |= RFL_DEBUG;
const char *lm = Args->CheckValue("-lightmethod"); const char *lm = Args->CheckValue("-lightmethod");
if (lm != NULL) if (lm != NULL)
{ {
if (!stricmp(lm, "deferred") && gl.lightmethod == LM_DIRECT) gl.lightmethod = LM_DEFERRED; if (!stricmp(lm, "deferred") && gl.lightmethod == LM_DIRECT) gl.lightmethod = LM_DEFERRED;
if (!stricmp(lm, "textured")) gl.lightmethod = LM_SOFTWARE; }
}
lm = Args->CheckValue("-buffermethod"); lm = Args->CheckValue("-buffermethod");
if (lm != NULL) if (lm != NULL)
{ {
if (!stricmp(lm, "deferred") && gl.buffermethod == BM_PERSISTENT) gl.buffermethod = BM_DEFERRED; if (!stricmp(lm, "deferred") && gl.buffermethod == BM_PERSISTENT) gl.buffermethod = BM_DEFERRED;
if (!stricmp(lm, "clientarray")) gl.buffermethod = BM_CLIENTARRAY; }
} }
int v; int v;
if (gl.lightmethod != LM_SOFTWARE && !(gl.flags & RFL_SHADER_STORAGE_BUFFER)) if (!gl.legacyMode && !(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{ {
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v); glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v);
gl.maxuniforms = v; gl.maxuniforms = v;
@ -284,24 +265,27 @@ void gl_LoadExtensions()
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl.max_texturesize); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl.max_texturesize);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// fudge a bit with the framebuffer stuff to avoid redundancies in the main code. Some of the older cards do not have the ARB stuff but the calls are nearly identical. if (gl.legacyMode)
FUDGE_FUNC(glGenerateMipmap, EXT); {
FUDGE_FUNC(glGenFramebuffers, EXT); // fudge a bit with the framebuffer stuff to avoid redundancies in the main code. Some of the older cards do not have the ARB stuff but the calls are nearly identical.
FUDGE_FUNC(glBindFramebuffer, EXT); FUDGE_FUNC(glGenerateMipmap, EXT);
FUDGE_FUNC(glDeleteFramebuffers, EXT); FUDGE_FUNC(glGenFramebuffers, EXT);
FUDGE_FUNC(glFramebufferTexture2D, EXT); FUDGE_FUNC(glBindFramebuffer, EXT);
FUDGE_FUNC(glGenerateMipmap, EXT); FUDGE_FUNC(glDeleteFramebuffers, EXT);
FUDGE_FUNC(glGenFramebuffers, EXT); FUDGE_FUNC(glFramebufferTexture2D, EXT);
FUDGE_FUNC(glBindFramebuffer, EXT); FUDGE_FUNC(glGenerateMipmap, EXT);
FUDGE_FUNC(glDeleteFramebuffers, EXT); FUDGE_FUNC(glGenFramebuffers, EXT);
FUDGE_FUNC(glFramebufferTexture2D, EXT); FUDGE_FUNC(glBindFramebuffer, EXT);
FUDGE_FUNC(glFramebufferRenderbuffer, EXT); FUDGE_FUNC(glDeleteFramebuffers, EXT);
FUDGE_FUNC(glGenRenderbuffers, EXT); FUDGE_FUNC(glFramebufferTexture2D, EXT);
FUDGE_FUNC(glDeleteRenderbuffers, EXT); FUDGE_FUNC(glFramebufferRenderbuffer, EXT);
FUDGE_FUNC(glRenderbufferStorage, EXT); FUDGE_FUNC(glGenRenderbuffers, EXT);
FUDGE_FUNC(glBindRenderbuffer, EXT); FUDGE_FUNC(glDeleteRenderbuffers, EXT);
FUDGE_FUNC(glCheckFramebufferStatus, EXT); FUDGE_FUNC(glRenderbufferStorage, EXT);
gl_PatchMenu(); FUDGE_FUNC(glBindRenderbuffer, EXT);
FUDGE_FUNC(glCheckFramebufferStatus, EXT);
gl_PatchMenu();
}
} }
//========================================================================== //==========================================================================
@ -313,7 +297,7 @@ void gl_LoadExtensions()
void gl_PrintStartupLog() void gl_PrintStartupLog()
{ {
int v = 0; int v = 0;
if (gl.version >= 3.2) glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &v); if (!gl.legacyMode) glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &v);
Printf ("GL_VENDOR: %s\n", glGetString(GL_VENDOR)); Printf ("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
Printf ("GL_RENDERER: %s\n", glGetString(GL_RENDERER)); Printf ("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
@ -332,7 +316,7 @@ void gl_PrintStartupLog()
glGetIntegerv(GL_MAX_VARYING_FLOATS, &v); glGetIntegerv(GL_MAX_VARYING_FLOATS, &v);
Printf ("Max. varying: %d\n", v); Printf ("Max. varying: %d\n", v);
if (gl.lightmethod != LM_SOFTWARE && !(gl.flags & RFL_SHADER_STORAGE_BUFFER)) if (!gl.legacyMode && !(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{ {
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &v); glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &v);
Printf ("Max. uniform block size: %d\n", v); Printf ("Max. uniform block size: %d\n", v);
@ -349,7 +333,7 @@ void gl_PrintStartupLog()
} }
// For shader-less, the special alphatexture translation must be changed to actually set the alpha, because it won't get translated by a shader. // For shader-less, the special alphatexture translation must be changed to actually set the alpha, because it won't get translated by a shader.
if (gl.glslversion == 0) if (gl.legacyMode)
{ {
FRemapTable *remap = translationtables[TRANSLATION_Standard][8]; FRemapTable *remap = translationtables[TRANSLATION_Standard][8];
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)

View file

@ -21,12 +21,10 @@ enum RenderFlags
RFL_BUFFER_STORAGE = 8, RFL_BUFFER_STORAGE = 8,
RFL_SAMPLER_OBJECTS = 16, RFL_SAMPLER_OBJECTS = 16,
RFL_NO_RGBA16F = 32, RFL_NO_CLIP_PLANES = 32,
RFL_NO_DEPTHSTENCIL = 64,
RFL_NO_CLIP_PLANES = 128,
RFL_INVALIDATE_BUFFER = 256, RFL_INVALIDATE_BUFFER = 64,
RFL_DEBUG = 512 RFL_DEBUG = 128
}; };
enum TexMode enum TexMode
@ -43,15 +41,15 @@ enum TexMode
enum ELightMethod enum ELightMethod
{ {
LM_SOFTWARE = 0, // multi-pass texturing LM_LEGACY = 0, // placeholder for legacy mode (textured lights), should not be checked anywhere in the code!
LM_DEFERRED = 1, // calculate lights up front in a separate pass LM_DEFERRED = 1, // calculate lights up front in a separate pass
LM_DIRECT = 2, // calculate lights on the fly along with the render data LM_DIRECT = 2, // calculate lights on the fly along with the render data
}; };
enum EBufferMethod enum EBufferMethod
{ {
BM_CLIENTARRAY = 0, // use a client array instead of a hardware buffer BM_LEGACY = 0, // placeholder for legacy mode (client arrays), should not be checked anywhere in the code!
BM_DEFERRED = 1, // use a temporarily mapped buffer (only necessary on GL 3.x core profile, i.e. Apple) BM_DEFERRED = 1, // use a temporarily mapped buffer, for GL 3.x core profile
BM_PERSISTENT = 2 // use a persistently mapped buffer BM_PERSISTENT = 2 // use a persistently mapped buffer
}; };
@ -64,10 +62,10 @@ struct RenderContext
unsigned int uniformblockalignment; unsigned int uniformblockalignment;
int lightmethod; int lightmethod;
int buffermethod; int buffermethod;
float version;
float glslversion; float glslversion;
int max_texturesize; int max_texturesize;
char * vendorstring; char * vendorstring;
bool legacyMode;
int MaxLights() const int MaxLights() const
{ {

View file

@ -264,7 +264,7 @@ unsigned char *gl_CreateUpsampledTextureBuffer ( const FTexture *inputTexture, u
return inputBuffer; return inputBuffer;
// [BB] Don't upsample non-shader handled warped textures. Needs too much memory and time // [BB] Don't upsample non-shader handled warped textures. Needs too much memory and time
if (gl.glslversion == 0 && inputTexture->bWarped) if (gl.legacyMode && inputTexture->bWarped)
return inputBuffer; return inputBuffer;
// already scaled? // already scaled?

View file

@ -296,7 +296,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla
if (translation <= 0) translation = -translation; if (translation <= 0) translation = -translation;
else else
{ {
alphatrans = (gl.glslversion == 0 && translation == TRANSLATION(TRANSLATION_Standard, 8)); alphatrans = (gl.legacyMode && translation == TRANSLATION(TRANSLATION_Standard, 8));
translation = GLTranslationPalette::GetInternalTranslation(translation); translation = GLTranslationPalette::GetInternalTranslation(translation);
} }
@ -307,7 +307,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla
if (hwtex) if (hwtex)
{ {
// Texture has become invalid // Texture has become invalid
if ((!tex->bHasCanvas && (!tex->bWarped || gl.glslversion == 0)) && tex->CheckModified()) if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified())
{ {
Clean(true); Clean(true);
hwtex = CreateHwTexture(); hwtex = CreateHwTexture();
@ -325,7 +325,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla
if (!tex->bHasCanvas) if (!tex->bHasCanvas)
{ {
buffer = CreateTexBuffer(translation, w, h, hirescheck, true, alphatrans); buffer = CreateTexBuffer(translation, w, h, hirescheck, true, alphatrans);
if (tex->bWarped && gl.glslversion == 0 && w*h <= 256*256) // do not software-warp larger textures, especially on the old systems that still need this fallback. if (tex->bWarped && gl.legacyMode && w*h <= 256*256) // do not software-warp larger textures, especially on the old systems that still need this fallback.
{ {
// need to do software warping // need to do software warping
FWarpTexture *wt = static_cast<FWarpTexture*>(tex); FWarpTexture *wt = static_cast<FWarpTexture*>(tex);
@ -489,7 +489,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded)
mSpriteU[0] = mSpriteV[0] = 0.f; mSpriteU[0] = mSpriteV[0] = 0.f;
mSpriteU[1] = mSpriteV[1] = 1.f; mSpriteU[1] = mSpriteV[1] = 1.f;
FTexture *basetex = (tx->bWarped && gl.glslversion == 0)? tx : tx->GetRedirect(false); FTexture *basetex = (tx->bWarped && gl.legacyMode)? tx : tx->GetRedirect(false);
// allow the redirect only if the textute is not expanded or the scale matches. // allow the redirect only if the textute is not expanded or the scale matches.
if (!expanded || (tx->Scale.X == basetex->Scale.X && tx->Scale.Y == basetex->Scale.Y)) if (!expanded || (tx->Scale.X == basetex->Scale.X && tx->Scale.Y == basetex->Scale.Y))
{ {

View file

@ -190,6 +190,9 @@ typedef NSInteger NSApplicationActivationPolicy;
static const NSWindowCollectionBehavior NSWindowCollectionBehaviorFullScreenAuxiliary = NSWindowCollectionBehavior(1 << 8); static const NSWindowCollectionBehavior NSWindowCollectionBehaviorFullScreenAuxiliary = NSWindowCollectionBehavior(1 << 8);
static const NSOpenGLPixelFormatAttribute NSOpenGLPFAOpenGLProfile(96);
static const NSOpenGLPixelFormatAttribute NSOpenGLProfileVersion3_2Core(0x3200);
#endif // prior to 10.7 #endif // prior to 10.7
#endif // COCOA_I_COMMON_INCLUDED #endif // COCOA_I_COMMON_INCLUDED

View file

@ -233,7 +233,7 @@ namespace
class CocoaVideo : public IVideo class CocoaVideo : public IVideo
{ {
public: public:
explicit CocoaVideo(int multisample); CocoaVideo();
virtual EDisplayType GetDisplayType() { return DISPLAY_Both; } virtual EDisplayType GetDisplayType() { return DISPLAY_Both; }
virtual void SetWindowedScale(float scale); virtual void SetWindowedScale(float scale);
@ -465,7 +465,7 @@ CocoaWindow* CreateCocoaWindow(const NSUInteger styleMask)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
CocoaVideo::CocoaVideo(const int multisample) CocoaVideo::CocoaVideo()
: m_window(CreateCocoaWindow(STYLE_MASK_WINDOWED)) : m_window(CreateCocoaWindow(STYLE_MASK_WINDOWED))
, m_width(-1) , m_width(-1)
, m_height(-1) , m_height(-1)
@ -492,13 +492,10 @@ CocoaVideo::CocoaVideo(const int multisample)
attributes[i++] = NSOpenGLPFAAllowOfflineRenderers; attributes[i++] = NSOpenGLPFAAllowOfflineRenderers;
} }
if (multisample) if (NSAppKitVersionNumber >= AppKit10_7)
{ {
attributes[i++] = NSOpenGLPFAMultisample; attributes[i++] = NSOpenGLPFAOpenGLProfile;
attributes[i++] = NSOpenGLPFASampleBuffers; attributes[i++] = NSOpenGLProfileVersion3_2Core;
attributes[i++] = NSOpenGLPixelFormatAttribute(1);
attributes[i++] = NSOpenGLPFASamples;
attributes[i++] = NSOpenGLPixelFormatAttribute(multisample);
} }
attributes[i] = NSOpenGLPixelFormatAttribute(0); attributes[i] = NSOpenGLPixelFormatAttribute(0);
@ -1254,7 +1251,7 @@ void I_InitGraphics()
val.Bool = !!Args->CheckParm("-devparm"); val.Bool = !!Args->CheckParm("-devparm");
ticker.SetGenericRepDefault(val, CVAR_Bool); ticker.SetGenericRepDefault(val, CVAR_Bool);
Video = new CocoaVideo(0); Video = new CocoaVideo;
atterm(I_ShutdownGraphics); atterm(I_ShutdownGraphics);
} }

View file

@ -748,11 +748,9 @@ bool Win32GLVideo::InitHardware (HWND Window, int multisample)
} }
int prof = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; int prof = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
const char *lm = Args->CheckValue("-buffermethod"); const char *version = Args->CheckValue("-glversion");
if (lm != NULL)
{ if (version != nullptr && strcmp(version, "3.0") < 0) prof = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
if (!stricmp(lm, "clientarray")) prof = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
}
for (; prof <= WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; prof++) for (; prof <= WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; prof++)
{ {

View file

@ -0,0 +1,16 @@
in vec2 TexCoord;
out vec4 FragColor;
uniform sampler2D tex;
uniform vec4 uFixedColormapStart;
uniform vec4 uFixedColormapRange;
void main()
{
vec4 frag = texture(tex, TexCoord);
float gray = (frag.r * 0.3 + frag.g * 0.56 + frag.b * 0.14);
vec4 cm = uFixedColormapStart + gray * uFixedColormapRange;
FragColor = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a);
}

View file

@ -133,32 +133,6 @@ vec4 desaturate(vec4 texel)
// //
//=========================================================================== //===========================================================================
#ifdef GLSL12_COMPATIBLE
vec4 getTexel(vec2 st)
{
vec4 texel = texture(tex, st);
//
// Apply texture modes
//
if (uTextureMode != 0)
{
if (uTextureMode == 1) texel.rgb = vec3(1.0,1.0,1.0);
else if (uTextureMode == 2) texel.a = 1.0;
else if (uTextureMode == 3) texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, texel.a);
else if (uTextureMode == 4) texel = vec4(1.0, 1.0, 1.0, texel.r*texel.a);
else if (uTextureMode == 5)
{
if (st.t < 0.0 || st.t > 1.0)
{
texel.a = 0.0;
}
}
}
texel *= uObjectColor;
return desaturate(texel);
}
#else
vec4 getTexel(vec2 st) vec4 getTexel(vec2 st)
{ {
vec4 texel = texture(tex, st); vec4 texel = texture(tex, st);
@ -195,7 +169,6 @@ vec4 getTexel(vec2 st)
return desaturate(texel); return desaturate(texel);
} }
#endif
//=========================================================================== //===========================================================================
// //

View file

@ -70,17 +70,10 @@ uniform sampler2D PaletteLUT;
vec3 Tonemap(vec3 color) vec3 Tonemap(vec3 color)
{ {
ivec3 c = ivec3(clamp(color.rgb, vec3(0.0), vec3(1.0)) * 255.0 + 0.5); ivec3 c = ivec3(clamp(color.rgb, vec3(0.0), vec3(1.0)) * 255.0 + 0.5);
#if __VERSION__ < 130
int index = (c.r / 4 * 64 + c.g / 4) * 64 + c.b / 4;
float tx = mod(index, 512) / 512.0;
float ty = float(index / 512) / 512.0;
return texture2D(PaletteLUT, vec2(tx, ty)).rgb;
#else
int index = ((c.r >> 2) * 64 + (c.g >> 2)) * 64 + (c.b >> 2); int index = ((c.r >> 2) * 64 + (c.g >> 2)) * 64 + (c.b >> 2);
int tx = index % 512; int tx = index % 512;
int ty = index / 512; int ty = index / 512;
return texelFetch(PaletteLUT, ivec2(tx, ty), 0).rgb; return texelFetch(PaletteLUT, ivec2(tx, ty), 0).rgb;
#endif
} }
#else #else