diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index 9754e2a185..fc0e04ff12 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -423,11 +423,11 @@ void FramebufferManagerGLES::DrawActiveTexture(float x, float y, float w, float pos[i * 3 + 1] = pos[i * 3 + 1] * invDestH - 1.0f; } - // Upscaling postshaders doesn't look well with linear + // Upscaling postshaders don't look well with linear if (flags & DRAWTEX_LINEAR) { - render_->SetTextureSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f); + render_->SetTextureSampler(0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f); } else { - render_->SetTextureSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); + render_->SetTextureSampler(0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); } Simple2DVertex verts[4]; diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index b3c25e01c2..5a5fc1f071 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -180,7 +180,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) { // TODO: If the device doesn't support blit, this will corrupt the currently applied texture. framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY); // If we are rendering at a higher resolution, linear is probably best for the dest color. - renderManager->SetTextureSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f); + renderManager->SetTextureSampler(1, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f); fboTexBound_ = true; fboTexNeedBind_ = false; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 59eb3184c1..d16f14f372 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -151,11 +151,11 @@ void TextureCacheGLES::UpdateSamplingParams(TexCacheEntry &entry, bool force) { minLod = 0.0f; maxLod = 0.0f; } - render_->SetTextureLod(minLod, maxLod, lodBias); + render_->SetTextureLod(0, minLod, maxLod, lodBias); } float aniso = 0.0f; - render_->SetTextureSampler(sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); + render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); } void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight) { @@ -170,7 +170,7 @@ void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferH minFilt &= 1; // framebuffers can't mipmap. float aniso = 0.0f; - render_->SetTextureSampler(sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); + render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); // Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case. // This happens whether we have OES_texture_npot or not. @@ -447,7 +447,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY); render_->BindTexture(3, clutTexture); - render_->SetTextureSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); + render_->SetTextureSampler(3, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); shaderApply.Shade(render_); diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index 552ba4b5c4..466a6d958a 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -816,7 +816,12 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { break; case GLRRenderCommand::TEXTURESAMPLER: { - GLRTexture *tex = curTex[activeSlot]; + GLint slot = c.textureSampler.slot; + if (slot != activeSlot) { + glActiveTexture(GL_TEXTURE0 + slot); + activeSlot = slot; + } + GLRTexture *tex = curTex[slot]; if (!tex) { break; } @@ -846,7 +851,12 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } case GLRRenderCommand::TEXTURELOD: { - GLRTexture *tex = curTex[activeSlot]; + GLint slot = c.textureSampler.slot; + if (slot != activeSlot) { + glActiveTexture(GL_TEXTURE0 + slot); + activeSlot = slot; + } + GLRTexture *tex = curTex[slot]; if (!tex) { break; } @@ -900,8 +910,10 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } } - if (activeSlot != 0) + if (activeSlot != 0) { glActiveTexture(GL_TEXTURE0); + activeSlot = 0; // doesn't matter, just nice. + } // Wipe out the current state. glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/ext/native/thin3d/GLQueueRunner.h b/ext/native/thin3d/GLQueueRunner.h index 6043e80c94..63a17503c4 100644 --- a/ext/native/thin3d/GLQueueRunner.h +++ b/ext/native/thin3d/GLQueueRunner.h @@ -152,6 +152,7 @@ struct GLRRenderData { size_t offset; } bindVertexBuffer; struct { + int slot; GLenum wrapS; GLenum wrapT; GLenum magFilter; @@ -159,6 +160,7 @@ struct GLRRenderData { float anisotropy; } textureSampler; struct { + int slot; float minLod; float maxLod; float lodBias; diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 670ecd72f7..4ef204d558 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -567,9 +567,10 @@ public: } // Modifies the current texture as per GL specs, not global state. - void SetTextureSampler(GLenum wrapS, GLenum wrapT, GLenum magFilter, GLenum minFilter, float anisotropy) { + void SetTextureSampler(int slot, GLenum wrapS, GLenum wrapT, GLenum magFilter, GLenum minFilter, float anisotropy) { _dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); GLRRenderData data{ GLRRenderCommand::TEXTURESAMPLER }; + data.textureSampler.slot = slot; data.textureSampler.wrapS = wrapS; data.textureSampler.wrapT = wrapT; data.textureSampler.magFilter = magFilter; @@ -578,9 +579,10 @@ public: curRenderStep_->commands.push_back(data); } - void SetTextureLod(float minLod, float maxLod, float lodBias) { + void SetTextureLod(int slot, float minLod, float maxLod, float lodBias) { _dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); GLRRenderData data{ GLRRenderCommand::TEXTURELOD}; + data.textureLod.slot = slot; data.textureLod.minLod = minLod; data.textureLod.maxLod = maxLod; data.textureLod.lodBias = lodBias; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 6d81a98c6e..6d5513de29 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -921,7 +921,7 @@ void OpenGLContext::ApplySamplers() { } GLenum magFilt = samp->magFilt; GLenum minFilt = tex->HasMips() ? samp->mipMinFilt : samp->minFilt; - renderManager_.SetTextureSampler(wrapS, wrapT, magFilt, minFilt, 0.0f); + renderManager_.SetTextureSampler(i, wrapS, wrapT, magFilt, minFilt, 0.0f); } } }