1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Merge pull request #1644 from vlj/gl

Gl: Fix for cubemap and R5G6B5 rtt format.
This commit is contained in:
vlj 2016-03-31 02:17:06 +02:00
commit d5bb951237
6 changed files with 53 additions and 16 deletions

@ -1 +1 @@
Subproject commit ec513f89f9354394fec465448a2838f106777640
Subproject commit 1affe90f0ec7f9bccb6841a56a2a5b66861efe6a

View File

@ -47,11 +47,11 @@ std::string getFunctionImpl(FUNCTION f)
case FUNCTION::FUNCTION_TEXTURE_SAMPLE1D_LOD:
return "textureLod($t, $0.x, $1)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D:
return "texture($t, $0.xy)";
return "texture($t, $0.xy * $t_coord_scale)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_PROJ:
return "textureProj($t, $0.xyz, $1.x)"; // Note: $1.x is bias
return "textureProj($t, $0.xyz * vec3($t_coord_scale, 1.) , $1.x)"; // Note: $1.x is bias
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_LOD:
return "textureLod($t, $0.xy, $1.x)";
return "textureLod($t, $0.xy * $t_coord_scale, $1.x)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE:
return "texture($t, $0.xyz)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE_PROJ:

View File

@ -85,9 +85,6 @@ void GLFragmentDecompilerThread::insertConstants(std::stringstream & OS)
std::string samplerType = PT.type;
int index = atoi(&PI.name.data()[3]);
if (m_prog.unnormalized_coords & (1 << index))
samplerType = "sampler2DRect";
OS << "uniform " << samplerType << " " << PI.name << ";" << std::endl;
}
}
@ -163,6 +160,27 @@ void GLFragmentDecompilerThread::insertMainStart(std::stringstream & OS)
OS << " vec4 ssa = gl_FrontFacing ? vec4(1.) : vec4(-1.);\n";
for (const ParamType& PT : m_parr.params[PF_PARAM_UNIFORM])
{
if (PT.type != "sampler2D")
continue;
for (const ParamItem& PI : PT.items)
{
std::string samplerType = PT.type;
int index = atoi(&PI.name.data()[3]);
if (m_prog.unnormalized_coords & (1 << index))
{
OS << "vec2 tex" << index << "_coord_scale = 1. / textureSize(" << PI.name << ", 0);\n";
}
else
{
OS << "vec2 tex" << index << "_coord_scale = vec2(1.);\n";
}
}
}
// search if there is fogc in inputs
for (const ParamType& PT : m_parr.params[PF_PARAM_IN])
{

View File

@ -393,6 +393,21 @@ namespace
}
}
namespace
{
GLenum get_gl_target_for_texture(const rsx::texture& tex)
{
switch (tex.get_extended_texture_dimension())
{
case rsx::texture_dimension_extended::texture_dimension_1d: return GL_TEXTURE_1D;
case rsx::texture_dimension_extended::texture_dimension_2d: return GL_TEXTURE_2D;
case rsx::texture_dimension_extended::texture_dimension_cubemap: return GL_TEXTURE_CUBE_MAP;
case rsx::texture_dimension_extended::texture_dimension_3d: return GL_TEXTURE_3D;
}
throw EXCEPTION("Unknow texture target");
}
}
void GLGSRender::end()
{
if (!draw_fbo)
@ -412,19 +427,15 @@ void GLGSRender::end()
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, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glProgramUniform1i(m_program->id(), location, i);
continue;
}
m_gl_textures[i].set_target(target);
m_gl_textures[i].set_target(get_gl_target_for_texture(textures[i]));
__glcheck m_gl_texture_cache.upload_texture(i, textures[i], m_gl_textures[i], m_rtts);
glProgramUniform1i(m_program->id(), location, i);

View File

@ -9,7 +9,7 @@ color_format rsx::internals::surface_color_format_to_gl(rsx::surface_color_forma
switch (color_format)
{
case rsx::surface_color_format::r5g6b5:
return{ ::gl::texture::type::ushort_5_6_5, ::gl::texture::format::bgr, false, 3, 2 };
return{ ::gl::texture::type::ushort_5_6_5, ::gl::texture::format::rgb, false, 3, 2 };
case rsx::surface_color_format::a8r8g8b8:
return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1 };

View File

@ -327,6 +327,12 @@ namespace rsx
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glTexStorage2D(m_target, tex.get_exact_mipmap_count(), get_sized_internal_format(format), tex.width(), tex.height());
// Note : input_layouts size is get_exact_mipmap_count() for non cubemap texture, and 6 * get_exact_mipmap_count() for cubemap
// Thus for non cubemap texture, mip_level / mipmap_per_layer will always be rounded to 0.
// mip_level % mipmap_per_layer will always be equal to mip_level
u16 mipmap_per_layer = tex.get_exact_mipmap_count();
GLenum real_target = tex.cubemap() ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target;
if (!is_compressed_format(format))
{
const auto &format_type = get_format_type(format);
@ -334,7 +340,8 @@ namespace rsx
for (const rsx_subresource_layout &layout : input_layouts)
{
upload_texture_subresource(data_upload_buf, layout, format, is_swizzled, 4);
glTexSubImage2D(m_target, mip_level++, 0, 0, layout.width_in_block, layout.height_in_block, std::get<0>(format_type), std::get<1>(format_type), data_upload_buf.data());
glTexSubImage2D(real_target + mip_level / mipmap_per_layer, mip_level % mipmap_per_layer, 0, 0, layout.width_in_block, layout.height_in_block, std::get<0>(format_type), std::get<1>(format_type), data_upload_buf.data());
mip_level++;
}
}
else
@ -344,7 +351,8 @@ namespace rsx
for (const rsx_subresource_layout &layout : input_layouts)
{
u32 size = layout.width_in_block * layout.height_in_block * ((format == CELL_GCM_TEXTURE_COMPRESSED_DXT1) ? 8 : 16);
glCompressedTexSubImage2D(m_target, mip_level++, 0, 0, layout.width_in_block * 4, layout.height_in_block * 4, get_sized_internal_format(format), size, layout.data.data());
glCompressedTexSubImage2D(real_target + mip_level / mipmap_per_layer, mip_level % mipmap_per_layer, 0, 0, layout.width_in_block * 4, layout.height_in_block * 4, get_sized_internal_format(format), size, layout.data.data());
mip_level++;
}
}