Moved state to FGLPostProcessState and merged vertex shaders
This commit is contained in:
parent
13a2bf57e5
commit
346badf25f
13 changed files with 176 additions and 154 deletions
|
|
@ -63,6 +63,7 @@
|
|||
#include "gl/renderer/gl_renderstate.h"
|
||||
#include "gl/renderer/gl_renderbuffers.h"
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/renderer/gl_postprocessstate.h"
|
||||
#include "gl/data/gl_data.h"
|
||||
#include "gl/data/gl_vertexbuffer.h"
|
||||
#include "gl/shaders/gl_bloomshader.h"
|
||||
|
|
@ -117,34 +118,11 @@ void FGLRenderer::BloomScene()
|
|||
if (!gl_bloom || !FGLRenderBuffers::IsEnabled() || gl_fixedcolormap != CM_DEFAULT)
|
||||
return;
|
||||
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
const float blurAmount = gl_bloom_amount;
|
||||
int sampleCount = gl_bloom_kernel_size;
|
||||
|
||||
// TBD: Maybe need a better way to share state with other parts of the pipeline
|
||||
GLint activeTex, textureBinding, samplerBinding;
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
{
|
||||
glGetIntegerv(GL_SAMPLER_BINDING, &samplerBinding);
|
||||
glBindSampler(0, 0);
|
||||
}
|
||||
GLboolean blendEnabled, scissorEnabled;
|
||||
GLint currentProgram, blendEquationRgb, blendEquationAlpha, blendSrcRgb, blendSrcAlpha, blendDestRgb, blendDestAlpha;
|
||||
glGetBooleanv(GL_BLEND, &blendEnabled);
|
||||
glGetBooleanv(GL_SCISSOR_TEST, &scissorEnabled);
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
||||
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRgb);
|
||||
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
|
||||
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRgb);
|
||||
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
|
||||
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRgb);
|
||||
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
const auto &level0 = mBuffers->BloomLevels[0];
|
||||
|
||||
// Extract blooming pixels from scene texture:
|
||||
|
|
@ -207,18 +185,6 @@ void FGLRenderer::BloomScene()
|
|||
mBloomCombineShader->Bind();
|
||||
mBloomCombineShader->BloomTexture.Set(0);
|
||||
mVBO->RenderScreenQuad();
|
||||
|
||||
if (blendEnabled)
|
||||
glEnable(GL_BLEND);
|
||||
if (scissorEnabled)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glBlendEquationSeparate(blendEquationRgb, blendEquationAlpha);
|
||||
glBlendFuncSeparate(blendSrcRgb, blendDestRgb, blendSrcAlpha, blendDestAlpha);
|
||||
glUseProgram(currentProgram);
|
||||
glBindTexture(GL_TEXTURE_2D, textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
glBindSampler(0, samplerBinding);
|
||||
glActiveTexture(activeTex);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -232,22 +198,7 @@ void FGLRenderer::TonemapScene()
|
|||
if (gl_tonemap == 0)
|
||||
return;
|
||||
|
||||
GLint activeTex, textureBinding, samplerBinding;
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
{
|
||||
glGetIntegerv(GL_SAMPLER_BINDING, &samplerBinding);
|
||||
glBindSampler(0, 0);
|
||||
}
|
||||
|
||||
GLboolean blendEnabled, scissorEnabled;
|
||||
glGetBooleanv(GL_BLEND, &blendEnabled);
|
||||
glGetBooleanv(GL_SCISSOR_TEST, &scissorEnabled);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
mBuffers->BindNextFB();
|
||||
mBuffers->BindCurrentTexture(0);
|
||||
|
|
@ -257,15 +208,6 @@ void FGLRenderer::TonemapScene()
|
|||
mVBO->BindVBO();
|
||||
mVBO->RenderScreenQuad();
|
||||
mBuffers->NextTexture();
|
||||
|
||||
if (blendEnabled)
|
||||
glEnable(GL_BLEND);
|
||||
if (scissorEnabled)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glBindTexture(GL_TEXTURE_2D, textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
glBindSampler(0, samplerBinding);
|
||||
glActiveTexture(activeTex);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -279,23 +221,6 @@ void FGLRenderer::LensDistortScene()
|
|||
if (gl_lens == 0)
|
||||
return;
|
||||
|
||||
GLint activeTex, textureBinding, samplerBinding;
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
{
|
||||
glGetIntegerv(GL_SAMPLER_BINDING, &samplerBinding);
|
||||
glBindSampler(0, 0);
|
||||
}
|
||||
|
||||
GLboolean blendEnabled, scissorEnabled;
|
||||
glGetBooleanv(GL_BLEND, &blendEnabled);
|
||||
glGetBooleanv(GL_SCISSOR_TEST, &scissorEnabled);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
float k[4] =
|
||||
{
|
||||
gl_lens_k,
|
||||
|
|
@ -321,6 +246,8 @@ void FGLRenderer::LensDistortScene()
|
|||
float f = MAX(f0, f2);
|
||||
float scale = 1.0f / f;
|
||||
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
mBuffers->BindNextFB();
|
||||
mBuffers->BindCurrentTexture(0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
|
@ -333,16 +260,9 @@ void FGLRenderer::LensDistortScene()
|
|||
mLensShader->CubicDistortionValue.Set(kcube);
|
||||
mVBO->BindVBO();
|
||||
mVBO->RenderScreenQuad();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
mBuffers->NextTexture();
|
||||
|
||||
if (blendEnabled)
|
||||
glEnable(GL_BLEND);
|
||||
if (scissorEnabled)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glBindTexture(GL_TEXTURE_2D, textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
glBindSampler(0, samplerBinding);
|
||||
glActiveTexture(activeTex);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -355,23 +275,7 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
|
|||
{
|
||||
if (FGLRenderBuffers::IsEnabled())
|
||||
{
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
|
||||
GLboolean blendEnabled;
|
||||
GLint currentProgram;
|
||||
GLint activeTex, textureBinding, samplerBinding;
|
||||
glGetBooleanv(GL_BLEND, &blendEnabled);
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
{
|
||||
glGetIntegerv(GL_SAMPLER_BINDING, &samplerBinding);
|
||||
glBindSampler(0, 0);
|
||||
}
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
mBuffers->BindOutputFB();
|
||||
|
||||
|
|
@ -446,13 +350,5 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
mVBO->BindVBO();
|
||||
mVBO->RenderScreenQuad(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
|
||||
|
||||
if (blendEnabled)
|
||||
glEnable(GL_BLEND);
|
||||
glUseProgram(currentProgram);
|
||||
glBindTexture(GL_TEXTURE_2D, textureBinding);
|
||||
if (gl.flags & RFL_SAMPLER_OBJECTS)
|
||||
glBindSampler(0, samplerBinding);
|
||||
glActiveTexture(activeTex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue