gl_state: Remove blend state tracking
This commit is contained in:
parent
7d9a5e9e30
commit
1bc0da3dea
|
@ -442,7 +442,9 @@ void RasterizerOpenGL::Clear() {
|
|||
}
|
||||
|
||||
// TODO: Signal state tracker about these changes
|
||||
// TODO(Rodrigo): Find out if these changes affect clearing
|
||||
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
|
||||
glDisablei(GL_BLEND, 0);
|
||||
|
||||
UNIMPLEMENTED_IF(regs.clear_flags.viewport);
|
||||
|
||||
|
@ -1049,37 +1051,34 @@ void RasterizerOpenGL::SyncBlendState() {
|
|||
|
||||
glBlendColor(regs.blend_color.r, regs.blend_color.g, regs.blend_color.b, regs.blend_color.a);
|
||||
|
||||
state.independant_blend.enabled = regs.independent_blend_enable;
|
||||
if (!state.independant_blend.enabled) {
|
||||
auto& blend = state.blend[0];
|
||||
if (!regs.independent_blend_enable) {
|
||||
const auto& src = regs.blend;
|
||||
blend.enabled = src.enable[0] != 0;
|
||||
if (blend.enabled) {
|
||||
blend.rgb_equation = MaxwellToGL::BlendEquation(src.equation_rgb);
|
||||
blend.src_rgb_func = MaxwellToGL::BlendFunc(src.factor_source_rgb);
|
||||
blend.dst_rgb_func = MaxwellToGL::BlendFunc(src.factor_dest_rgb);
|
||||
blend.a_equation = MaxwellToGL::BlendEquation(src.equation_a);
|
||||
blend.src_a_func = MaxwellToGL::BlendFunc(src.factor_source_a);
|
||||
blend.dst_a_func = MaxwellToGL::BlendFunc(src.factor_dest_a);
|
||||
}
|
||||
for (std::size_t i = 1; i < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets; i++) {
|
||||
state.blend[i].enabled = false;
|
||||
oglEnable(GL_BLEND, src.enable[0]);
|
||||
if (!src.enable[0]) {
|
||||
return;
|
||||
}
|
||||
glBlendFuncSeparate(MaxwellToGL::BlendFunc(src.factor_source_rgb),
|
||||
MaxwellToGL::BlendFunc(src.factor_dest_rgb),
|
||||
MaxwellToGL::BlendFunc(src.factor_source_a),
|
||||
MaxwellToGL::BlendFunc(src.factor_dest_a));
|
||||
glBlendEquationSeparate(MaxwellToGL::BlendEquation(src.equation_rgb),
|
||||
MaxwellToGL::BlendEquation(src.equation_a));
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets; i++) {
|
||||
auto& blend = state.blend[i];
|
||||
const auto& src = regs.independent_blend[i];
|
||||
blend.enabled = regs.blend.enable[i] != 0;
|
||||
if (!blend.enabled)
|
||||
for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) {
|
||||
oglEnablei(GL_BLEND, regs.blend.enable[i], static_cast<GLuint>(i));
|
||||
if (!regs.blend.enable[i]) {
|
||||
continue;
|
||||
blend.rgb_equation = MaxwellToGL::BlendEquation(src.equation_rgb);
|
||||
blend.src_rgb_func = MaxwellToGL::BlendFunc(src.factor_source_rgb);
|
||||
blend.dst_rgb_func = MaxwellToGL::BlendFunc(src.factor_dest_rgb);
|
||||
blend.a_equation = MaxwellToGL::BlendEquation(src.equation_a);
|
||||
blend.src_a_func = MaxwellToGL::BlendFunc(src.factor_source_a);
|
||||
blend.dst_a_func = MaxwellToGL::BlendFunc(src.factor_dest_a);
|
||||
}
|
||||
const auto& src = regs.independent_blend[i];
|
||||
glBlendFuncSeparatei(static_cast<GLuint>(i), MaxwellToGL::BlendFunc(src.factor_source_rgb),
|
||||
MaxwellToGL::BlendFunc(src.factor_dest_rgb),
|
||||
MaxwellToGL::BlendFunc(src.factor_source_a),
|
||||
MaxwellToGL::BlendFunc(src.factor_dest_a));
|
||||
glBlendEquationSeparatei(static_cast<GLuint>(i),
|
||||
MaxwellToGL::BlendEquation(src.equation_rgb),
|
||||
MaxwellToGL::BlendEquation(src.equation_a));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,66 +106,6 @@ void OpenGLState::ApplyProgramPipeline() {
|
|||
}
|
||||
}
|
||||
|
||||
void OpenGLState::ApplyGlobalBlending() {
|
||||
const Blend& updated = blend[0];
|
||||
Blend& current = cur_state.blend[0];
|
||||
|
||||
Enable(GL_BLEND, current.enabled, updated.enabled);
|
||||
|
||||
if (current.src_rgb_func != updated.src_rgb_func ||
|
||||
current.dst_rgb_func != updated.dst_rgb_func || current.src_a_func != updated.src_a_func ||
|
||||
current.dst_a_func != updated.dst_a_func) {
|
||||
current.src_rgb_func = updated.src_rgb_func;
|
||||
current.dst_rgb_func = updated.dst_rgb_func;
|
||||
current.src_a_func = updated.src_a_func;
|
||||
current.dst_a_func = updated.dst_a_func;
|
||||
glBlendFuncSeparate(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func,
|
||||
updated.dst_a_func);
|
||||
}
|
||||
|
||||
if (current.rgb_equation != updated.rgb_equation || current.a_equation != updated.a_equation) {
|
||||
current.rgb_equation = updated.rgb_equation;
|
||||
current.a_equation = updated.a_equation;
|
||||
glBlendEquationSeparate(updated.rgb_equation, updated.a_equation);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) {
|
||||
const Blend& updated = blend[target];
|
||||
Blend& current = cur_state.blend[target];
|
||||
|
||||
if (current.enabled != updated.enabled || force) {
|
||||
current.enabled = updated.enabled;
|
||||
Enable(GL_BLEND, static_cast<GLuint>(target), updated.enabled);
|
||||
}
|
||||
|
||||
if (UpdateTie(std::tie(current.src_rgb_func, current.dst_rgb_func, current.src_a_func,
|
||||
current.dst_a_func),
|
||||
std::tie(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func,
|
||||
updated.dst_a_func))) {
|
||||
glBlendFuncSeparatei(static_cast<GLuint>(target), updated.src_rgb_func,
|
||||
updated.dst_rgb_func, updated.src_a_func, updated.dst_a_func);
|
||||
}
|
||||
|
||||
if (UpdateTie(std::tie(current.rgb_equation, current.a_equation),
|
||||
std::tie(updated.rgb_equation, updated.a_equation))) {
|
||||
glBlendEquationSeparatei(static_cast<GLuint>(target), updated.rgb_equation,
|
||||
updated.a_equation);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLState::ApplyBlending() {
|
||||
if (independant_blend.enabled) {
|
||||
const bool force = independant_blend.enabled != cur_state.independant_blend.enabled;
|
||||
for (std::size_t target = 0; target < Maxwell::NumRenderTargets; ++target) {
|
||||
ApplyTargetBlending(target, force);
|
||||
}
|
||||
} else {
|
||||
ApplyGlobalBlending();
|
||||
}
|
||||
cur_state.independant_blend.enabled = independant_blend.enabled;
|
||||
}
|
||||
|
||||
void OpenGLState::ApplyRenderBuffer() {
|
||||
if (cur_state.renderbuffer != renderbuffer) {
|
||||
cur_state.renderbuffer = renderbuffer;
|
||||
|
@ -206,7 +146,6 @@ void OpenGLState::Apply() {
|
|||
ApplyFramebufferState();
|
||||
ApplyShaderProgram();
|
||||
ApplyProgramPipeline();
|
||||
ApplyBlending();
|
||||
ApplyTextures();
|
||||
ApplySamplers();
|
||||
ApplyImages();
|
||||
|
|
|
@ -13,21 +13,6 @@ namespace OpenGL {
|
|||
|
||||
class OpenGLState {
|
||||
public:
|
||||
struct Blend {
|
||||
bool enabled = false; // GL_BLEND
|
||||
GLenum rgb_equation = GL_FUNC_ADD; // GL_BLEND_EQUATION_RGB
|
||||
GLenum a_equation = GL_FUNC_ADD; // GL_BLEND_EQUATION_ALPHA
|
||||
GLenum src_rgb_func = GL_ONE; // GL_BLEND_SRC_RGB
|
||||
GLenum dst_rgb_func = GL_ZERO; // GL_BLEND_DST_RGB
|
||||
GLenum src_a_func = GL_ONE; // GL_BLEND_SRC_ALPHA
|
||||
GLenum dst_a_func = GL_ZERO; // GL_BLEND_DST_ALPHA
|
||||
};
|
||||
std::array<Blend, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> blend;
|
||||
|
||||
struct {
|
||||
bool enabled = false;
|
||||
} independant_blend;
|
||||
|
||||
static constexpr std::size_t NumSamplers = 32 * 5;
|
||||
static constexpr std::size_t NumImages = 8 * 5;
|
||||
std::array<GLuint, NumSamplers> textures = {};
|
||||
|
@ -56,9 +41,6 @@ public:
|
|||
void ApplyFramebufferState();
|
||||
void ApplyShaderProgram();
|
||||
void ApplyProgramPipeline();
|
||||
void ApplyTargetBlending(std::size_t target, bool force);
|
||||
void ApplyGlobalBlending();
|
||||
void ApplyBlending();
|
||||
void ApplyTextures();
|
||||
void ApplySamplers();
|
||||
void ApplyImages();
|
||||
|
|
|
@ -537,8 +537,11 @@ void TextureCacheOpenGL::ImageBlit(View& src_view, View& dst_view,
|
|||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
// TODO(Rodrigo): Find out if rasterizer discard affects blits
|
||||
// TODO(Rodrigo): Find out if blending affects blits
|
||||
// TODO(Rodrigo): Find out if clip control affects blits
|
||||
glDisable(GL_RASTERIZER_DISCARD);
|
||||
glDisablei(GL_SCISSOR_TEST, 0);
|
||||
glDisablei(GL_BLEND, 0);
|
||||
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
|
||||
|
||||
u32 buffers{};
|
||||
|
|
|
@ -582,6 +582,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
|
|||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glDisable(GL_RASTERIZER_DISCARD);
|
||||
glDisablei(GL_BLEND, 0);
|
||||
glDisablei(GL_SCISSOR_TEST, 0);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CW);
|
||||
|
|
Reference in New Issue