diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index 4cb0efd6a..8e27c34fe 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -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() diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 79bd31860..dd4cc71aa 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -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(vid_contrast, 0.1f, 3.f)); mPresentShader->Brightness.Set(clamp(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(); } } diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 0fe91dae2..1a8883b3f 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -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); diff --git a/src/gl/shaders/gl_presentshader.cpp b/src/gl/shaders/gl_presentshader.cpp index 9998fda36..e40aa7a2c 100644 --- a/src/gl/shaders/gl_presentshader.cpp +++ b/src/gl/shaders/gl_presentshader.cpp @@ -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(); } diff --git a/src/gl/shaders/gl_presentshader.h b/src/gl/shaders/gl_presentshader.h index 6bec79625..513af41cc 100644 --- a/src/gl/shaders/gl_presentshader.h +++ b/src/gl/shaders/gl_presentshader.h @@ -12,6 +12,7 @@ public: FBufferedUniform1f Gamma; FBufferedUniform1f Contrast; FBufferedUniform1f Brightness; + FBufferedUniform2f Scale; private: FShaderProgram mShader; diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index ca534c31d..a0b01d20d 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -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 diff --git a/wadsrc/static/shaders/glsl/screenquadscale.vp b/wadsrc/static/shaders/glsl/screenquadscale.vp new file mode 100644 index 000000000..2d7f505b4 --- /dev/null +++ b/wadsrc/static/shaders/glsl/screenquadscale.vp @@ -0,0 +1,11 @@ + +in vec4 PositionInProjection; +in vec2 UV; +uniform vec2 UVScale; +out vec2 TexCoord; + +void main() +{ + gl_Position = PositionInProjection; + TexCoord = UV * UVScale; +}