yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

GLState: Support changing the GL_TEXTURE_SWIZZLE parameter of each texture unit.

This commit is contained in:
Subv 2018-06-06 18:26:41 -05:00
parent 0ff2929644
commit 89e81a9be2
3 changed files with 20 additions and 0 deletions

View File

@ -50,6 +50,10 @@ OpenGLState::OpenGLState() {
for (auto& texture_unit : texture_units) { for (auto& texture_unit : texture_units) {
texture_unit.texture_2d = 0; texture_unit.texture_2d = 0;
texture_unit.sampler = 0; texture_unit.sampler = 0;
texture_unit.swizzle.r = GL_RED;
texture_unit.swizzle.g = GL_GREEN;
texture_unit.swizzle.b = GL_BLUE;
texture_unit.swizzle.a = GL_ALPHA;
} }
lighting_lut.texture_buffer = 0; lighting_lut.texture_buffer = 0;
@ -200,6 +204,15 @@ void OpenGLState::Apply() const {
if (texture_units[i].sampler != cur_state.texture_units[i].sampler) { if (texture_units[i].sampler != cur_state.texture_units[i].sampler) {
glBindSampler(i, texture_units[i].sampler); glBindSampler(i, texture_units[i].sampler);
} }
// Update the texture swizzle
if (texture_units[i].swizzle.r != cur_state.texture_units[i].swizzle.r ||
texture_units[i].swizzle.g != cur_state.texture_units[i].swizzle.g ||
texture_units[i].swizzle.b != cur_state.texture_units[i].swizzle.b ||
texture_units[i].swizzle.a != cur_state.texture_units[i].swizzle.a) {
std::array<GLint, 4> mask = {texture_units[i].swizzle.r, texture_units[i].swizzle.g,
texture_units[i].swizzle.b, texture_units[i].swizzle.a};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask.data());
}
} }
// Constbuffers // Constbuffers

View File

@ -85,6 +85,12 @@ public:
struct { struct {
GLuint texture_2d; // GL_TEXTURE_BINDING_2D GLuint texture_2d; // GL_TEXTURE_BINDING_2D
GLuint sampler; // GL_SAMPLER_BINDING GLuint sampler; // GL_SAMPLER_BINDING
struct {
GLint r; // GL_TEXTURE_SWIZZLE_R
GLint g; // GL_TEXTURE_SWIZZLE_G
GLint b; // GL_TEXTURE_SWIZZLE_B
GLint a; // GL_TEXTURE_SWIZZLE_A
} swizzle;
} texture_units[32]; } texture_units[32];
struct { struct {

View File

@ -316,6 +316,7 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
}}; }};
state.texture_units[0].texture_2d = screen_info.display_texture; state.texture_units[0].texture_2d = screen_info.display_texture;
state.texture_units[0].swizzle = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
state.Apply(); state.Apply();
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices.data()); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices.data());