From d8cd2c3252ab6f2ce6c1656b5eb194863e834f52 Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Mon, 29 Jun 2015 22:19:19 -0300 Subject: Implement scaled partial texture updates --- Source/Core/VideoBackends/OGL/TextureCache.cpp | 69 +++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index cefc8017d6..ebc3a672f1 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -33,11 +33,13 @@ namespace OGL { +static SHADER s_ColorCopyProgram; static SHADER s_ColorMatrixProgram; static SHADER s_DepthMatrixProgram; static GLuint s_ColorMatrixUniform; static GLuint s_DepthMatrixUniform; static GLuint s_ColorCopyPositionUniform; +static GLuint s_ColorMatrixPositionUniform; static GLuint s_DepthCopyPositionUniform; static u32 s_ColorCbufid; static u32 s_DepthCbufid; @@ -137,12 +139,53 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConf return entry; } -void TextureCache::TCacheEntry::DoPartialTextureUpdate(TCacheEntryBase* entry_, u32 x, u32 y) +void TextureCache::TCacheEntry::CopyRectangleFromTexture( + const TCacheEntryBase* source, + const MathUtil::Rectangle &srcrect, + const MathUtil::Rectangle &dstrect) { - - TCacheEntry* entry = (TCacheEntry*)entry_; - - glCopyImageSubData(entry->texture, GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, texture, GL_TEXTURE_2D_ARRAY, 0, x, y, 0, entry->native_width, entry->native_height, 1); + TCacheEntry* srcentry = (TCacheEntry*)source; + if (srcrect.GetWidth() == dstrect.GetWidth() + && srcrect.GetHeight() == dstrect.GetHeight() + && g_ActiveConfig.backend_info.bSupportsCopySubImage) + { + glCopyImageSubData( + srcentry->texture, + GL_TEXTURE_2D_ARRAY, + 0, + srcrect.left, + srcrect.top, + 0, + texture, + GL_TEXTURE_2D_ARRAY, + 0, + dstrect.left, + dstrect.top, + 0, + dstrect.GetWidth(), + dstrect.GetHeight(), + 1); + return; + } + else if (!config.rendertarget) + { + return; + } + g_renderer->ResetAPIState(); + FramebufferManager::SetFramebuffer(framebuffer); + glActiveTexture(GL_TEXTURE9); + glBindTexture(GL_TEXTURE_2D_ARRAY, srcentry->texture); + g_sampler_cache->BindLinearSampler(9); + glViewport(dstrect.left, dstrect.top, dstrect.GetWidth(), dstrect.GetHeight()); + s_ColorCopyProgram.Bind(); + glUniform4f(s_ColorCopyPositionUniform, + float(srcrect.left), + float(srcrect.top), + float(srcrect.GetWidth()), + float(srcrect.GetHeight())); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + FramebufferManager::SetFramebuffer(0); + g_renderer->RestoreAPIState(); } void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, @@ -208,7 +251,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo if (s_ColorCbufid != cbufid) glUniform4fv(s_ColorMatrixUniform, 7, colmat); s_ColorCbufid = cbufid; - uniform_location = s_ColorCopyPositionUniform; + uniform_location = s_ColorMatrixPositionUniform; } TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect); @@ -286,6 +329,16 @@ void TextureCache::SetStage() void TextureCache::CompileShaders() { + const char *pColorCopyProg = + "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" + "in vec3 f_uv0;\n" + "out vec4 ocol0;\n" + "\n" + "void main(){\n" + " vec4 texcol = texture(samp9, f_uv0);\n" + " ocol0 = texcol;\n" + "}\n"; + const char *pColorMatrixProg = "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "uniform vec4 colmat[7];\n" @@ -357,6 +410,7 @@ void TextureCache::CompileShaders() const char* prefix = (GProgram == nullptr) ? "f" : "v"; const char* depth_layer = (g_ActiveConfig.bStereoEFBMonoDepth) ? "0.0" : "f_uv0.z"; + ProgramShaderCache::CompileShader(s_ColorCopyProgram, StringFromFormat(VProgram, prefix, prefix).c_str(), pColorCopyProg, GProgram); ProgramShaderCache::CompileShader(s_ColorMatrixProgram, StringFromFormat(VProgram, prefix, prefix).c_str(), pColorMatrixProg, GProgram); ProgramShaderCache::CompileShader(s_DepthMatrixProgram, StringFromFormat(VProgram, prefix, prefix).c_str(), StringFromFormat(pDepthMatrixProg, depth_layer).c_str(), GProgram); @@ -365,7 +419,8 @@ void TextureCache::CompileShaders() s_ColorCbufid = -1; s_DepthCbufid = -1; - s_ColorCopyPositionUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "copy_position"); + s_ColorCopyPositionUniform = glGetUniformLocation(s_ColorCopyProgram.glprogid, "copy_position"); + s_ColorMatrixPositionUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "copy_position"); s_DepthCopyPositionUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "copy_position"); std::string palette_shader = -- cgit v1.2.3