diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index a4513f90b..9fa5f9e65 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -124,7 +124,7 @@ inline void Write(u32 addr, const T data) { UNIMPLEMENTED(); break; } - + unsigned horizontal_scale = (config.scaling != config.NoScale) ? 2 : 1; unsigned vertical_scale = (config.scaling == config.ScaleXY) ? 2 : 1; diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h index a672d2bed..5757ac75d 100644 --- a/src/video_core/renderer_base.h +++ b/src/video_core/renderer_base.h @@ -50,7 +50,7 @@ public: return m_current_frame; } - HWRasterizer *hw_rasterizer; + std::unique_ptr hw_rasterizer; protected: f32 m_current_fps; ///< Current framerate, should be set by the renderer diff --git a/src/video_core/renderer_opengl/gl_pica_to_gl.h b/src/video_core/renderer_opengl/gl_pica_to_gl.h index 59b92ab52..9512b8571 100644 --- a/src/video_core/renderer_opengl/gl_pica_to_gl.h +++ b/src/video_core/renderer_opengl/gl_pica_to_gl.h @@ -26,8 +26,7 @@ static GLenum WrapMode(Pica::Regs::TextureConfig::WrapMode mode) { } } -static GLenum BlendFunc(u32 factor) -{ +static GLenum BlendFunc(u32 factor) { switch (factor) { case Pica::registers.output_merger.alpha_blending.Zero: return GL_ZERO; @@ -65,8 +64,7 @@ static GLenum BlendFunc(u32 factor) } } -static GLenum CompareFunc(u32 func) -{ +static GLenum CompareFunc(u32 func) { switch (func) { case Pica::registers.output_merger.Never: return GL_NEVER; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 33bfd25a7..8b80f8256 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -447,8 +447,7 @@ void RasterizerOpenGL::SyncDrawState() { state.stencil.test_func = PicaToGL::CompareFunc(Pica::registers.output_merger.stencil_test.stencil_test_func.Value()); state.stencil.test_ref = Pica::registers.output_merger.stencil_test.stencil_reference_value.Value(); state.stencil.test_mask = Pica::registers.output_merger.stencil_test.stencil_replacement_value.Value(); - } - else { + } else { state.stencil.test_enabled = false; } @@ -484,8 +483,7 @@ void RasterizerOpenGL::SyncDrawState() { if (texture.enabled) { state.texture_unit[i].enabled_2d = true; res_cache.LoadAndBindTexture(state, i, texture); - } - else { + } else { state.texture_unit[i].enabled_2d = false; } } @@ -559,19 +557,17 @@ void RasterizerOpenGL::ReloadColorBuffer() { u32 bytes_per_pixel = ColorFormatBytesPerPixel(fb_color_texture.format); - u8* ogl_img = new u8[fb_color_texture.width * fb_color_texture.height * bytes_per_pixel]; + std::unique_ptr ogl_img(new u8[fb_color_texture.width * fb_color_texture.height * bytes_per_pixel]); // TODO: Evaluate whether u16/memcpy/u32 is faster for 2/3/4 bpp versus memcpy for all - for (int x = 0; x < fb_color_texture.width; ++x) - { - for (int y = 0; y < fb_color_texture.height; ++y) - { + for (int x = 0; x < fb_color_texture.width; ++x) { + for (int y = 0; y < fb_color_texture.height; ++y) { const u32 coarse_y = y & ~7; u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; u32 ogl_px_idx = x * bytes_per_pixel + y * fb_color_texture.width * bytes_per_pixel; u8* pixel = color_buffer + dst_offset; - memcpy(&ogl_img[ogl_px_idx], pixel, bytes_per_pixel); + memcpy(&ogl_img.get()[ogl_px_idx], pixel, bytes_per_pixel); } } @@ -580,9 +576,7 @@ void RasterizerOpenGL::ReloadColorBuffer() { state.Apply(); glActiveTexture(GL_TEXTURE0); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, fb_color_texture.width, fb_color_texture.height, fb_color_texture.gl_format, fb_color_texture.gl_type, ogl_img); - - delete[] ogl_img; + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, fb_color_texture.width, fb_color_texture.height, fb_color_texture.gl_format, fb_color_texture.gl_type, ogl_img.get()); } /// Copies the 3ds depth framebuffer into the OpenGL depth framebuffer texture @@ -599,27 +593,25 @@ void RasterizerOpenGL::ReloadDepthBuffer() { // OpenGL needs 4 bpp alignment for D24 u32 ogl_bpp = bytes_per_pixel == 3 ? 4 : bytes_per_pixel; - u8* ogl_img = new u8[fb_depth_texture.width * fb_depth_texture.height * ogl_bpp]; + std::unique_ptr ogl_img(new u8[fb_depth_texture.width * fb_depth_texture.height * ogl_bpp]); - for (int x = 0; x < fb_depth_texture.width; ++x) - { - for (int y = 0; y < fb_depth_texture.height; ++y) - { + for (int x = 0; x < fb_depth_texture.width; ++x) { + for (int y = 0; y < fb_depth_texture.height; ++y) { const u32 coarse_y = y & ~7; u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; u32 ogl_px_idx = x + y * fb_depth_texture.width; switch (fb_depth_texture.format) { case Pica::Regs::DepthFormat::D16: - ((u16*)ogl_img)[ogl_px_idx] = Color::DecodeD16(depth_buffer + dst_offset); + ((u16*)ogl_img.get())[ogl_px_idx] = Color::DecodeD16(depth_buffer + dst_offset); break; case Pica::Regs::DepthFormat::D24: - ((u32*)ogl_img)[ogl_px_idx] = Color::DecodeD24(depth_buffer + dst_offset); + ((u32*)ogl_img.get())[ogl_px_idx] = Color::DecodeD24(depth_buffer + dst_offset); break; case Pica::Regs::DepthFormat::D24S8: { Math::Vec2 depth_stencil = Color::DecodeD24S8(depth_buffer + dst_offset); - ((u32*)ogl_img)[ogl_px_idx] = depth_stencil.x << 8 | depth_stencil.y; + ((u32*)ogl_img.get())[ogl_px_idx] = depth_stencil.x << 8 | depth_stencil.y; break; } default: @@ -635,9 +627,7 @@ void RasterizerOpenGL::ReloadDepthBuffer() { state.Apply(); glActiveTexture(GL_TEXTURE0); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, fb_depth_texture.width, fb_depth_texture.height, fb_depth_texture.gl_format, fb_depth_texture.gl_type, ogl_img); - - delete[] ogl_img; + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, fb_depth_texture.width, fb_depth_texture.height, fb_depth_texture.gl_format, fb_depth_texture.gl_type, ogl_img.get()); } /** @@ -646,8 +636,7 @@ void RasterizerOpenGL::ReloadDepthBuffer() { * Then copies into the 3ds framebuffer using proper Morton order */ void RasterizerOpenGL::CommitFramebuffer() { - if (last_fb_color_addr != -1) - { + if (last_fb_color_addr != -1) { u8* color_buffer = Memory::GetPhysicalPointer(last_fb_color_addr); if (color_buffer != nullptr) { @@ -662,10 +651,8 @@ void RasterizerOpenGL::CommitFramebuffer() { glActiveTexture(GL_TEXTURE0); glGetTexImage(GL_TEXTURE_2D, 0, fb_color_texture.gl_format, fb_color_texture.gl_type, ogl_img.get()); - for (int x = 0; x < fb_color_texture.width; ++x) - { - for (int y = 0; y < fb_color_texture.height; ++y) - { + for (int x = 0; x < fb_color_texture.width; ++x) { + for (int y = 0; y < fb_color_texture.height; ++y) { const u32 coarse_y = y & ~7; u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; u32 ogl_px_idx = x * bytes_per_pixel + y * fb_color_texture.width * bytes_per_pixel; @@ -677,8 +664,7 @@ void RasterizerOpenGL::CommitFramebuffer() { } } - if (last_fb_depth_addr != -1) - { + if (last_fb_depth_addr != -1) { // TODO: Output seems correct visually, but doesn't quite match sw renderer output. One of them is wrong. u8* depth_buffer = Memory::GetPhysicalPointer(last_fb_depth_addr); @@ -697,10 +683,8 @@ void RasterizerOpenGL::CommitFramebuffer() { glActiveTexture(GL_TEXTURE0); glGetTexImage(GL_TEXTURE_2D, 0, fb_depth_texture.gl_format, fb_depth_texture.gl_type, ogl_img.get()); - for (int x = 0; x < fb_depth_texture.width; ++x) - { - for (int y = 0; y < fb_depth_texture.height; ++y) - { + for (int x = 0; x < fb_depth_texture.width; ++x) { + for (int y = 0; y < fb_depth_texture.height; ++y) { const u32 coarse_y = y & ~7; u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; u32 ogl_px_idx = x + y * fb_depth_texture.width; diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index d8bdb8de4..34f5ce4e1 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -22,7 +22,7 @@ void RasterizerCacheOpenGL::LoadAndBindTexture(OpenGLState &state, int texture_u state.texture_unit[texture_unit].texture_2d = cached_texture->second->texture.GetHandle(); state.Apply(); } else { - std::shared_ptr new_texture(new CachedTexture()); + std::unique_ptr new_texture(new CachedTexture()); new_texture->texture.Create(); state.texture_unit[texture_unit].texture_2d = new_texture->texture.GetHandle(); @@ -43,10 +43,8 @@ void RasterizerCacheOpenGL::LoadAndBindTexture(OpenGLState &state, int texture_u Math::Vec4* rgba_tex = new Math::Vec4[info.width * info.height]; - for (int i = 0; i < info.width; i++) - { - for (int j = 0; j < info.height; j++) - { + for (int i = 0; i < info.width; i++) { + for (int j = 0; j < info.height; j++) { rgba_tex[i + info.width * j] = Pica::DebugUtils::LookupTexture(Memory::GetPhysicalPointer(tex_paddr), i, info.height - 1 - j, info); } } @@ -55,7 +53,7 @@ void RasterizerCacheOpenGL::LoadAndBindTexture(OpenGLState &state, int texture_u delete[] rgba_tex; - texture_cache.emplace(tex_paddr, new_texture); + texture_cache.emplace(tex_paddr, std::move(new_texture)); } } diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index 652b41829..3c4a7e41e 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -32,5 +32,5 @@ private: u32 size; }; - std::map> texture_cache; + std::map> texture_cache; }; diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index b0c2258a9..e81a6c38f 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -6,8 +6,7 @@ OpenGLState OpenGLState::cur_state; -OpenGLState::OpenGLState() -{ +OpenGLState::OpenGLState() { // These all match default OpenGL values cull.enabled = false; cull.mode = GL_BACK; @@ -58,7 +57,7 @@ void OpenGLState::Apply() { glDisable(GL_CULL_FACE); } - //Depth test + // Depth test if (depth.test_enabled) { if (depth.test_enabled != cur_state.depth.test_enabled) { glEnable(GL_DEPTH_TEST); @@ -131,8 +130,7 @@ void OpenGLState::Apply() { glActiveTexture(GL_TEXTURE0 + i); glBindTexture(GL_TEXTURE_2D, texture_unit[i].texture_2d); } - } - else if (texture_unit[i].enabled_2d != cur_state.texture_unit[i].enabled_2d) { + } else if (texture_unit[i].enabled_2d != cur_state.texture_unit[i].enabled_2d) { glActiveTexture(GL_TEXTURE0 + i); glDisable(GL_TEXTURE_2D); } diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 18d3c7069..05c936879 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -53,14 +53,14 @@ static std::array MakeOrthographicMatrix(const float width, const /// RendererOpenGL constructor RendererOpenGL::RendererOpenGL() { - hw_rasterizer = new RasterizerOpenGL(); + hw_rasterizer.reset(new RasterizerOpenGL()); resolution_width = std::max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); resolution_height = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight; } /// RendererOpenGL destructor RendererOpenGL::~RendererOpenGL() { - delete hw_rasterizer; + } /// Swap buffers (render frame)