Skip to content

Commit

Permalink
fix an assert() when using custom render targets
Browse files Browse the repository at this point in the history
we now always mask out target bits that don't exist in the render
target before converting them to GLenums.

Fixes #2285
  • Loading branch information
pixelflinger committed Mar 27, 2020
1 parent ffa62d4 commit 965777d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ void OpenGLDriver::createRenderTargetR(Handle<HwRenderTarget> rth,
*/

rt->gl.samples = samples;
rt->targets = targets;

if (any(targets & TargetBufferFlags::COLOR_ALL)) {
GLenum bufs[4] = { GL_NONE };
Expand Down Expand Up @@ -1861,10 +1862,12 @@ void OpenGLDriver::beginRenderPass(Handle<HwRenderTarget> rth,

mRenderPassTarget = rth;
mRenderPassParams = params;
const TargetBufferFlags clearFlags = params.flags.clear;
TargetBufferFlags discardFlags = params.flags.discardStart;

GLRenderTarget* rt = handle_cast<GLRenderTarget*>(rth);

const TargetBufferFlags clearFlags = params.flags.clear & rt->targets;
TargetBufferFlags discardFlags = params.flags.discardStart & rt->targets;

gl.bindFramebuffer(GL_FRAMEBUFFER, rt->gl.fbo);

// glInvalidateFramebuffer appeared on GLES 3.0 and GL4.3, for simplicity we just
Expand Down Expand Up @@ -1923,7 +1926,7 @@ void OpenGLDriver::endRenderPass(int) {

GLRenderTarget const* const rt = handle_cast<GLRenderTarget*>(mRenderPassTarget);

const TargetBufferFlags discardFlags = mRenderPassParams.flags.discardEnd;
const TargetBufferFlags discardFlags = mRenderPassParams.flags.discardEnd & rt->targets;
if (rt->gl.fbo_read) {
resolvePass(ResolveAction::STORE, rt, discardFlags);
}
Expand Down Expand Up @@ -1977,7 +1980,9 @@ void OpenGLDriver::resolvePass(ResolveAction action, GLRenderTarget const* rt,
}

GLsizei OpenGLDriver::getAttachments(std::array<GLenum, 6>& attachments,
GLRenderTarget const* rt, TargetBufferFlags buffers) const noexcept {
GLRenderTarget const* rt, TargetBufferFlags buffers) noexcept {
assert(buffers <= rt->targets);

GLsizei attachmentCount = 0;
// the default framebuffer uses different constants!!!
const bool defaultFramebuffer = (rt->gl.fbo == 0);
Expand Down
5 changes: 3 additions & 2 deletions filament/backend/src/opengl/OpenGLDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class OpenGLDriver final : public backend::DriverBase {
mutable backend::TargetBufferFlags resolve = backend::TargetBufferFlags::NONE; // attachments in fbo_draw to resolve
uint8_t samples : 4;
} gl;
backend::TargetBufferFlags targets;
};

OpenGLDriver(OpenGLDriver const&) = delete;
Expand Down Expand Up @@ -337,8 +338,8 @@ class OpenGLDriver final : public backend::DriverBase {
return mSamplerBindings;
}

GLsizei getAttachments(std::array<GLenum, 6>& attachments,
GLRenderTarget const* rt, backend::TargetBufferFlags buffers) const noexcept;
static GLsizei getAttachments(std::array<GLenum, 6>& attachments,
GLRenderTarget const* rt, backend::TargetBufferFlags buffers) noexcept;

backend::RasterState mRasterState;

Expand Down

0 comments on commit 965777d

Please sign in to comment.