move utils texture to sampler 8+9

rasterfont tex will aways bound to samp8.
efb copy utils will be done in samp9.
This commit is contained in:
degasus 2013-01-19 00:39:31 +01:00
parent 6401a18143
commit 074f73c641
7 changed files with 35 additions and 27 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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; y<char_height; y++) {
@ -280,8 +281,7 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
cached_color = color;
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glActiveTexture(GL_TEXTURE0+8);
glDrawArrays(GL_TRIANGLES, 0, usage/4);
}

View File

@ -1437,6 +1437,8 @@ void Renderer::RestoreAPIState()
VertexManager *vm = (OGL::VertexManager*)g_vertex_manager;
glBindBuffer(GL_ARRAY_BUFFER, vm->m_vertex_buffers);
vm->m_last_vao = 0;
TextureCache::SetStage();
}
void Renderer::SetGenerationMode()

View File

@ -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<u32> 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 ()
{
}
}

View File

@ -34,6 +34,7 @@ class TextureCache : public ::TextureCache
public:
TextureCache();
static void DisableStage(unsigned int stage);
static void SetStage();
private:
struct TCacheEntry : TCacheEntryBase

View File

@ -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();