Style cleanup, pointer smartification

This commit is contained in:
tfarley 2015-05-11 16:00:40 -07:00
parent feaf460e1f
commit 73c6c6f03b
8 changed files with 34 additions and 56 deletions

View File

@ -50,7 +50,7 @@ public:
return m_current_frame; return m_current_frame;
} }
HWRasterizer *hw_rasterizer; std::unique_ptr<HWRasterizer> hw_rasterizer;
protected: protected:
f32 m_current_fps; ///< Current framerate, should be set by the renderer f32 m_current_fps; ///< Current framerate, should be set by the renderer

View File

@ -26,8 +26,7 @@ static GLenum WrapMode(Pica::Regs::TextureConfig::WrapMode mode) {
} }
} }
static GLenum BlendFunc(u32 factor) static GLenum BlendFunc(u32 factor) {
{
switch (factor) { switch (factor) {
case Pica::registers.output_merger.alpha_blending.Zero: case Pica::registers.output_merger.alpha_blending.Zero:
return GL_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) { switch (func) {
case Pica::registers.output_merger.Never: case Pica::registers.output_merger.Never:
return GL_NEVER; return GL_NEVER;

View File

@ -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_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_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(); state.stencil.test_mask = Pica::registers.output_merger.stencil_test.stencil_replacement_value.Value();
} } else {
else {
state.stencil.test_enabled = false; state.stencil.test_enabled = false;
} }
@ -484,8 +483,7 @@ void RasterizerOpenGL::SyncDrawState() {
if (texture.enabled) { if (texture.enabled) {
state.texture_unit[i].enabled_2d = true; state.texture_unit[i].enabled_2d = true;
res_cache.LoadAndBindTexture(state, i, texture); res_cache.LoadAndBindTexture(state, i, texture);
} } else {
else {
state.texture_unit[i].enabled_2d = false; state.texture_unit[i].enabled_2d = false;
} }
} }
@ -559,19 +557,17 @@ void RasterizerOpenGL::ReloadColorBuffer() {
u32 bytes_per_pixel = ColorFormatBytesPerPixel(fb_color_texture.format); 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<u8> 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 // 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 x = 0; x < fb_color_texture.width; ++x) {
{ for (int y = 0; y < fb_color_texture.height; ++y) {
for (int y = 0; y < fb_color_texture.height; ++y)
{
const u32 coarse_y = y & ~7; 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 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; u32 ogl_px_idx = x * bytes_per_pixel + y * fb_color_texture.width * bytes_per_pixel;
u8* pixel = color_buffer + dst_offset; 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(); state.Apply();
glActiveTexture(GL_TEXTURE0); 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); 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());
delete[] ogl_img;
} }
/// Copies the 3ds depth framebuffer into the OpenGL depth framebuffer texture /// 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 // OpenGL needs 4 bpp alignment for D24
u32 ogl_bpp = bytes_per_pixel == 3 ? 4 : bytes_per_pixel; 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<u8> 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 x = 0; x < fb_depth_texture.width; ++x) {
{ for (int y = 0; y < fb_depth_texture.height; ++y) {
for (int y = 0; y < fb_depth_texture.height; ++y)
{
const u32 coarse_y = y & ~7; 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 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; u32 ogl_px_idx = x + y * fb_depth_texture.width;
switch (fb_depth_texture.format) { switch (fb_depth_texture.format) {
case Pica::Regs::DepthFormat::D16: 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; break;
case Pica::Regs::DepthFormat::D24: 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; break;
case Pica::Regs::DepthFormat::D24S8: case Pica::Regs::DepthFormat::D24S8:
{ {
Math::Vec2<u32> depth_stencil = Color::DecodeD24S8(depth_buffer + dst_offset); Math::Vec2<u32> 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; break;
} }
default: default:
@ -635,9 +627,7 @@ void RasterizerOpenGL::ReloadDepthBuffer() {
state.Apply(); state.Apply();
glActiveTexture(GL_TEXTURE0); 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); 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());
delete[] ogl_img;
} }
/** /**
@ -646,8 +636,7 @@ void RasterizerOpenGL::ReloadDepthBuffer() {
* Then copies into the 3ds framebuffer using proper Morton order * Then copies into the 3ds framebuffer using proper Morton order
*/ */
void RasterizerOpenGL::CommitFramebuffer() { void RasterizerOpenGL::CommitFramebuffer() {
if (last_fb_color_addr != -1) if (last_fb_color_addr != -1) {
{
u8* color_buffer = Memory::GetPhysicalPointer(last_fb_color_addr); u8* color_buffer = Memory::GetPhysicalPointer(last_fb_color_addr);
if (color_buffer != nullptr) { if (color_buffer != nullptr) {
@ -662,10 +651,8 @@ void RasterizerOpenGL::CommitFramebuffer() {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glGetTexImage(GL_TEXTURE_2D, 0, fb_color_texture.gl_format, fb_color_texture.gl_type, ogl_img.get()); 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 x = 0; x < fb_color_texture.width; ++x) {
{ for (int y = 0; y < fb_color_texture.height; ++y) {
for (int y = 0; y < fb_color_texture.height; ++y)
{
const u32 coarse_y = y & ~7; 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 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; 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. // 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); u8* depth_buffer = Memory::GetPhysicalPointer(last_fb_depth_addr);
@ -697,10 +683,8 @@ void RasterizerOpenGL::CommitFramebuffer() {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glGetTexImage(GL_TEXTURE_2D, 0, fb_depth_texture.gl_format, fb_depth_texture.gl_type, ogl_img.get()); 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 x = 0; x < fb_depth_texture.width; ++x) {
{ for (int y = 0; y < fb_depth_texture.height; ++y) {
for (int y = 0; y < fb_depth_texture.height; ++y)
{
const u32 coarse_y = y & ~7; 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 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; u32 ogl_px_idx = x + y * fb_depth_texture.width;

View File

@ -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.texture_unit[texture_unit].texture_2d = cached_texture->second->texture.GetHandle();
state.Apply(); state.Apply();
} else { } else {
std::shared_ptr<CachedTexture> new_texture(new CachedTexture()); std::unique_ptr<CachedTexture> new_texture(new CachedTexture());
new_texture->texture.Create(); new_texture->texture.Create();
state.texture_unit[texture_unit].texture_2d = new_texture->texture.GetHandle(); 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<u8>* rgba_tex = new Math::Vec4<u8>[info.width * info.height]; Math::Vec4<u8>* rgba_tex = new Math::Vec4<u8>[info.width * info.height];
for (int i = 0; i < info.width; i++) for (int i = 0; i < info.width; i++) {
{ for (int j = 0; j < info.height; j++) {
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); 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; delete[] rgba_tex;
texture_cache.emplace(tex_paddr, new_texture); texture_cache.emplace(tex_paddr, std::move(new_texture));
} }
} }

View File

@ -32,5 +32,5 @@ private:
u32 size; u32 size;
}; };
std::map<u32, std::shared_ptr<CachedTexture>> texture_cache; std::map<u32, std::unique_ptr<CachedTexture>> texture_cache;
}; };

View File

@ -6,8 +6,7 @@
OpenGLState OpenGLState::cur_state; OpenGLState OpenGLState::cur_state;
OpenGLState::OpenGLState() OpenGLState::OpenGLState() {
{
// These all match default OpenGL values // These all match default OpenGL values
cull.enabled = false; cull.enabled = false;
cull.mode = GL_BACK; cull.mode = GL_BACK;
@ -58,7 +57,7 @@ void OpenGLState::Apply() {
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
} }
//Depth test // Depth test
if (depth.test_enabled) { if (depth.test_enabled) {
if (depth.test_enabled != cur_state.depth.test_enabled) { if (depth.test_enabled != cur_state.depth.test_enabled) {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -131,8 +130,7 @@ void OpenGLState::Apply() {
glActiveTexture(GL_TEXTURE0 + i); glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, texture_unit[i].texture_2d); 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); glActiveTexture(GL_TEXTURE0 + i);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} }

View File

@ -53,14 +53,14 @@ static std::array<GLfloat, 3*2> MakeOrthographicMatrix(const float width, const
/// RendererOpenGL constructor /// RendererOpenGL constructor
RendererOpenGL::RendererOpenGL() { RendererOpenGL::RendererOpenGL() {
hw_rasterizer = new RasterizerOpenGL(); hw_rasterizer.reset(new RasterizerOpenGL());
resolution_width = std::max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); resolution_width = std::max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth);
resolution_height = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight; resolution_height = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight;
} }
/// RendererOpenGL destructor /// RendererOpenGL destructor
RendererOpenGL::~RendererOpenGL() { RendererOpenGL::~RendererOpenGL() {
delete hw_rasterizer;
} }
/// Swap buffers (render frame) /// Swap buffers (render frame)