TextureCache: Implement layered framebuffer support.

Stereoscopic EFB2Tex is now supported.
This commit is contained in:
Jules Blok 2014-10-27 00:52:56 +01:00
parent d9e280e338
commit 80616c6e9e
2 changed files with 31 additions and 11 deletions

View file

@ -74,6 +74,8 @@ public:
// Resolved framebuffer is only used in MSAA mode. // Resolved framebuffer is only used in MSAA mode.
static GLuint GetResolvedFramebuffer() { return m_resolvedFramebuffer; } static GLuint GetResolvedFramebuffer() { return m_resolvedFramebuffer; }
static int GetEFBLayers() { return m_EFBLayers; }
static void SetFramebuffer(GLuint fb); static void SetFramebuffer(GLuint fb);
// If in MSAA mode, this will perform a resolve of the specified rectangle, and return the resolve target as a texture ID. // If in MSAA mode, this will perform a resolve of the specified rectangle, and return the resolve target as a texture ID.

View file

@ -222,9 +222,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
int layers = 1; glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, gl_iformat, scaled_tex_w, scaled_tex_h, FramebufferManager::GetEFBLayers(), 0, gl_format, gl_type, nullptr);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, gl_iformat, scaled_tex_w, scaled_tex_h, layers, 0, gl_format, gl_type, nullptr);
glBindTexture(GL_TEXTURE_2D_ARRAY, 0); glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
glGenFramebuffers(1, &entry->framebuffer); glGenFramebuffers(1, &entry->framebuffer);
@ -322,11 +320,11 @@ TextureCache::TextureCache()
const char *pColorMatrixProg = const char *pColorMatrixProg =
"SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
"uniform vec4 colmat[7];\n" "uniform vec4 colmat[7];\n"
"in vec2 uv0;\n" "in vec3 f_uv0;\n"
"out vec4 ocol0;\n" "out vec4 ocol0;\n"
"\n" "\n"
"void main(){\n" "void main(){\n"
" vec4 texcol = texture(samp9, vec3(uv0, 0.0));\n" " vec4 texcol = texture(samp9, f_uv0);\n"
" texcol = round(texcol * colmat[5]) * colmat[6];\n" " texcol = round(texcol * colmat[5]) * colmat[6];\n"
" ocol0 = texcol * mat4(colmat[0], colmat[1], colmat[2], colmat[3]) + colmat[4];\n" " ocol0 = texcol * mat4(colmat[0], colmat[1], colmat[2], colmat[3]) + colmat[4];\n"
"}\n"; "}\n";
@ -334,11 +332,11 @@ TextureCache::TextureCache()
const char *pDepthMatrixProg = const char *pDepthMatrixProg =
"SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
"uniform vec4 colmat[5];\n" "uniform vec4 colmat[5];\n"
"in vec2 uv0;\n" "in vec3 f_uv0;\n"
"out vec4 ocol0;\n" "out vec4 ocol0;\n"
"\n" "\n"
"void main(){\n" "void main(){\n"
" vec4 texcol = texture(samp9, vec3(uv0, 0.0));\n" " vec4 texcol = texture(samp9, f_uv0);\n"
// 255.99998474121 = 16777215/16777216*256 // 255.99998474121 = 16777215/16777216*256
" float workspace = texcol.x * 255.99998474121;\n" " float workspace = texcol.x * 255.99998474121;\n"
@ -365,18 +363,38 @@ TextureCache::TextureCache()
"}\n"; "}\n";
const char *VProgram = const char *VProgram =
"out vec2 uv0;\n" "out vec2 v_uv0;\n"
"SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
"uniform vec4 copy_position;\n" // left, top, right, bottom "uniform vec4 copy_position;\n" // left, top, right, bottom
"void main()\n" "void main()\n"
"{\n" "{\n"
" vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n" " vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n"
" uv0 = mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0).xy);\n" " v_uv0 = mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0).xy);\n"
" gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n"
"}\n"; "}\n";
ProgramShaderCache::CompileShader(s_ColorMatrixProgram, VProgram, pColorMatrixProg); const char *GProgram =
ProgramShaderCache::CompileShader(s_DepthMatrixProgram, VProgram, pDepthMatrixProg); "layout(triangles) in;\n"
"layout(triangle_strip, max_vertices = 3) out;\n"
"in vec2 v_uv0[];\n"
"out vec3 f_uv0;\n"
"SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
"void main()\n"
"{\n"
" int layers = textureSize(samp9, 0).z;\n"
" for (int layer = 0; layer < layers; ++layer) {\n"
" for (int i = 0; i < gl_in.length(); ++i) {\n"
" f_uv0 = vec3(v_uv0[i], layer);\n"
" gl_Position = gl_in[i].gl_Position;\n"
" gl_Layer = layer;\n"
" EmitVertex();\n"
" }\n"
" EndPrimitive();\n"
" }\n"
"}\n";
ProgramShaderCache::CompileShader(s_ColorMatrixProgram, VProgram, pColorMatrixProg, GProgram);
ProgramShaderCache::CompileShader(s_DepthMatrixProgram, VProgram, pDepthMatrixProg, GProgram);
s_ColorMatrixUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "colmat"); s_ColorMatrixUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "colmat");
s_DepthMatrixUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "colmat"); s_DepthMatrixUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "colmat");