Skip to content

Commit

Permalink
Merge pull request RPCS3#1512 from kd-11/gl_sampler_fix
Browse files Browse the repository at this point in the history
gl: Always bind null for unused shader inputs
  • Loading branch information
tambry committed Feb 25, 2016
2 parents 0f0de47 + 974ea68 commit 6353575
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions rpcs3/Emu/RSX/GL/GLGSRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,21 @@ void GLGSRender::end()
//setup textures
for (int i = 0; i < rsx::limits::textures_count; ++i)
{
if (!textures[i].enabled())
{
continue;
}

int location;
if (m_program->uniforms.has_location("tex" + std::to_string(i), &location))
{
u32 target = GL_TEXTURE_2D;
if (textures[i].format() & CELL_GCM_TEXTURE_UN)
target = GL_TEXTURE_RECTANGLE;

if (!textures[i].enabled())
{
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(target, NULL);
glProgramUniform1i(m_program->id(), location, i);
continue;
}

m_gl_textures[i].set_target(target);

__glcheck m_gl_texture_cache.upload_texture(i, textures[i], m_gl_textures[i]);
Expand Down Expand Up @@ -469,13 +472,18 @@ void GLGSRender::end()
{
auto &vertex_info = vertex_arrays_info[index];

if (!vertex_info.size) // disabled
continue;

int location;
if (!m_program->uniforms.has_location(reg_table[index] + "_buffer", &location))
continue;

if (!vertex_info.size) // disabled, bind a null sampler
{
glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count);
glBindTexture(GL_TEXTURE_BUFFER, NULL);
glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count);
continue;
}

const u32 element_size = rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.size);
u32 data_size = element_size * vertex_draw_count;
u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size);
Expand Down Expand Up @@ -536,7 +544,7 @@ void GLGSRender::end()
texture->copy_from(*buffer, gl_type);

//Link texture to uniform
m_program->uniforms.texture(location, index + rsx::limits::vertex_count, *texture);
m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture);
}
}

Expand All @@ -552,14 +560,19 @@ void GLGSRender::end()
{
for (int index = 0; index < rsx::limits::vertex_count; ++index)
{
bool enabled = !!(input_mask & (1 << index));
if (!enabled)
continue;

int location;
if (!m_program->uniforms.has_location(reg_table[index]+"_buffer", &location))
continue;

bool enabled = !!(input_mask & (1 << index));
if (!enabled)
{
glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count);
glBindTexture(GL_TEXTURE_BUFFER, NULL);
glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count);
continue;
}

if (vertex_arrays_info[index].size > 0)
{
auto &vertex_info = vertex_arrays_info[index];
Expand Down Expand Up @@ -637,7 +650,7 @@ void GLGSRender::end()
texture->copy_from(*buffer, gl_type);

//Link texture to uniform
m_program->uniforms.texture(location, index + rsx::limits::vertex_count, *texture);
m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture);
}
else if (register_vertex_info[index].size > 0)
{
Expand All @@ -663,14 +676,21 @@ void GLGSRender::end()
texture->copy_from(*buffer, gl_type);

//Link texture to uniform
m_program->uniforms.texture(location, index + rsx::limits::vertex_count, *texture);
m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture);
break;
}
default:
LOG_ERROR(RSX, "bad non array vertex data format (type = %d, size = %d)", vertex_info.type, vertex_info.size);
break;
}
}
else
{
glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count);
glBindTexture(GL_TEXTURE_BUFFER, NULL);
glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count);
continue;
}
}
}

Expand Down

0 comments on commit 6353575

Please sign in to comment.