diff options
Diffstat (limited to 'src/video_core/renderer_opengl')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 20 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 87 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 3 |
4 files changed, 54 insertions, 66 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 456443e86..8b717e43d 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -561,20 +561,16 @@ RasterizerCacheOpenGL::GetFramebufferSurfaces( color_params.is_tiled = depth_params.is_tiled = true; // Set the internal resolution, assume the same scaling factor for top and bottom screens - const Layout::FramebufferLayout& layout = VideoCore::g_emu_window->GetFramebufferLayout(); - if (Settings::values.resolution_factor == 0.0f) { + float resolution_scale_factor = Settings::values.resolution_factor; + if (resolution_scale_factor == 0.0f) { // Auto - scale resolution to the window size - color_params.res_scale_width = depth_params.res_scale_width = - (float)layout.top_screen.GetWidth() / VideoCore::kScreenTopWidth; - color_params.res_scale_height = depth_params.res_scale_height = - (float)layout.top_screen.GetHeight() / VideoCore::kScreenTopHeight; - } else { - // Otherwise, scale the resolution by the specified factor - color_params.res_scale_width = Settings::values.resolution_factor; - depth_params.res_scale_width = Settings::values.resolution_factor; - color_params.res_scale_height = Settings::values.resolution_factor; - depth_params.res_scale_height = Settings::values.resolution_factor; + resolution_scale_factor = VideoCore::g_emu_window->GetFramebufferLayout().GetScalingRatio(); } + // Scale the resolution by the specified factor + color_params.res_scale_width = resolution_scale_factor; + depth_params.res_scale_width = resolution_scale_factor; + color_params.res_scale_height = resolution_scale_factor; + depth_params.res_scale_height = resolution_scale_factor; color_params.addr = config.GetColorBufferPhysicalAddress(); color_params.pixel_format = CachedSurface::PixelFormatFromColorFormat(config.color_format); diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 3eeb47d33..db53710aa 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -152,12 +152,40 @@ static bool IsPassThroughTevStage(const TevStageConfig& stage) { stage.GetColorMultiplier() == 1 && stage.GetAlphaMultiplier() == 1); } -static std::string TexCoord(const PicaShaderConfig& config, int texture_unit) { - if (texture_unit == 2 && config.state.texture2_use_coord1) { - return "texcoord[1]"; +static std::string SampleTexture(const PicaShaderConfig& config, unsigned texture_unit) { + const auto& state = config.state; + switch (texture_unit) { + case 0: + // Only unit 0 respects the texturing type + switch (state.texture0_type) { + case TexturingRegs::TextureConfig::Texture2D: + return "texture(tex[0], texcoord[0])"; + case TexturingRegs::TextureConfig::Projection2D: + return "textureProj(tex[0], vec3(texcoord[0], texcoord0_w))"; + default: + LOG_CRITICAL(HW_GPU, "Unhandled texture type %x", + static_cast<int>(state.texture0_type)); + UNIMPLEMENTED(); + return "texture(tex[0], texcoord[0])"; + } + case 1: + return "texture(tex[1], texcoord[1])"; + case 2: + if (state.texture2_use_coord1) + return "texture(tex[2], texcoord[1])"; + else + return "texture(tex[2], texcoord[2])"; + case 3: + if (state.proctex.enable) { + return "ProcTex()"; + } else { + LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it"); + return "vec4(0.0)"; + } + default: + UNREACHABLE(); + return ""; } - - return "texcoord[" + std::to_string(texture_unit) + "]"; } /// Writes the specified TEV stage source component(s) @@ -176,35 +204,16 @@ static void AppendSource(std::string& out, const PicaShaderConfig& config, out += "secondary_fragment_color"; break; case Source::Texture0: - // Only unit 0 respects the texturing type (according to 3DBrew) - switch (state.texture0_type) { - case TexturingRegs::TextureConfig::Texture2D: - out += "texture(tex[0], texcoord[0])"; - break; - case TexturingRegs::TextureConfig::Projection2D: - out += "textureProj(tex[0], vec3(texcoord[0], texcoord0_w))"; - break; - default: - out += "texture(tex[0], texcoord[0])"; - LOG_CRITICAL(HW_GPU, "Unhandled texture type %x", - static_cast<int>(state.texture0_type)); - UNIMPLEMENTED(); - break; - } + out += SampleTexture(config, 0); break; case Source::Texture1: - out += "texture(tex[1], texcoord[1])"; + out += SampleTexture(config, 1); break; case Source::Texture2: - out += "texture(tex[2], " + TexCoord(config, 2) + ")"; + out += SampleTexture(config, 2); break; case Source::Texture3: - if (config.state.proctex.enable) { - out += "ProcTex()"; - } else { - LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it"); - out += "vec4(0.0)"; - } + out += SampleTexture(config, 3); break; case Source::PreviousBuffer: out += "combiner_buffer"; @@ -515,18 +524,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { // Bump mapping is enabled using a normal map, read perturbation vector from the selected // texture - if (lighting.bump_selector == 3) { - if (config.state.proctex.enable) { - out += "vec3 surface_normal = 2.0 * ProcTex().rgb - 1.0;\n"; - } else { - LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it"); - out += "vec3 surface_normal = vec3(-1.0);\n"; - } - } else { - std::string bump_selector = std::to_string(lighting.bump_selector); - out += "vec3 surface_normal = 2.0 * texture(tex[" + bump_selector + "], " + - TexCoord(config, lighting.bump_selector) + ").rgb - 1.0;\n"; - } + out += "vec3 surface_normal = 2.0 * (" + SampleTexture(config, lighting.bump_selector) + + ").rgb - 1.0;\n"; // Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher // precision result @@ -545,8 +544,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { } // Rotate the surface-local normal by the interpolated normal quaternion to convert it to - // eyespace - out += "vec3 normal = normalize(quaternion_rotate(normquat, surface_normal));\n"; + // eyespace. + out += "vec3 normal = quaternion_rotate(normalize(normquat), surface_normal);\n"; // Gets the index into the specified lookup table for specular lighting auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input, @@ -1030,7 +1029,9 @@ uniform sampler1D proctex_diff_lut; // Rotate the vector v by the quaternion q vec3 quaternion_rotate(vec4 q, vec3 v) { return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v); -})"; +} + +)"; if (config.state.proctex.enable) AppendProcTexSampler(out, config); diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index e19375466..d90c776f9 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -94,14 +94,8 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons return matrix; } -/// RendererOpenGL constructor -RendererOpenGL::RendererOpenGL() { - resolution_width = std::max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); - resolution_height = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight; -} - -/// RendererOpenGL destructor -RendererOpenGL::~RendererOpenGL() {} +RendererOpenGL::RendererOpenGL() = default; +RendererOpenGL::~RendererOpenGL() = default; /// Swap buffers (render frame) void RendererOpenGL::SwapBuffers() { diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 87c556cff..0b4f69e8f 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -68,9 +68,6 @@ private: EmuWindow* render_window; ///< Handle to render window - int resolution_width; ///< Current resolution width - int resolution_height; ///< Current resolution height - OpenGLState state; // OpenGL object IDs |
