- use static buffer data and a uniform to handle the texture positioning of the present shader.

That's again one less write access to the buffer. The uniform method was chosen because this way a buffer update can be completely avoided, and setting a single uniform is a lot cheaper and simpler to handle.
This commit is contained in:
Christoph Oelckers 2016-08-08 16:06:02 +02:00
parent 8daaf61160
commit 675822004d
7 changed files with 37 additions and 11 deletions

View file

@ -126,7 +126,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
map = new FFlatVertex[BUFFER_SIZE];
}
mIndex = mCurIndex = 0;
mNumReserved = 8;
mNumReserved = 12;
vbo_shadowdata.Resize(mNumReserved);
// the first quad is reserved for handling coordinates through uniforms.
@ -141,6 +141,12 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
vbo_shadowdata[6].Set((float)width, 0, 0, 0, 0);
vbo_shadowdata[7].Set((float)width, (float)height, 0, 0, 0);
// and this is for the postprocessing copy operation
vbo_shadowdata[8].Set(-1.0f, -1.0f, 0, 0.0f, 0.0f);
vbo_shadowdata[9].Set(-1.0f, 1.0f, 0, 0.0f, 1.f);
vbo_shadowdata[10].Set(1.0f, -1.0f, 0, 1.f, 0.0f);
vbo_shadowdata[11].Set(1.0f, 1.0f, 0, 1.f, 1.f);
}
FFlatVertexBuffer::~FFlatVertexBuffer()

View file

@ -108,16 +108,11 @@ EXTERN_CVAR(Float, vid_brightness)
EXTERN_CVAR(Float, vid_contrast)
void FGLRenderer::RenderScreenQuad(float maxU, float maxV)
void FGLRenderer::RenderScreenQuad()
{
FFlatVertex *ptr = mVBO->GetBuffer();
mVBO->BindVBO();
gl_RenderState.ResetVertexBuffer();
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
ptr->Set(-1.0f, 1.0f, 0, 0.0f, maxV); ptr++;
ptr->Set(1.0f, -1.0f, 0, maxU, 0.0f); ptr++;
ptr->Set(1.0f, 1.0f, 0, maxU, maxV); ptr++;
mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
}
//-----------------------------------------------------------------------------
@ -357,9 +352,10 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
mPresentShader->Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
}
mPresentShader->Scale.Set(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
mBuffers->BindCurrentTexture(0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
RenderScreenQuad(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
RenderScreenQuad();
}
}

View file

@ -153,7 +153,7 @@ public:
unsigned char *GetTextureBuffer(FTexture *tex, int &w, int &h);
void SetupLevel();
void RenderScreenQuad(float maxU = 1.0f, float maxV = 1.0f);
void RenderScreenQuad();
void SetFixedColormap (player_t *player);
void WriteSavePic (player_t *player, FILE *file, int width, int height);
void EndDrawScene(sector_t * viewsector);

View file

@ -53,7 +53,7 @@ void FPresentShader::Bind()
{
if (!mShader)
{
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/present.fp", "", 330);
mShader.SetFragDataLocation(0, "FragColor");
mShader.Link("shaders/glsl/present");
@ -63,6 +63,7 @@ void FPresentShader::Bind()
Gamma.Init(mShader, "Gamma");
Contrast.Init(mShader, "Contrast");
Brightness.Init(mShader, "Brightness");
Scale.Init(mShader, "UVScale");
}
mShader.Bind();
}

View file

@ -12,6 +12,7 @@ public:
FBufferedUniform1f Gamma;
FBufferedUniform1f Contrast;
FBufferedUniform1f Brightness;
FBufferedUniform2f Scale;
private:
FShaderProgram mShader;

View file

@ -123,6 +123,17 @@ public:
glUniform2fv(mIndex, 1, newvalue);
}
}
void Set(float f1, float f2)
{
if (mBuffer[0] != f1 || mBuffer[1] != f2)
{
mBuffer[0] = f1;
mBuffer[1] = f2;
glUniform2fv(mIndex, 1, mBuffer);
}
}
};
class FBufferedUniform4f

View file

@ -0,0 +1,11 @@
in vec4 PositionInProjection;
in vec2 UV;
uniform vec2 UVScale;
out vec2 TexCoord;
void main()
{
gl_Position = PositionInProjection;
TexCoord = UV * UVScale;
}