Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/common/rendering/gl_load/gl_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ void gl_LoadExtensions()
#ifdef __MOBILE__
gl_version = 3.31;
gl.flags |= RFL_NO_CLIP_PLANES;
gl.flags |= RFL_INVALIDATE_BUFFER;
gl.flags |= RFL_SHADER_STORAGE_BUFFER;
#endif
// Don't even start if it's lower than 2.0 or no framebuffers are available (The framebuffer extension is needed for glGenerateMipmapsEXT!)
Expand All @@ -157,6 +156,8 @@ void gl_LoadExtensions()
gl.vendorstring = (char*)glGetString(GL_VENDOR);
gl.modelstring = (char*)glGetString(GL_RENDERER);

bool isGLES = strstr(glversion, "OpenGL ES") != NULL;

// 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;
Expand Down Expand Up @@ -194,8 +195,10 @@ void gl_LoadExtensions()
if (gl_no_clip_planes)
gl.flags |= RFL_NO_CLIP_PLANES;

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 (((isGLES && gl_version >= 3.0f) || (!isGLES && gl_version >= 4.3f)) || CheckExtension("GL_ARB_invalidate_subdata"))
gl.flags |= RFL_INVALIDATE_BUFFER;
if (((isGLES && gl_version >= 3.2f) || (!isGLES && gl_version >= 4.3f)) || CheckExtension("GL_KHR_debug"))
gl.flags |= RFL_DEBUG;

glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v);
gl.maxuniforms = v;
Expand Down
35 changes: 27 additions & 8 deletions src/common/rendering/gles/gles_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ GLBuffer::GLBuffer(int usetype)
{
glGenBuffers(1, &mBufferId);
isData = false;
hasGLBuffer = true;
}
else if ((usetype == GL_UNIFORM_BUFFER) || (usetype == GL_SHADER_STORAGE_BUFFER))
{
// GLDataBuffer stays a CPU-side buffer for viewpoint/lights/bones,
// which read it back via a raw pointer into `memory` and never touch
// the GPU object (gles_renderstate.cpp's ApplyShader()/ApplyViewport()),
// so isData stays true and that CPU shadow copy is kept exactly as
// before. But real postprocess/custom shaders declare a genuine
// `layout(std140) uniform Uniforms{}` block and can only read it via
// an actually-uploaded, actually-bound GL buffer, so also create and
// track a real one here - mirroring gl_buffers.cpp, whose GLBuffer
// always has a real buffer object regardless of type.
glGenBuffers(1, &mBufferId);
hasGLBuffer = true;
isData = true;
}
else
{
Expand All @@ -71,7 +87,11 @@ GLBuffer::~GLBuffer()
{
if (mBufferId != 0)
{
if (gles.useMappedBuffers)
// Only real vertex/index buffers are ever glMapBufferRange'd (Map()/
// Lock() below are still gated on !isData); data buffers (isData ==
// true, including the uniform/storage ones above) are only ever
// written via SetData()/glBufferData, so must not be glUnmapBuffer'd.
if (!isData && gles.useMappedBuffers)
{
glBindBuffer(mUseType, mBufferId);
glUnmapBuffer(mUseType);
Expand All @@ -86,13 +106,12 @@ GLBuffer::~GLBuffer()

void GLBuffer::Bind()
{
if (!isData)
if (hasGLBuffer)
{
glBindBuffer(mUseType, mBufferId);
}
}


void GLBuffer::SetData(size_t size, const void* data, BufferUsageType usage)
{
bool staticdata = (usage == BufferUsageType::Static || usage == BufferUsageType::Mappable);
Expand All @@ -107,7 +126,7 @@ void GLBuffer::SetData(size_t size, const void* data, BufferUsageType usage)
memcpy(memory, data, size);
}

if (!isData)
if (hasGLBuffer)
{
Bind();
glBufferData(mUseType, size, data, staticdata ? GL_STATIC_DRAW : GL_STREAM_DRAW);
Expand All @@ -132,7 +151,7 @@ void GLBuffer::SetSubData(size_t offset, size_t size, const void *data)

memcpy(memory + offset, data, size);

if (!isData)
if (hasGLBuffer)
{
glBufferSubData(mUseType, offset, size, data);
}
Expand Down Expand Up @@ -314,7 +333,7 @@ void GLVertexBuffer::Bind(int *offsets)
glVertexAttribPointer(i, attrinf.size, attrinf.format, attrinf.normalize, (GLsizei)mStride, (void*)(intptr_t)ofs);
else
{
if (gles.glesMode >= GLES_MODE_OGL3)
if (strcmp(gles.shaderVersionString, "100") != 0)
glVertexAttribIPointer(i, attrinf.size, attrinf.format, (GLsizei)mStride, (void*)(intptr_t)ofs);
}
}
Expand All @@ -332,12 +351,12 @@ void GLDataBuffer::BindRange(FRenderState *state, size_t start, size_t length)

void GLDataBuffer::BindBase()
{

glBindBufferBase(mUseType, mBindingPoint, mBufferId);
}


GLVertexBuffer::GLVertexBuffer() : GLBuffer(GL_ARRAY_BUFFER) {}
GLIndexBuffer::GLIndexBuffer() : GLBuffer(GL_ELEMENT_ARRAY_BUFFER) {}
GLDataBuffer::GLDataBuffer(int bindingpoint, bool is_ssbo) : GLBuffer(0), mBindingPoint(bindingpoint) {}
GLDataBuffer::GLDataBuffer(int bindingpoint, bool is_ssbo) : GLBuffer(is_ssbo ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER), mBindingPoint(bindingpoint) {}

}
1 change: 1 addition & 0 deletions src/common/rendering/gles/gles_buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GLBuffer : virtual public IBuffer
GLsync mGLSync = 0;

bool isData = false;
bool hasGLBuffer = false; // true once a real glGenBuffers() object backs mBufferId
char *memory = nullptr;

GLBuffer(int usetype);
Expand Down
14 changes: 13 additions & 1 deletion src/common/rendering/gles/gles_framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bo
return new GLDataBuffer(bindingpoint, ssbo);
}

void OpenGLFrameBuffer::BlurScene(float amount)
{
if (GLRenderer != nullptr)
GLRenderer->BlurScene(amount);
}

void OpenGLFrameBuffer::UpdatePalette()
{
if (GLRenderer != nullptr)
GLRenderer->ClearTonemapPalette();
}


void OpenGLFrameBuffer::SetViewportRects(IntRect *bounds)
{
Expand Down Expand Up @@ -516,7 +528,7 @@ void OpenGLFrameBuffer::Draw2D(bool outside2D)

void OpenGLFrameBuffer::PostProcessScene(bool swscene, int fixedcm, float flash, const std::function<void()> &afterBloomDrawEndScene2D)
{
//if (!swscene) GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture
if (!swscene) GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture
GLRenderer->PostProcessScene(fixedcm, flash, afterBloomDrawEndScene2D);
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/rendering/gles/gles_framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class OpenGLFrameBuffer : public SystemGLFrameBuffer

void Draw2D(bool outside2D = false) override;
void PostProcessScene(bool swscene, int fixedcm, float flash, const std::function<void()> &afterBloomDrawEndScene2D) override;
void BlurScene(float amount) override;
void UpdatePalette() override;

bool HWGammaActive = false; // Are we using hardware or software gamma?
std::unique_ptr<OpenGLESRenderer::FGLDebug> mDebug; // Debug API
Expand Down
39 changes: 39 additions & 0 deletions src/common/rendering/gles/gles_postprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,49 @@ void FGLRenderer::RenderScreenQuad()

void FGLRenderer::PostProcessScene(int fixedcm, float flash, const std::function<void()> &afterBloomDrawEndScene2D)
{
int sceneWidth = mBuffers->GetSceneWidth();
int sceneHeight = mBuffers->GetSceneHeight();

GLPPRenderState renderstate(mBuffers);

if (strcmp(gles.shaderVersionString, "100") != 0)
{
hw_postprocess.Pass1(&renderstate, fixedcm, sceneWidth, sceneHeight);
}
#ifndef NO_RENDER_BUFFER
mBuffers->BindCurrentFB();
#endif
if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D();
if (strcmp(gles.shaderVersionString, "100") != 0)
{
hw_postprocess.Pass2(&renderstate, fixedcm, flash, sceneWidth, sceneHeight);
}
}

void FGLRenderer::BlurScene(float gameinfobluramount)
{
int sceneWidth = mBuffers->GetSceneWidth();
int sceneHeight = mBuffers->GetSceneHeight();

if (strcmp(gles.shaderVersionString, "100") == 0)
{
return;
}

GLPPRenderState renderstate(mBuffers);

auto vrmode = VRMode::GetVRMode(true);
int eyeCount = vrmode->mEyeCount;
for (int i = 0; i < eyeCount; ++i)
{
hw_postprocess.bloom.RenderBlur(&renderstate, sceneWidth, sceneHeight, gameinfobluramount);
mBuffers->NextEye(eyeCount);
}
}

void FGLRenderer::ClearTonemapPalette()
{
hw_postprocess.tonemap.ClearTonemapPalette();
}


Expand Down
Loading
Loading