mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-18 22:51:39 +00:00
- 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:
parent
8daaf61160
commit
675822004d
7 changed files with 37 additions and 11 deletions
|
@ -126,7 +126,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
||||||
map = new FFlatVertex[BUFFER_SIZE];
|
map = new FFlatVertex[BUFFER_SIZE];
|
||||||
}
|
}
|
||||||
mIndex = mCurIndex = 0;
|
mIndex = mCurIndex = 0;
|
||||||
mNumReserved = 8;
|
mNumReserved = 12;
|
||||||
vbo_shadowdata.Resize(mNumReserved);
|
vbo_shadowdata.Resize(mNumReserved);
|
||||||
|
|
||||||
// the first quad is reserved for handling coordinates through uniforms.
|
// 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[6].Set((float)width, 0, 0, 0, 0);
|
||||||
vbo_shadowdata[7].Set((float)width, (float)height, 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()
|
FFlatVertexBuffer::~FFlatVertexBuffer()
|
||||||
|
|
|
@ -108,16 +108,11 @@ EXTERN_CVAR(Float, vid_brightness)
|
||||||
EXTERN_CVAR(Float, vid_contrast)
|
EXTERN_CVAR(Float, vid_contrast)
|
||||||
|
|
||||||
|
|
||||||
void FGLRenderer::RenderScreenQuad(float maxU, float maxV)
|
void FGLRenderer::RenderScreenQuad()
|
||||||
{
|
{
|
||||||
FFlatVertex *ptr = mVBO->GetBuffer();
|
|
||||||
mVBO->BindVBO();
|
mVBO->BindVBO();
|
||||||
gl_RenderState.ResetVertexBuffer();
|
gl_RenderState.ResetVertexBuffer();
|
||||||
ptr->Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); ptr++;
|
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -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->Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
|
||||||
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
|
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);
|
mBuffers->BindCurrentTexture(0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ public:
|
||||||
unsigned char *GetTextureBuffer(FTexture *tex, int &w, int &h);
|
unsigned char *GetTextureBuffer(FTexture *tex, int &w, int &h);
|
||||||
void SetupLevel();
|
void SetupLevel();
|
||||||
|
|
||||||
void RenderScreenQuad(float maxU = 1.0f, float maxV = 1.0f);
|
void RenderScreenQuad();
|
||||||
void SetFixedColormap (player_t *player);
|
void SetFixedColormap (player_t *player);
|
||||||
void WriteSavePic (player_t *player, FILE *file, int width, int height);
|
void WriteSavePic (player_t *player, FILE *file, int width, int height);
|
||||||
void EndDrawScene(sector_t * viewsector);
|
void EndDrawScene(sector_t * viewsector);
|
||||||
|
|
|
@ -53,7 +53,7 @@ void FPresentShader::Bind()
|
||||||
{
|
{
|
||||||
if (!mShader)
|
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.Compile(FShaderProgram::Fragment, "shaders/glsl/present.fp", "", 330);
|
||||||
mShader.SetFragDataLocation(0, "FragColor");
|
mShader.SetFragDataLocation(0, "FragColor");
|
||||||
mShader.Link("shaders/glsl/present");
|
mShader.Link("shaders/glsl/present");
|
||||||
|
@ -63,6 +63,7 @@ void FPresentShader::Bind()
|
||||||
Gamma.Init(mShader, "Gamma");
|
Gamma.Init(mShader, "Gamma");
|
||||||
Contrast.Init(mShader, "Contrast");
|
Contrast.Init(mShader, "Contrast");
|
||||||
Brightness.Init(mShader, "Brightness");
|
Brightness.Init(mShader, "Brightness");
|
||||||
|
Scale.Init(mShader, "UVScale");
|
||||||
}
|
}
|
||||||
mShader.Bind();
|
mShader.Bind();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ public:
|
||||||
FBufferedUniform1f Gamma;
|
FBufferedUniform1f Gamma;
|
||||||
FBufferedUniform1f Contrast;
|
FBufferedUniform1f Contrast;
|
||||||
FBufferedUniform1f Brightness;
|
FBufferedUniform1f Brightness;
|
||||||
|
FBufferedUniform2f Scale;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FShaderProgram mShader;
|
FShaderProgram mShader;
|
||||||
|
|
|
@ -123,6 +123,17 @@ public:
|
||||||
glUniform2fv(mIndex, 1, newvalue);
|
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
|
class FBufferedUniform4f
|
||||||
|
|
11
wadsrc/static/shaders/glsl/screenquadscale.vp
Normal file
11
wadsrc/static/shaders/glsl/screenquadscale.vp
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue