diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 6982b97e60..3dbb3aaa38 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -90,6 +90,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) float samples = (float)GetEncodedSampleCount(format); if (ApiType == API_OPENGL) { + WRITE(p, "#define samp0 samp9\n"); WRITE(p, "uniform sampler2DRect samp0;\n"); } else if (ApiType & API_D3D9) @@ -171,6 +172,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType) // 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments if (ApiType == API_OPENGL) { + WRITE(p, "#define samp0 samp9\n"); WRITE(p, "uniform sampler2DRect samp0;\n"); } else if (ApiType & API_D3D9) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index ad0173341c..cbeed4376c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -86,7 +86,7 @@ void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry) entry.UniformLocations[a] = glGetUniformLocation(entry.prog_id, UniformNames[a]); // Bind Texture Sampler - for (int a = 0; a < 8; ++a) + for (int a = 0; a <= 9; ++a) { char name[8]; snprintf(name, 8, "samp%d", a); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index 7ac793527c..95ca3f202d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -141,12 +141,12 @@ static const char *s_vertexShaderSrc = static const char *s_fragmentShaderSrc = "#version 130\n" - "uniform sampler2D samp0;\n" + "uniform sampler2D samp8;\n" "uniform vec4 color;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" "void main(void) {\n" - " ocol0 = texture2D(samp0,uv0) * color;\n" + " ocol0 = texture2D(samp8,uv0) * color;\n" "}\n"; @@ -157,6 +157,7 @@ RasterFont::RasterFont() { // generate the texture glGenTextures(1, &texture); + glActiveTexture(GL_TEXTURE0+8); glBindTexture(GL_TEXTURE_2D, texture); u32* texture_data = new u32[char_width*char_count*char_height]; for(u32 y=0; ym_vertex_buffers); vm->m_last_vao = 0; + + TextureCache::SetStage(); } void Renderer::SetGenerationMode() diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 9a393305d1..5b372a106f 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -97,8 +97,11 @@ bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width int width = std::max(virtual_width >> level, 1); int height = std::max(virtual_height >> level, 1); std::vector data(width * height); + glActiveTexture(GL_TEXTURE0+9); glBindTexture(textarget, tex); glGetTexImage(textarget, level, GL_BGRA, GL_UNSIGNED_BYTE, &data[0]); + glBindTexture(textarget, 0); + TextureCache::SetStage(); const GLenum err = GL_REPORT_ERROR(); if (GL_NO_ERROR != err) @@ -254,6 +257,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture( unsigned int scaled_tex_w, unsigned int scaled_tex_h) { TCacheEntry *const entry = new TCacheEntry; + glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_2D, entry->texture); GL_REPORT_ERRORD(); @@ -267,6 +271,10 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture( glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, scaled_tex_w, scaled_tex_h, 0, gl_format, gl_type, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + + SetStage(); + GL_REPORT_ERRORD(); return entry; @@ -295,8 +303,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo GL_REPORT_FBO_ERROR(); GL_REPORT_ERRORD(); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_RECTANGLE, read_texture); glViewport(0, 0, virtual_width, virtual_height); @@ -446,7 +453,7 @@ TextureCache::TextureCache() const char *pColorMatrixProg = "#version 130\n" "#extension GL_ARB_texture_rectangle : enable\n" - "uniform sampler2DRect samp0;\n" + "uniform sampler2DRect samp9;\n" "uniform vec4 colmat[7];\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" @@ -454,7 +461,7 @@ TextureCache::TextureCache() "void main(){\n" " vec4 Temp0, Temp1;\n" " vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n" - " Temp0 = texture2DRect(samp0, uv0);\n" + " Temp0 = texture2DRect(samp9, uv0);\n" " Temp0 = Temp0 * colmat[5];\n" " Temp0 = Temp0 + K0;\n" " Temp0 = floor(Temp0);\n" @@ -474,7 +481,7 @@ TextureCache::TextureCache() const char *pDepthMatrixProg = "#version 130\n" "#extension GL_ARB_texture_rectangle : enable\n" - "uniform sampler2DRect samp0;\n" + "uniform sampler2DRect samp9;\n" "uniform vec4 colmat[5];\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" @@ -483,7 +490,7 @@ TextureCache::TextureCache() " vec4 R0, R1, R2;\n" " vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n" " vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n" - " R2 = texture2DRect(samp0, uv0);\n" + " R2 = texture2DRect(samp9, uv0);\n" " R0.x = R2.x * K0.x;\n" " R0.x = floor(R0).x;\n" " R0.yzw = (R0 - R0.x).yzw;\n" @@ -555,4 +562,9 @@ void TextureCache::DisableStage(unsigned int stage) { } +void TextureCache::SetStage () +{ +} + + } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h index af0bb071c7..4d14c61698 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h @@ -34,6 +34,7 @@ class TextureCache : public ::TextureCache public: TextureCache(); static void DisableStage(unsigned int stage); + static void SetStage(); private: struct TCacheEntry : TCacheEntryBase diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 5f98fe9377..97b53552a9 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -73,13 +73,13 @@ void CreatePrograms() const char *FProgramRgbToYuyv = "#version 130\n" "#extension GL_ARB_texture_rectangle : enable\n" - "uniform sampler2DRect samp0;\n" + "uniform sampler2DRect samp9;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" "void main()\n" "{\n" - " vec3 c0 = texture2DRect(samp0, uv0).rgb;\n" - " vec3 c1 = texture2DRect(samp0, uv0 + vec2(1.0, 0.0)).rgb;\n" + " vec3 c0 = texture2DRect(samp9, uv0).rgb;\n" + " vec3 c1 = texture2DRect(samp9, uv0 + vec2(1.0, 0.0)).rgb;\n" " vec3 c01 = (c0 + c1) * 0.5;\n" " vec3 y_const = vec3(0.257,0.504,0.098);\n" " vec3 u_const = vec3(-0.148,-0.291,0.439);\n" @@ -93,12 +93,12 @@ void CreatePrograms() const char *FProgramYuyvToRgb = "#version 130\n" "#extension GL_ARB_texture_rectangle : enable\n" - "uniform sampler2DRect samp0;\n" + "uniform sampler2DRect samp9;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" "void main()\n" "{\n" - " vec4 c0 = texture2DRect(samp0, uv0).rgba;\n" + " vec4 c0 = texture2DRect(samp9, uv0).rgba;\n" " float f = step(0.5, fract(uv0.x));\n" " float y = mix(c0.b, c0.r, f);\n" " float yComp = 1.164f * (y - 0.0625f);\n" @@ -237,12 +237,8 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc, glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, s_dstRenderBuffer); GL_REPORT_ERRORD(); - for (int i = 1; i < 8; ++i) - TextureCache::DisableStage(i); - // set source texture - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_RECTANGLE, srcTexture); if (linearFilter) @@ -415,13 +411,9 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender GL_REPORT_FBO_ERROR(); - for (int i = 1; i < 8; ++i) - TextureCache::DisableStage(i); - // activate source texture // set srcAddr as data for source texture - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_RECTANGLE, s_srcTexture); // TODO: make this less slow. (How?) @@ -469,7 +461,6 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender // reset state glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - TextureCache::DisableStage(0); VertexShaderManager::SetViewportChanged();