Fixing color/depth clear state.

This commit is contained in:
Ben Vanik 2015-03-22 00:45:00 -07:00
parent c8ddc48106
commit b75e070d1b
2 changed files with 25 additions and 10 deletions

View File

@ -254,9 +254,10 @@ void Blitter::BlitTexture2D(GLuint src_texture, Rect2D src_rect,
SavedState state; SavedState state;
state.Save(); state.Save();
glColorMaski(0, true, true, true, true); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDepthMask(false); glDepthMask(GL_FALSE);
glStencilMask(0xFF);
glBindProgramPipeline(color_pipeline_); glBindProgramPipeline(color_pipeline_);
Draw(src_texture, src_rect, dest_rect, filter); Draw(src_texture, src_rect, dest_rect, filter);
@ -270,9 +271,9 @@ void Blitter::CopyColorTexture2D(GLuint src_texture, Rect2D src_rect,
SavedState state; SavedState state;
state.Save(); state.Save();
glColorMaski(0, true, true, true, true); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDepthMask(false); glDepthMask(GL_FALSE);
glBindProgramPipeline(color_pipeline_); glBindProgramPipeline(color_pipeline_);
glNamedFramebufferTexture(scratch_framebuffer_, GL_COLOR_ATTACHMENT0, glNamedFramebufferTexture(scratch_framebuffer_, GL_COLOR_ATTACHMENT0,
@ -292,10 +293,10 @@ void Blitter::CopyDepthTexture(GLuint src_texture, Rect2D src_rect,
SavedState state; SavedState state;
state.Save(); state.Save();
glColorMaski(0, false, false, false, false); glColorMaski(0, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS); glDepthFunc(GL_ALWAYS);
glDepthMask(true); glDepthMask(GL_TRUE);
glBindProgramPipeline(depth_pipeline_); glBindProgramPipeline(depth_pipeline_);
glNamedFramebufferTexture(scratch_framebuffer_, GL_DEPTH_STENCIL_ATTACHMENT, glNamedFramebufferTexture(scratch_framebuffer_, GL_DEPTH_STENCIL_ATTACHMENT,

View File

@ -2785,8 +2785,14 @@ bool CommandProcessor::IssueCopy() {
((copy_color_clear >> 8) & 0xFF) / 255.0f, ((copy_color_clear >> 8) & 0xFF) / 255.0f,
((copy_color_clear >> 16) & 0xFF) / 255.0f, ((copy_color_clear >> 16) & 0xFF) / 255.0f,
((copy_color_clear >> 24) & 0xFF) / 255.0f}; ((copy_color_clear >> 24) & 0xFF) / 255.0f};
// TODO(benvanik): remove query.
GLboolean old_color_mask[4];
glGetBooleani_v(GL_COLOR_WRITEMASK, copy_src_select, old_color_mask);
glColorMaski(copy_src_select, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearNamedFramebufferfv(source_framebuffer->framebuffer, GL_COLOR, glClearNamedFramebufferfv(source_framebuffer->framebuffer, GL_COLOR,
copy_src_select, color); copy_src_select, color);
glColorMaski(copy_src_select, old_color_mask[0], old_color_mask[1],
old_color_mask[2], old_color_mask[3]);
} }
if (depth_clear_enabled) { if (depth_clear_enabled) {
@ -2794,15 +2800,23 @@ bool CommandProcessor::IssueCopy() {
// TODO(benvanik): verify format. // TODO(benvanik): verify format.
GLfloat depth = {(copy_depth_clear & 0xFFFFFF00) / float(0xFFFFFF00)}; GLfloat depth = {(copy_depth_clear & 0xFFFFFF00) / float(0xFFFFFF00)};
GLint stencil = copy_depth_clear & 0xFF; GLint stencil = copy_depth_clear & 0xFF;
// HACK: this should work, but throws INVALID_ENUM on nvidia drivers.
// glClearNamedFramebufferfi(source_framebuffer->framebuffer,
// GL_DEPTH_STENCIL,
// depth, stencil);
GLint old_draw_framebuffer; GLint old_draw_framebuffer;
GLboolean old_depth_mask;
GLint old_stencil_mask;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_framebuffer); glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_framebuffer);
glGetBooleanv(GL_DEPTH_WRITEMASK, &old_depth_mask);
glGetIntegerv(GL_STENCIL_WRITEMASK, &old_stencil_mask);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, source_framebuffer->framebuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, source_framebuffer->framebuffer);
glDepthMask(GL_TRUE);
glStencilMask(0xFF);
// HACK: this should work, but throws INVALID_ENUM on nvidia drivers.
/* glClearNamedFramebufferfi(source_framebuffer->framebuffer,
GL_DEPTH_STENCIL,
depth, stencil);*/
glClearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil); glClearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_framebuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_framebuffer);
glDepthMask(old_depth_mask);
glStencilMask(old_stencil_mask);
} }
return true; return true;