diff options
| author | 2014-04-07 00:57:37 -0400 | |
|---|---|---|
| committer | 2014-04-07 00:57:37 -0400 | |
| commit | f446f79da27d8c75b85772654152ea8e67a2214d (patch) | |
| tree | cf3924876405ed5244fc8ee72c8615cc74e51267 /src/video_core | |
| parent | Remove Core::GetState(). Use new ARM_Interface instead. (diff) | |
| parent | removed unused comments, changed main processing loop to be infinite (diff) | |
| download | yuzu-f446f79da27d8c75b85772654152ea8e67a2214d.tar.gz yuzu-f446f79da27d8c75b85772654152ea8e67a2214d.tar.xz yuzu-f446f79da27d8c75b85772654152ea8e67a2214d.zip | |
Merge branch 'hardware-interface'
Conflicts:
src/core/src/core.h
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 19 | ||||
| -rw-r--r-- | src/video_core/src/renderer_base.h | 132 | ||||
| -rw-r--r-- | src/video_core/src/renderer_opengl/renderer_opengl.cpp | 461 | ||||
| -rw-r--r-- | src/video_core/src/renderer_opengl/renderer_opengl.h | 153 | ||||
| -rw-r--r-- | src/video_core/src/utils.cpp | 66 | ||||
| -rw-r--r-- | src/video_core/src/utils.h | 83 | ||||
| -rw-r--r-- | src/video_core/src/video_core.cpp | 88 | ||||
| -rw-r--r-- | src/video_core/src/video_core.h | 59 | ||||
| -rw-r--r-- | src/video_core/video_core.vcxproj | 131 | ||||
| -rw-r--r-- | src/video_core/video_core.vcxproj.filters | 26 |
10 files changed, 1218 insertions, 0 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt new file mode 100644 index 000000000..3f486b8fe --- /dev/null +++ b/src/video_core/CMakeLists.txt | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | set(SRCS | ||
| 2 | src/bp_mem.cpp | ||
| 3 | src/cp_mem.cpp | ||
| 4 | src/xf_mem.cpp | ||
| 5 | src/fifo.cpp | ||
| 6 | src/fifo_player.cpp | ||
| 7 | src/vertex_loader.cpp | ||
| 8 | src/vertex_manager.cpp | ||
| 9 | src/video_core.cpp | ||
| 10 | src/shader_manager.cpp | ||
| 11 | src/texture_decoder.cpp | ||
| 12 | src/texture_manager.cpp | ||
| 13 | src/utils.cpp | ||
| 14 | src/renderer_gl3/renderer_gl3.cpp | ||
| 15 | src/renderer_gl3/shader_interface.cpp | ||
| 16 | src/renderer_gl3/texture_interface.cpp | ||
| 17 | src/renderer_gl3/uniform_manager.cpp) | ||
| 18 | |||
| 19 | add_library(video_core STATIC ${SRCS}) | ||
diff --git a/src/video_core/src/renderer_base.h b/src/video_core/src/renderer_base.h new file mode 100644 index 000000000..50f1475b2 --- /dev/null +++ b/src/video_core/src/renderer_base.h | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2014 Citra Emulator | ||
| 3 | * | ||
| 4 | * @file renderer_base.h | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-05 | ||
| 7 | * @brief Renderer base class for new video core | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include "common.h" | ||
| 28 | #include "hash.h" | ||
| 29 | |||
| 30 | class RendererBase { | ||
| 31 | public: | ||
| 32 | |||
| 33 | /// Used to reference a framebuffer | ||
| 34 | enum kFramebuffer { | ||
| 35 | kFramebuffer_VirtualXFB = 0, | ||
| 36 | kFramebuffer_EFB, | ||
| 37 | kFramebuffer_Texture | ||
| 38 | }; | ||
| 39 | |||
| 40 | /// Used for referencing the render modes | ||
| 41 | enum kRenderMode { | ||
| 42 | kRenderMode_None = 0, | ||
| 43 | kRenderMode_Multipass = 1, | ||
| 44 | kRenderMode_ZComp = 2, | ||
| 45 | kRenderMode_UseDstAlpha = 4 | ||
| 46 | }; | ||
| 47 | |||
| 48 | RendererBase() : current_fps_(0), current_frame_(0) { | ||
| 49 | } | ||
| 50 | |||
| 51 | ~RendererBase() { | ||
| 52 | } | ||
| 53 | |||
| 54 | /// Swap buffers (render frame) | ||
| 55 | virtual void SwapBuffers() = 0; | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Blits the EFB to the external framebuffer (XFB) | ||
| 59 | * @param src_rect Source rectangle in EFB to copy | ||
| 60 | * @param dst_rect Destination rectangle in EFB to copy to | ||
| 61 | * @param dest_height Destination height in pixels | ||
| 62 | */ | ||
| 63 | virtual void CopyToXFB(const Rect& src_rect, const Rect& dst_rect) = 0; | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Clear the screen | ||
| 67 | * @param rect Screen rectangle to clear | ||
| 68 | * @param enable_color Enable color clearing | ||
| 69 | * @param enable_alpha Enable alpha clearing | ||
| 70 | * @param enable_z Enable depth clearing | ||
| 71 | * @param color Clear color | ||
| 72 | * @param z Clear depth | ||
| 73 | */ | ||
| 74 | virtual void Clear(const Rect& rect, bool enable_color, bool enable_alpha, bool enable_z, | ||
| 75 | u32 color, u32 z) = 0; | ||
| 76 | |||
| 77 | /// Sets the renderer viewport location, width, and height | ||
| 78 | virtual void SetViewport(int x, int y, int width, int height) = 0; | ||
| 79 | |||
| 80 | /// Sets the renderer depthrange, znear and zfar | ||
| 81 | virtual void SetDepthRange(double znear, double zfar) = 0; | ||
| 82 | |||
| 83 | /* Sets the scissor box | ||
| 84 | * @param rect Renderer rectangle to set scissor box to | ||
| 85 | */ | ||
| 86 | virtual void SetScissorBox(const Rect& rect) = 0; | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Sets the line and point size | ||
| 90 | * @param line_width Line width to use | ||
| 91 | * @param point_size Point size to use | ||
| 92 | */ | ||
| 93 | virtual void SetLinePointSize(f32 line_width, f32 point_size) = 0; | ||
| 94 | |||
| 95 | /** | ||
| 96 | * Set a specific render mode | ||
| 97 | * @param flag Render flags mode to enable | ||
| 98 | */ | ||
| 99 | virtual void SetMode(kRenderMode flags) = 0; | ||
| 100 | |||
| 101 | /// Reset the full renderer API to the NULL state | ||
| 102 | virtual void ResetRenderState() = 0; | ||
| 103 | |||
| 104 | /// Restore the full renderer API state - As the game set it | ||
| 105 | virtual void RestoreRenderState() = 0; | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Set the emulator window to use for renderer | ||
| 109 | * @param window EmuWindow handle to emulator window to use for rendering | ||
| 110 | */ | ||
| 111 | virtual void SetWindow(EmuWindow* window) = 0; | ||
| 112 | |||
| 113 | /// Initialize the renderer | ||
| 114 | virtual void Init() = 0; | ||
| 115 | |||
| 116 | /// Shutdown the renderer | ||
| 117 | virtual void ShutDown() = 0; | ||
| 118 | |||
| 119 | // Getter/setter functions: | ||
| 120 | // ------------------------ | ||
| 121 | |||
| 122 | f32 current_fps() const { return current_fps_; } | ||
| 123 | |||
| 124 | int current_frame() const { return current_frame_; } | ||
| 125 | |||
| 126 | protected: | ||
| 127 | f32 current_fps_; ///< Current framerate, should be set by the renderer | ||
| 128 | int current_frame_; ///< Current frame, should be set by the renderer | ||
| 129 | |||
| 130 | private: | ||
| 131 | DISALLOW_COPY_AND_ASSIGN(RendererBase); | ||
| 132 | }; | ||
diff --git a/src/video_core/src/renderer_opengl/renderer_opengl.cpp b/src/video_core/src/renderer_opengl/renderer_opengl.cpp new file mode 100644 index 000000000..27917a5a2 --- /dev/null +++ b/src/video_core/src/renderer_opengl/renderer_opengl.cpp | |||
| @@ -0,0 +1,461 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2014 Citra Emulator | ||
| 3 | * | ||
| 4 | * @file renderer_opengl.cpp | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-05 | ||
| 7 | * @brief Renderer for OpenGL 3.x | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "mem_map.h" | ||
| 26 | #include "video_core.h" | ||
| 27 | #include "renderer_opengl/renderer_opengl.h" | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Helper function to flip framebuffer from left-to-right to top-to-bottom | ||
| 31 | * @param addr Address of framebuffer in RAM | ||
| 32 | * @param out Pointer to output buffer with flipped framebuffer | ||
| 33 | * @todo Early on hack... I'd like to find a more efficient way of doing this /bunnei | ||
| 34 | */ | ||
| 35 | inline void _flip_framebuffer(u32 addr, u8* out) { | ||
| 36 | u8* in = Memory::GetPointer(addr); | ||
| 37 | for (int y = 0; y < VideoCore::kScreenTopHeight; y++) { | ||
| 38 | for (int x = 0; x < VideoCore::kScreenTopWidth; x++) { | ||
| 39 | int in_coord = (VideoCore::kScreenTopHeight * 3 * x) + (VideoCore::kScreenTopHeight * 3) | ||
| 40 | - (3 * y + 3); | ||
| 41 | int out_coord = (VideoCore::kScreenTopWidth * y * 3) + (x * 3); | ||
| 42 | |||
| 43 | out[out_coord + 0] = in[in_coord + 0]; | ||
| 44 | out[out_coord + 1] = in[in_coord + 1]; | ||
| 45 | out[out_coord + 2] = in[in_coord + 2]; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | /// RendererOpenGL constructor | ||
| 51 | RendererOpenGL::RendererOpenGL() { | ||
| 52 | memset(fbo_, 0, sizeof(fbo_)); | ||
| 53 | memset(fbo_rbo_, 0, sizeof(fbo_rbo_)); | ||
| 54 | memset(fbo_depth_buffers_, 0, sizeof(fbo_depth_buffers_)); | ||
| 55 | |||
| 56 | resolution_width_ = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); | ||
| 57 | resolution_height_ = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight; | ||
| 58 | |||
| 59 | xfb_texture_top_ = 0; | ||
| 60 | xfb_texture_bottom_ = 0; | ||
| 61 | |||
| 62 | xfb_top_ = 0; | ||
| 63 | xfb_bottom_ = 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | /// RendererOpenGL destructor | ||
| 67 | RendererOpenGL::~RendererOpenGL() { | ||
| 68 | } | ||
| 69 | |||
| 70 | /// Swap buffers (render frame) | ||
| 71 | void RendererOpenGL::SwapBuffers() { | ||
| 72 | |||
| 73 | ResetRenderState(); | ||
| 74 | |||
| 75 | // EFB->XFB copy | ||
| 76 | // TODO(bunnei): This is a hack and does not belong here. The copy should be triggered by some | ||
| 77 | // register write We're also treating both framebuffers as a single one in OpenGL. | ||
| 78 | Rect framebuffer_size(0, 0, resolution_width_, resolution_height_); | ||
| 79 | RenderXFB(framebuffer_size, framebuffer_size); | ||
| 80 | |||
| 81 | // XFB->Window copy | ||
| 82 | RenderFramebuffer(); | ||
| 83 | |||
| 84 | // Swap buffers | ||
| 85 | render_window_->PollEvents(); | ||
| 86 | render_window_->SwapBuffers(); | ||
| 87 | |||
| 88 | // Switch back to EFB and clear | ||
| 89 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_EFB]); | ||
| 90 | |||
| 91 | RestoreRenderState(); | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Renders external framebuffer (XFB) | ||
| 96 | * @param src_rect Source rectangle in XFB to copy | ||
| 97 | * @param dst_rect Destination rectangle in output framebuffer to copy to | ||
| 98 | */ | ||
| 99 | void RendererOpenGL::RenderXFB(const Rect& src_rect, const Rect& dst_rect) { | ||
| 100 | static u8 xfb_top_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopWidth *3]; | ||
| 101 | static u8 xfb_bottom_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopWidth *3]; | ||
| 102 | |||
| 103 | _flip_framebuffer(0x20282160, xfb_top_flipped); | ||
| 104 | _flip_framebuffer(0x202118E0, xfb_bottom_flipped); | ||
| 105 | |||
| 106 | ResetRenderState(); | ||
| 107 | |||
| 108 | // Blit the top framebuffer | ||
| 109 | // ------------------------ | ||
| 110 | |||
| 111 | // Update textures with contents of XFB in RAM - top | ||
| 112 | glBindTexture(GL_TEXTURE_2D, xfb_texture_top_); | ||
| 113 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, | ||
| 114 | GL_RGB, GL_UNSIGNED_BYTE, xfb_top_flipped); | ||
| 115 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 116 | |||
| 117 | // Render target is destination framebuffer | ||
| 118 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]); | ||
| 119 | glViewport(0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight); | ||
| 120 | |||
| 121 | // Render source is our EFB | ||
| 122 | glBindFramebuffer(GL_READ_FRAMEBUFFER, xfb_top_); | ||
| 123 | glReadBuffer(GL_COLOR_ATTACHMENT0); | ||
| 124 | |||
| 125 | // Blit | ||
| 126 | glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_, | ||
| 127 | dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_, | ||
| 128 | GL_COLOR_BUFFER_BIT, GL_LINEAR); | ||
| 129 | |||
| 130 | glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | ||
| 131 | |||
| 132 | // Blit the bottom framebuffer | ||
| 133 | // --------------------------- | ||
| 134 | |||
| 135 | // Update textures with contents of XFB in RAM - bottom | ||
| 136 | glBindTexture(GL_TEXTURE_2D, xfb_texture_bottom_); | ||
| 137 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, | ||
| 138 | GL_RGB, GL_UNSIGNED_BYTE, xfb_bottom_flipped); | ||
| 139 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 140 | |||
| 141 | // Render target is destination framebuffer | ||
| 142 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]); | ||
| 143 | glViewport(0, 0, | ||
| 144 | VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight); | ||
| 145 | |||
| 146 | // Render source is our EFB | ||
| 147 | glBindFramebuffer(GL_READ_FRAMEBUFFER, xfb_bottom_); | ||
| 148 | glReadBuffer(GL_COLOR_ATTACHMENT0); | ||
| 149 | |||
| 150 | // Blit | ||
| 151 | int offset = (VideoCore::kScreenTopWidth - VideoCore::kScreenBottomWidth) / 2; | ||
| 152 | glBlitFramebuffer(0,0, VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight, | ||
| 153 | offset, VideoCore::kScreenBottomHeight, VideoCore::kScreenBottomWidth + offset, 0, | ||
| 154 | GL_COLOR_BUFFER_BIT, GL_LINEAR); | ||
| 155 | |||
| 156 | glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | ||
| 157 | |||
| 158 | RestoreRenderState(); | ||
| 159 | } | ||
| 160 | |||
| 161 | /** | ||
| 162 | * Blits the EFB to the external framebuffer (XFB) | ||
| 163 | * @param src_rect Source rectangle in EFB to copy | ||
| 164 | * @param dst_rect Destination rectangle in EFB to copy to | ||
| 165 | */ | ||
| 166 | void RendererOpenGL::CopyToXFB(const Rect& src_rect, const Rect& dst_rect) { | ||
| 167 | ERROR_LOG(RENDER, "CopyToXFB not implemented! No EFB support yet!"); | ||
| 168 | //ResetRenderState(); | ||
| 169 | |||
| 170 | //// Render target is destination framebuffer | ||
| 171 | //glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]); | ||
| 172 | //glViewport(0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight); | ||
| 173 | |||
| 174 | //// Render source is our EFB | ||
| 175 | //glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_[kFramebuffer_EFB]); | ||
| 176 | //glReadBuffer(GL_COLOR_ATTACHMENT0); | ||
| 177 | |||
| 178 | //// Blit | ||
| 179 | //glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_, | ||
| 180 | // dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_, | ||
| 181 | // GL_COLOR_BUFFER_BIT, GL_LINEAR); | ||
| 182 | |||
| 183 | //glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | ||
| 184 | |||
| 185 | //RestoreRenderState(); | ||
| 186 | } | ||
| 187 | |||
| 188 | /** | ||
| 189 | * Clear the screen | ||
| 190 | * @param rect Screen rectangle to clear | ||
| 191 | * @param enable_color Enable color clearing | ||
| 192 | * @param enable_alpha Enable alpha clearing | ||
| 193 | * @param enable_z Enable depth clearing | ||
| 194 | * @param color Clear color | ||
| 195 | * @param z Clear depth | ||
| 196 | */ | ||
| 197 | void RendererOpenGL::Clear(const Rect& rect, bool enable_color, bool enable_alpha, bool enable_z, | ||
| 198 | u32 color, u32 z) { | ||
| 199 | GLboolean const color_mask = enable_color ? GL_TRUE : GL_FALSE; | ||
| 200 | GLboolean const alpha_mask = enable_alpha ? GL_TRUE : GL_FALSE; | ||
| 201 | |||
| 202 | ResetRenderState(); | ||
| 203 | |||
| 204 | // Clear color | ||
| 205 | glColorMask(color_mask, color_mask, color_mask, alpha_mask); | ||
| 206 | glClearColor(float((color >> 16) & 0xFF) / 255.0f, float((color >> 8) & 0xFF) / 255.0f, | ||
| 207 | float((color >> 0) & 0xFF) / 255.0f, float((color >> 24) & 0xFF) / 255.0f); | ||
| 208 | |||
| 209 | // Clear depth | ||
| 210 | glDepthMask(enable_z ? GL_TRUE : GL_FALSE); | ||
| 211 | glClearDepth(float(z & 0xFFFFFF) / float(0xFFFFFF)); | ||
| 212 | |||
| 213 | // Specify the rectangle of the EFB to clear | ||
| 214 | glEnable(GL_SCISSOR_TEST); | ||
| 215 | glScissor(rect.x0_, rect.y1_, rect.width(), rect.height()); | ||
| 216 | |||
| 217 | // Clear it! | ||
| 218 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
| 219 | |||
| 220 | RestoreRenderState(); | ||
| 221 | } | ||
| 222 | |||
| 223 | /// Sets the renderer viewport location, width, and height | ||
| 224 | void RendererOpenGL::SetViewport(int x, int y, int width, int height) { | ||
| 225 | glViewport(x, y, width, height); | ||
| 226 | } | ||
| 227 | |||
| 228 | /// Sets the renderer depthrange, znear and zfar | ||
| 229 | void RendererOpenGL::SetDepthRange(double znear, double zfar) { | ||
| 230 | glDepthRange(znear, zfar); | ||
| 231 | } | ||
| 232 | |||
| 233 | /* Sets the scissor box | ||
| 234 | * @param rect Renderer rectangle to set scissor box to | ||
| 235 | */ | ||
| 236 | void RendererOpenGL::SetScissorBox(const Rect& rect) { | ||
| 237 | glScissor(rect.x0_, rect.y1_, rect.width(), rect.height()); | ||
| 238 | } | ||
| 239 | |||
| 240 | /** | ||
| 241 | * Sets the line and point size | ||
| 242 | * @param line_width Line width to use | ||
| 243 | * @param point_size Point size to use | ||
| 244 | */ | ||
| 245 | void RendererOpenGL::SetLinePointSize(f32 line_width, f32 point_size) { | ||
| 246 | glLineWidth((GLfloat)line_width); | ||
| 247 | glPointSize((GLfloat)point_size); | ||
| 248 | } | ||
| 249 | |||
| 250 | /** | ||
| 251 | * Set a specific render mode | ||
| 252 | * @param flag Render flags mode to enable | ||
| 253 | */ | ||
| 254 | void RendererOpenGL::SetMode(kRenderMode flags) { | ||
| 255 | if(flags & kRenderMode_ZComp) { | ||
| 256 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | ||
| 257 | } | ||
| 258 | if(flags & kRenderMode_Multipass) { | ||
| 259 | glEnable(GL_DEPTH_TEST); | ||
| 260 | glDepthMask(GL_FALSE); | ||
| 261 | glDepthFunc(GL_EQUAL); | ||
| 262 | } | ||
| 263 | if (flags & kRenderMode_UseDstAlpha) { | ||
| 264 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); | ||
| 265 | glDisable(GL_BLEND); | ||
| 266 | } | ||
| 267 | last_mode_ |= flags; | ||
| 268 | } | ||
| 269 | |||
| 270 | /// Reset the full renderer API to the NULL state | ||
| 271 | void RendererOpenGL::ResetRenderState() { | ||
| 272 | glDisable(GL_SCISSOR_TEST); | ||
| 273 | glDisable(GL_DEPTH_TEST); | ||
| 274 | glDisable(GL_CULL_FACE); | ||
| 275 | glDisable(GL_BLEND); | ||
| 276 | glDepthMask(GL_FALSE); | ||
| 277 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | ||
| 278 | } | ||
| 279 | |||
| 280 | /// Restore the full renderer API state - As the game set it | ||
| 281 | void RendererOpenGL::RestoreRenderState() { | ||
| 282 | |||
| 283 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_EFB]); | ||
| 284 | |||
| 285 | //gp::XF_UpdateViewport(); | ||
| 286 | SetViewport(0, 0, resolution_width_, resolution_height_); | ||
| 287 | SetDepthRange(0.0f, 1.0f); | ||
| 288 | |||
| 289 | //SetGenerationMode(); | ||
| 290 | glEnable(GL_CULL_FACE); | ||
| 291 | glFrontFace(GL_CCW); | ||
| 292 | |||
| 293 | //glEnable(GL_SCISSOR_TEST); | ||
| 294 | //gp::BP_SetScissorBox(); | ||
| 295 | glDisable(GL_SCISSOR_TEST); | ||
| 296 | |||
| 297 | //SetColorMask(gp::g_bp_regs.cmode0); | ||
| 298 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | ||
| 299 | |||
| 300 | //SetDepthMode(); | ||
| 301 | glDisable(GL_DEPTH_TEST); | ||
| 302 | glDepthMask(GL_FALSE); | ||
| 303 | |||
| 304 | //SetBlendMode(gp::g_bp_regs.cmode0, gp::g_bp_regs.cmode1, true); | ||
| 305 | //if (common::g_config->current_renderer_config().enable_wireframe) { | ||
| 306 | // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | ||
| 307 | //} else { | ||
| 308 | // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | ||
| 309 | //} | ||
| 310 | } | ||
| 311 | |||
| 312 | /// Initialize the FBO | ||
| 313 | void RendererOpenGL::InitFramebuffer() { | ||
| 314 | // TODO(en): This should probably be implemented with the top screen and bottom screen as | ||
| 315 | // separate framebuffers | ||
| 316 | |||
| 317 | // Init the FBOs | ||
| 318 | // ------------- | ||
| 319 | |||
| 320 | glGenFramebuffers(kMaxFramebuffers, fbo_); // Generate primary framebuffer | ||
| 321 | glGenRenderbuffers(kMaxFramebuffers, fbo_rbo_); // Generate primary RBOs | ||
| 322 | glGenRenderbuffers(kMaxFramebuffers, fbo_depth_buffers_); // Generate primary depth buffer | ||
| 323 | |||
| 324 | for (int i = 0; i < kMaxFramebuffers; i++) { | ||
| 325 | // Generate color buffer storage | ||
| 326 | glBindRenderbuffer(GL_RENDERBUFFER, fbo_rbo_[i]); | ||
| 327 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, VideoCore::kScreenTopWidth, | ||
| 328 | VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); | ||
| 329 | |||
| 330 | // Generate depth buffer storage | ||
| 331 | glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_buffers_[i]); | ||
| 332 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, VideoCore::kScreenTopWidth, | ||
| 333 | VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); | ||
| 334 | |||
| 335 | // Attach the buffers | ||
| 336 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[i]); | ||
| 337 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | ||
| 338 | GL_RENDERBUFFER, fbo_depth_buffers_[i]); | ||
| 339 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | ||
| 340 | GL_RENDERBUFFER, fbo_rbo_[i]); | ||
| 341 | |||
| 342 | // Check for completeness | ||
| 343 | if (GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)) { | ||
| 344 | NOTICE_LOG(RENDER, "framebuffer(%d) initialized ok", i); | ||
| 345 | } else { | ||
| 346 | ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer"); | ||
| 347 | exit(1); | ||
| 348 | } | ||
| 349 | } | ||
| 350 | glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s) | ||
| 351 | |||
| 352 | // Initialize framebuffer textures | ||
| 353 | // ------------------------------- | ||
| 354 | |||
| 355 | // Create XFB textures | ||
| 356 | glGenTextures(1, &xfb_texture_top_); | ||
| 357 | glGenTextures(1, &xfb_texture_bottom_); | ||
| 358 | |||
| 359 | // Alocate video memorry for XFB textures | ||
| 360 | glBindTexture(GL_TEXTURE_2D, xfb_texture_top_); | ||
| 361 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, | ||
| 362 | 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); | ||
| 363 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 364 | |||
| 365 | glBindTexture(GL_TEXTURE_2D, xfb_texture_bottom_); | ||
| 366 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, | ||
| 367 | 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); | ||
| 368 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 369 | |||
| 370 | // Create the FBO and attach color/depth textures | ||
| 371 | glGenFramebuffers(1, &xfb_top_); // Generate framebuffer | ||
| 372 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, xfb_top_); | ||
| 373 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | ||
| 374 | xfb_texture_top_, 0); | ||
| 375 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
| 376 | |||
| 377 | glGenFramebuffers(1, &xfb_bottom_); // Generate framebuffer | ||
| 378 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, xfb_bottom_); | ||
| 379 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | ||
| 380 | xfb_texture_bottom_, 0); | ||
| 381 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
| 382 | } | ||
| 383 | |||
| 384 | /// Blit the FBO to the OpenGL default framebuffer | ||
| 385 | void RendererOpenGL::RenderFramebuffer() { | ||
| 386 | |||
| 387 | // Render target is default framebuffer | ||
| 388 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); | ||
| 389 | glViewport(0, 0, resolution_width_, resolution_height_); | ||
| 390 | |||
| 391 | // Render source is our XFB | ||
| 392 | glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]); | ||
| 393 | glReadBuffer(GL_COLOR_ATTACHMENT0); | ||
| 394 | |||
| 395 | // Blit | ||
| 396 | glBlitFramebuffer(0, 0, resolution_width_, resolution_height_, 0, 0, | ||
| 397 | resolution_width_, resolution_height_, GL_COLOR_BUFFER_BIT, GL_LINEAR); | ||
| 398 | |||
| 399 | // Update the FPS count | ||
| 400 | UpdateFramerate(); | ||
| 401 | |||
| 402 | // Rebind EFB | ||
| 403 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_EFB]); | ||
| 404 | |||
| 405 | current_frame_++; | ||
| 406 | } | ||
| 407 | |||
| 408 | /// Updates the framerate | ||
| 409 | void RendererOpenGL::UpdateFramerate() { | ||
| 410 | } | ||
| 411 | |||
| 412 | /** | ||
| 413 | * Set the emulator window to use for renderer | ||
| 414 | * @param window EmuWindow handle to emulator window to use for rendering | ||
| 415 | */ | ||
| 416 | void RendererOpenGL::SetWindow(EmuWindow* window) { | ||
| 417 | render_window_ = window; | ||
| 418 | } | ||
| 419 | |||
| 420 | /// Initialize the renderer | ||
| 421 | void RendererOpenGL::Init() { | ||
| 422 | render_window_->MakeCurrent(); | ||
| 423 | glShadeModel(GL_SMOOTH); | ||
| 424 | |||
| 425 | |||
| 426 | glStencilFunc(GL_ALWAYS, 0, 0); | ||
| 427 | glBlendFunc(GL_ONE, GL_ONE); | ||
| 428 | |||
| 429 | glViewport(0, 0, resolution_width_, resolution_height_); | ||
| 430 | |||
| 431 | glClearDepth(1.0f); | ||
| 432 | glEnable(GL_DEPTH_TEST); | ||
| 433 | glDisable(GL_LIGHTING); | ||
| 434 | glDepthFunc(GL_LEQUAL); | ||
| 435 | |||
| 436 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); | ||
| 437 | |||
| 438 | glDisable(GL_STENCIL_TEST); | ||
| 439 | glEnable(GL_SCISSOR_TEST); | ||
| 440 | |||
| 441 | glScissor(0, 0, resolution_width_, resolution_height_); | ||
| 442 | glClearDepth(1.0f); | ||
| 443 | |||
| 444 | GLenum err = glewInit(); | ||
| 445 | if (GLEW_OK != err) { | ||
| 446 | ERROR_LOG(RENDER, " Failed to initialize GLEW! Error message: \"%s\". Exiting...", | ||
| 447 | glewGetErrorString(err)); | ||
| 448 | exit(-1); | ||
| 449 | } | ||
| 450 | |||
| 451 | // Initialize everything else | ||
| 452 | // -------------------------- | ||
| 453 | |||
| 454 | InitFramebuffer(); | ||
| 455 | |||
| 456 | NOTICE_LOG(RENDER, "GL_VERSION: %s\n", glGetString(GL_VERSION)); | ||
| 457 | } | ||
| 458 | |||
| 459 | /// Shutdown the renderer | ||
| 460 | void RendererOpenGL::ShutDown() { | ||
| 461 | } | ||
diff --git a/src/video_core/src/renderer_opengl/renderer_opengl.h b/src/video_core/src/renderer_opengl/renderer_opengl.h new file mode 100644 index 000000000..b84afc5d2 --- /dev/null +++ b/src/video_core/src/renderer_opengl/renderer_opengl.h | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2014 Citra Emulator | ||
| 3 | * | ||
| 4 | * @file renderer_opengl.h | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-05 | ||
| 7 | * @brief Renderer for OpenGL 3.x | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include <GL/glew.h> | ||
| 28 | |||
| 29 | |||
| 30 | #include "common.h" | ||
| 31 | #include "emu_window.h" | ||
| 32 | |||
| 33 | #include "renderer_base.h" | ||
| 34 | |||
| 35 | |||
| 36 | class RendererOpenGL : virtual public RendererBase { | ||
| 37 | public: | ||
| 38 | |||
| 39 | static const int kMaxFramebuffers = 2; ///< Maximum number of framebuffers | ||
| 40 | |||
| 41 | RendererOpenGL(); | ||
| 42 | ~RendererOpenGL(); | ||
| 43 | |||
| 44 | /// Swap buffers (render frame) | ||
| 45 | void SwapBuffers(); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Renders external framebuffer (XFB) | ||
| 49 | * @param src_rect Source rectangle in XFB to copy | ||
| 50 | * @param dst_rect Destination rectangle in output framebuffer to copy to | ||
| 51 | */ | ||
| 52 | void RenderXFB(const Rect& src_rect, const Rect& dst_rect); | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Blits the EFB to the external framebuffer (XFB) | ||
| 56 | * @param src_rect Source rectangle in EFB to copy | ||
| 57 | * @param dst_rect Destination rectangle in EFB to copy to | ||
| 58 | */ | ||
| 59 | void CopyToXFB(const Rect& src_rect, const Rect& dst_rect); | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Clear the screen | ||
| 63 | * @param rect Screen rectangle to clear | ||
| 64 | * @param enable_color Enable color clearing | ||
| 65 | * @param enable_alpha Enable alpha clearing | ||
| 66 | * @param enable_z Enable depth clearing | ||
| 67 | * @param color Clear color | ||
| 68 | * @param z Clear depth | ||
| 69 | */ | ||
| 70 | void Clear(const Rect& rect, bool enable_color, bool enable_alpha, bool enable_z, | ||
| 71 | u32 color, u32 z); | ||
| 72 | |||
| 73 | /// Sets the renderer viewport location, width, and height | ||
| 74 | void SetViewport(int x, int y, int width, int height); | ||
| 75 | |||
| 76 | /// Sets the renderer depthrange, znear and zfar | ||
| 77 | void SetDepthRange(double znear, double zfar); | ||
| 78 | |||
| 79 | /* Sets the scissor box | ||
| 80 | * @param rect Renderer rectangle to set scissor box to | ||
| 81 | */ | ||
| 82 | void SetScissorBox(const Rect& rect); | ||
| 83 | |||
| 84 | /** | ||
| 85 | * Sets the line and point size | ||
| 86 | * @param line_width Line width to use | ||
| 87 | * @param point_size Point size to use | ||
| 88 | */ | ||
| 89 | void SetLinePointSize(f32 line_width, f32 point_size); | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Set a specific render mode | ||
| 93 | * @param flag Render flags mode to enable | ||
| 94 | */ | ||
| 95 | void SetMode(kRenderMode flags); | ||
| 96 | |||
| 97 | /// Reset the full renderer API to the NULL state | ||
| 98 | void ResetRenderState(); | ||
| 99 | |||
| 100 | /// Restore the full renderer API state - As the game set it | ||
| 101 | void RestoreRenderState(); | ||
| 102 | |||
| 103 | /** | ||
| 104 | * Set the emulator window to use for renderer | ||
| 105 | * @param window EmuWindow handle to emulator window to use for rendering | ||
| 106 | */ | ||
| 107 | void SetWindow(EmuWindow* window); | ||
| 108 | |||
| 109 | /// Initialize the renderer | ||
| 110 | void Init(); | ||
| 111 | |||
| 112 | /// Shutdown the renderer | ||
| 113 | void ShutDown(); | ||
| 114 | |||
| 115 | // Framebuffer object(s) | ||
| 116 | // --------------------- | ||
| 117 | |||
| 118 | GLuint fbo_[kMaxFramebuffers]; ///< Framebuffer objects | ||
| 119 | |||
| 120 | private: | ||
| 121 | |||
| 122 | /// Initialize the FBO | ||
| 123 | void InitFramebuffer(); | ||
| 124 | |||
| 125 | // Blit the FBO to the OpenGL default framebuffer | ||
| 126 | void RenderFramebuffer(); | ||
| 127 | |||
| 128 | /// Updates the framerate | ||
| 129 | void UpdateFramerate(); | ||
| 130 | |||
| 131 | EmuWindow* render_window_; | ||
| 132 | u32 last_mode_; ///< Last render mode | ||
| 133 | |||
| 134 | int resolution_width_; | ||
| 135 | int resolution_height_; | ||
| 136 | |||
| 137 | // Render buffers | ||
| 138 | // -------------- | ||
| 139 | |||
| 140 | GLuint fbo_rbo_[kMaxFramebuffers]; ///< Render buffer objects | ||
| 141 | GLuint fbo_depth_buffers_[kMaxFramebuffers]; ///< Depth buffers objects | ||
| 142 | |||
| 143 | // External framebuffers | ||
| 144 | // --------------------- | ||
| 145 | |||
| 146 | GLuint xfb_texture_top_; ///< GL handle to top framebuffer texture | ||
| 147 | GLuint xfb_texture_bottom_; ///< GL handle to bottom framebuffer texture | ||
| 148 | |||
| 149 | GLuint xfb_top_; | ||
| 150 | GLuint xfb_bottom_; | ||
| 151 | |||
| 152 | DISALLOW_COPY_AND_ASSIGN(RendererOpenGL); | ||
| 153 | }; \ No newline at end of file | ||
diff --git a/src/video_core/src/utils.cpp b/src/video_core/src/utils.cpp new file mode 100644 index 000000000..a5e702f67 --- /dev/null +++ b/src/video_core/src/utils.cpp | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2005-2012 Gekko Emulator | ||
| 3 | * | ||
| 4 | * @file utils.cpp | ||
| 5 | * @author ShizZy <shizzy247@gmail.com> | ||
| 6 | * @date 2012-12-28 | ||
| 7 | * @brief Utility functions (in general, not related to emulation) useful for video core | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <stdio.h> | ||
| 26 | #include <string.h> | ||
| 27 | |||
| 28 | #include "utils.h" | ||
| 29 | |||
| 30 | namespace VideoCore { | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Dumps a texture to TGA | ||
| 34 | * @param filename String filename to dump texture to | ||
| 35 | * @param width Width of texture in pixels | ||
| 36 | * @param height Height of texture in pixels | ||
| 37 | * @param raw_data Raw RGBA8 texture data to dump | ||
| 38 | * @todo This should be moved to some general purpose/common code | ||
| 39 | */ | ||
| 40 | void DumpTGA(std::string filename, int width, int height, u8* raw_data) { | ||
| 41 | TGAHeader hdr; | ||
| 42 | FILE* fout; | ||
| 43 | u8 r, g, b; | ||
| 44 | |||
| 45 | memset(&hdr, 0, sizeof(hdr)); | ||
| 46 | hdr.datatypecode = 2; // uncompressed RGB | ||
| 47 | hdr.bitsperpixel = 24; // 24 bpp | ||
| 48 | hdr.width = width; | ||
| 49 | hdr.height = height; | ||
| 50 | |||
| 51 | fout = fopen(filename.c_str(), "wb"); | ||
| 52 | fwrite(&hdr, sizeof(TGAHeader), 1, fout); | ||
| 53 | for (int i = 0; i < height; i++) { | ||
| 54 | for (int j = 0; j < width; j++) { | ||
| 55 | r = raw_data[(4 * (i * width)) + (4 * j) + 0]; | ||
| 56 | g = raw_data[(4 * (i * width)) + (4 * j) + 1]; | ||
| 57 | b = raw_data[(4 * (i * width)) + (4 * j) + 2]; | ||
| 58 | putc(b, fout); | ||
| 59 | putc(g, fout); | ||
| 60 | putc(r, fout); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | fclose(fout); | ||
| 64 | } | ||
| 65 | |||
| 66 | } // namespace | ||
diff --git a/src/video_core/src/utils.h b/src/video_core/src/utils.h new file mode 100644 index 000000000..2d7fa4a3a --- /dev/null +++ b/src/video_core/src/utils.h | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2005-2012 Gekko Emulator | ||
| 3 | * | ||
| 4 | * @file utils.h | ||
| 5 | * @author ShizZy <shizzy247@gmail.com> | ||
| 6 | * @date 2012-12-28 | ||
| 7 | * @brief Utility functions (in general, not related to emulation) useful for video core | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include "common_types.h" | ||
| 28 | #include <string> | ||
| 29 | |||
| 30 | namespace FormatPrecision { | ||
| 31 | |||
| 32 | /// Adjust RGBA8 color with RGBA6 precision | ||
| 33 | static inline u32 rgba8_with_rgba6(u32 src) { | ||
| 34 | u32 color = src; | ||
| 35 | color &= 0xFCFCFCFC; | ||
| 36 | color |= (color >> 6) & 0x03030303; | ||
| 37 | return color; | ||
| 38 | } | ||
| 39 | |||
| 40 | /// Adjust RGBA8 color with RGB565 precision | ||
| 41 | static inline u32 rgba8_with_rgb565(u32 src) { | ||
| 42 | u32 color = (src & 0xF8FCF8); | ||
| 43 | color |= (color >> 5) & 0x070007; | ||
| 44 | color |= (color >> 6) & 0x000300; | ||
| 45 | color |= 0xFF000000; | ||
| 46 | return color; | ||
| 47 | } | ||
| 48 | |||
| 49 | /// Adjust Z24 depth value with Z16 precision | ||
| 50 | static inline u32 z24_with_z16(u32 src) { | ||
| 51 | return (src & 0xFFFF00) | (src >> 16); | ||
| 52 | } | ||
| 53 | |||
| 54 | } // namespace | ||
| 55 | |||
| 56 | namespace VideoCore { | ||
| 57 | |||
| 58 | /// Structure for the TGA texture format (for dumping) | ||
| 59 | struct TGAHeader { | ||
| 60 | char idlength; | ||
| 61 | char colourmaptype; | ||
| 62 | char datatypecode; | ||
| 63 | short int colourmaporigin; | ||
| 64 | short int colourmaplength; | ||
| 65 | short int x_origin; | ||
| 66 | short int y_origin; | ||
| 67 | short width; | ||
| 68 | short height; | ||
| 69 | char bitsperpixel; | ||
| 70 | char imagedescriptor; | ||
| 71 | }; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Dumps a texture to TGA | ||
| 75 | * @param filename String filename to dump texture to | ||
| 76 | * @param width Width of texture in pixels | ||
| 77 | * @param height Height of texture in pixels | ||
| 78 | * @param raw_data Raw RGBA8 texture data to dump | ||
| 79 | * @todo This should be moved to some general purpose/common code | ||
| 80 | */ | ||
| 81 | void DumpTGA(std::string filename, int width, int height, u8* raw_data); | ||
| 82 | |||
| 83 | } // namespace | ||
diff --git a/src/video_core/src/video_core.cpp b/src/video_core/src/video_core.cpp new file mode 100644 index 000000000..52ff90488 --- /dev/null +++ b/src/video_core/src/video_core.cpp | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2014 Citra Emulator | ||
| 3 | * | ||
| 4 | * @file video_core.cpp | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-05 | ||
| 7 | * @brief Main module for new video core | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "common.h" | ||
| 26 | #include "emu_window.h" | ||
| 27 | #include "log.h" | ||
| 28 | |||
| 29 | #include "core.h" | ||
| 30 | |||
| 31 | #include "video_core.h" | ||
| 32 | #include "renderer_base.h" | ||
| 33 | #include "renderer_opengl/renderer_opengl.h" | ||
| 34 | |||
| 35 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 36 | // Video Core namespace | ||
| 37 | |||
| 38 | namespace VideoCore { | ||
| 39 | |||
| 40 | EmuWindow* g_emu_window = NULL; ///< Frontend emulator window | ||
| 41 | RendererBase* g_renderer = NULL; ///< Renderer plugin | ||
| 42 | int g_current_frame = 0; | ||
| 43 | |||
| 44 | int VideoEntry(void*) { | ||
| 45 | if (g_emu_window == NULL) { | ||
| 46 | ERROR_LOG(VIDEO, "VideoCore::VideoEntry called without calling Init()!"); | ||
| 47 | } | ||
| 48 | g_emu_window->MakeCurrent(); | ||
| 49 | //for(;;) { | ||
| 50 | // gp::Fifo_DecodeCommand(); | ||
| 51 | //} | ||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | /// Start the video core | ||
| 56 | void Start() { | ||
| 57 | if (g_emu_window == NULL) { | ||
| 58 | ERROR_LOG(VIDEO, "VideoCore::Start called without calling Init()!"); | ||
| 59 | } | ||
| 60 | //if (common::g_config->enable_multicore()) { | ||
| 61 | // g_emu_window->DoneCurrent(); | ||
| 62 | // g_video_thread = SDL_CreateThread(VideoEntry, NULL, NULL); | ||
| 63 | // if (g_video_thread == NULL) { | ||
| 64 | // LOG_ERROR(TVIDEO, "Unable to create thread: %s... Exiting\n", SDL_GetError()); | ||
| 65 | // exit(1); | ||
| 66 | // } | ||
| 67 | //} | ||
| 68 | } | ||
| 69 | |||
| 70 | /// Initialize the video core | ||
| 71 | void Init(EmuWindow* emu_window) { | ||
| 72 | g_emu_window = emu_window; | ||
| 73 | g_emu_window->MakeCurrent(); | ||
| 74 | g_renderer = new RendererOpenGL(); | ||
| 75 | g_renderer->SetWindow(g_emu_window); | ||
| 76 | g_renderer->Init(); | ||
| 77 | |||
| 78 | g_current_frame = 0; | ||
| 79 | |||
| 80 | NOTICE_LOG(VIDEO, "initialized ok"); | ||
| 81 | } | ||
| 82 | |||
| 83 | /// Shutdown the video core | ||
| 84 | void Shutdown() { | ||
| 85 | delete g_renderer; | ||
| 86 | } | ||
| 87 | |||
| 88 | } // namespace | ||
diff --git a/src/video_core/src/video_core.h b/src/video_core/src/video_core.h new file mode 100644 index 000000000..10b8f1105 --- /dev/null +++ b/src/video_core/src/video_core.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /*! | ||
| 2 | * Copyright (C) 2014 Citra Emulator | ||
| 3 | * | ||
| 4 | * @file video_core.h | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-05 | ||
| 7 | * @brief Main module for new video core | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include "common.h" | ||
| 28 | #include "emu_window.h" | ||
| 29 | #include "renderer_base.h" | ||
| 30 | |||
| 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 32 | // Video Core namespace | ||
| 33 | |||
| 34 | namespace VideoCore { | ||
| 35 | |||
| 36 | // 3DS Video Constants | ||
| 37 | // ------------------- | ||
| 38 | |||
| 39 | static const int kScreenTopWidth = 400; ///< 3DS top screen width | ||
| 40 | static const int kScreenTopHeight = 240; ///< 3DS top screen height | ||
| 41 | static const int kScreenBottomWidth = 320; ///< 3DS bottom screen width | ||
| 42 | static const int kScreenBottomHeight = 240; ///< 3DS bottom screen height | ||
| 43 | |||
| 44 | // Video core renderer | ||
| 45 | // --------------------- | ||
| 46 | |||
| 47 | extern RendererBase* g_renderer; ///< Renderer plugin | ||
| 48 | extern int g_current_frame; ///< Current frame | ||
| 49 | |||
| 50 | /// Start the video core | ||
| 51 | void Start(); | ||
| 52 | |||
| 53 | /// Initialize the video core | ||
| 54 | void Init(EmuWindow* emu_window); | ||
| 55 | |||
| 56 | /// Shutdown the video core | ||
| 57 | void Shutdown(); | ||
| 58 | |||
| 59 | } // namespace | ||
diff --git a/src/video_core/video_core.vcxproj b/src/video_core/video_core.vcxproj new file mode 100644 index 000000000..5c56e9b71 --- /dev/null +++ b/src/video_core/video_core.vcxproj | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| 3 | <ItemGroup Label="ProjectConfigurations"> | ||
| 4 | <ProjectConfiguration Include="Debug|Win32"> | ||
| 5 | <Configuration>Debug</Configuration> | ||
| 6 | <Platform>Win32</Platform> | ||
| 7 | </ProjectConfiguration> | ||
| 8 | <ProjectConfiguration Include="Debug|x64"> | ||
| 9 | <Configuration>Debug</Configuration> | ||
| 10 | <Platform>x64</Platform> | ||
| 11 | </ProjectConfiguration> | ||
| 12 | <ProjectConfiguration Include="Release|Win32"> | ||
| 13 | <Configuration>Release</Configuration> | ||
| 14 | <Platform>Win32</Platform> | ||
| 15 | </ProjectConfiguration> | ||
| 16 | <ProjectConfiguration Include="Release|x64"> | ||
| 17 | <Configuration>Release</Configuration> | ||
| 18 | <Platform>x64</Platform> | ||
| 19 | </ProjectConfiguration> | ||
| 20 | </ItemGroup> | ||
| 21 | <ItemGroup> | ||
| 22 | <ClCompile Include="src\renderer_opengl\renderer_opengl.cpp" /> | ||
| 23 | <ClCompile Include="src\utils.cpp" /> | ||
| 24 | <ClCompile Include="src\video_core.cpp" /> | ||
| 25 | </ItemGroup> | ||
| 26 | <ItemGroup> | ||
| 27 | <ClInclude Include="src\renderer_base.h" /> | ||
| 28 | <ClInclude Include="src\renderer_opengl\renderer_opengl.h" /> | ||
| 29 | <ClInclude Include="src\utils.h" /> | ||
| 30 | <ClInclude Include="src\video_core.h" /> | ||
| 31 | </ItemGroup> | ||
| 32 | <ItemGroup> | ||
| 33 | <Text Include="CMakeLists.txt" /> | ||
| 34 | </ItemGroup> | ||
| 35 | <PropertyGroup Label="Globals"> | ||
| 36 | <ProjectGuid>{6678D1A3-33A6-48A9-878B-48E5D2903D27}</ProjectGuid> | ||
| 37 | <RootNamespace>input_common</RootNamespace> | ||
| 38 | <ProjectName>video_core</ProjectName> | ||
| 39 | </PropertyGroup> | ||
| 40 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
| 41 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
| 42 | <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| 43 | <UseDebugLibraries>true</UseDebugLibraries> | ||
| 44 | <PlatformToolset>v120</PlatformToolset> | ||
| 45 | </PropertyGroup> | ||
| 46 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
| 47 | <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| 48 | <UseDebugLibraries>true</UseDebugLibraries> | ||
| 49 | <PlatformToolset>v120</PlatformToolset> | ||
| 50 | </PropertyGroup> | ||
| 51 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
| 52 | <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| 53 | <UseDebugLibraries>false</UseDebugLibraries> | ||
| 54 | <PlatformToolset>v120</PlatformToolset> | ||
| 55 | </PropertyGroup> | ||
| 56 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
| 57 | <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| 58 | <UseDebugLibraries>false</UseDebugLibraries> | ||
| 59 | <PlatformToolset>v120</PlatformToolset> | ||
| 60 | </PropertyGroup> | ||
| 61 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
| 62 | <ImportGroup Label="ExtensionSettings"> | ||
| 63 | </ImportGroup> | ||
| 64 | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| 65 | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| 66 | <Import Project="..\..\vsprops\Base.props" /> | ||
| 67 | <Import Project="..\..\vsprops\code_generation_debug.props" /> | ||
| 68 | <Import Project="..\..\vsprops\optimization_debug.props" /> | ||
| 69 | <Import Project="..\..\vsprops\externals.props" /> | ||
| 70 | </ImportGroup> | ||
| 71 | <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> | ||
| 72 | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| 73 | <Import Project="..\..\vsprops\Base.props" /> | ||
| 74 | <Import Project="..\..\vsprops\code_generation_debug.props" /> | ||
| 75 | <Import Project="..\..\vsprops\optimization_debug.props" /> | ||
| 76 | <Import Project="..\..\vsprops\externals.props" /> | ||
| 77 | </ImportGroup> | ||
| 78 | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| 79 | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| 80 | <Import Project="..\..\vsprops\Base.props" /> | ||
| 81 | <Import Project="..\..\vsprops\code_generation_release.props" /> | ||
| 82 | <Import Project="..\..\vsprops\optimization_release.props" /> | ||
| 83 | <Import Project="..\..\vsprops\externals.props" /> | ||
| 84 | </ImportGroup> | ||
| 85 | <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> | ||
| 86 | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| 87 | <Import Project="..\..\vsprops\Base.props" /> | ||
| 88 | <Import Project="..\..\vsprops\code_generation_release.props" /> | ||
| 89 | <Import Project="..\..\vsprops\optimization_release.props" /> | ||
| 90 | <Import Project="..\..\vsprops\externals.props" /> | ||
| 91 | </ImportGroup> | ||
| 92 | <PropertyGroup Label="UserMacros" /> | ||
| 93 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> | ||
| 94 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> | ||
| 95 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> | ||
| 96 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> | ||
| 97 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| 98 | <ClCompile /> | ||
| 99 | <Link> | ||
| 100 | <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| 101 | </Link> | ||
| 102 | </ItemDefinitionGroup> | ||
| 103 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
| 104 | <ClCompile /> | ||
| 105 | <Link> | ||
| 106 | <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| 107 | </Link> | ||
| 108 | </ItemDefinitionGroup> | ||
| 109 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| 110 | <ClCompile /> | ||
| 111 | <Link> | ||
| 112 | <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| 113 | <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
| 114 | <OptimizeReferences>true</OptimizeReferences> | ||
| 115 | </Link> | ||
| 116 | <ClCompile /> | ||
| 117 | <ClCompile /> | ||
| 118 | <ClCompile /> | ||
| 119 | </ItemDefinitionGroup> | ||
| 120 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
| 121 | <ClCompile /> | ||
| 122 | <Link> | ||
| 123 | <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| 124 | <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
| 125 | <OptimizeReferences>true</OptimizeReferences> | ||
| 126 | </Link> | ||
| 127 | </ItemDefinitionGroup> | ||
| 128 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
| 129 | <ImportGroup Label="ExtensionTargets"> | ||
| 130 | </ImportGroup> | ||
| 131 | </Project> \ No newline at end of file | ||
diff --git a/src/video_core/video_core.vcxproj.filters b/src/video_core/video_core.vcxproj.filters new file mode 100644 index 000000000..e796fbe21 --- /dev/null +++ b/src/video_core/video_core.vcxproj.filters | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| 3 | <ItemGroup> | ||
| 4 | <ClCompile Include="src\video_core.cpp" /> | ||
| 5 | <ClCompile Include="src\utils.cpp" /> | ||
| 6 | <ClCompile Include="src\renderer_opengl\renderer_opengl.cpp"> | ||
| 7 | <Filter>renderer_opengl</Filter> | ||
| 8 | </ClCompile> | ||
| 9 | </ItemGroup> | ||
| 10 | <ItemGroup> | ||
| 11 | <ClInclude Include="src\renderer_base.h" /> | ||
| 12 | <ClInclude Include="src\video_core.h" /> | ||
| 13 | <ClInclude Include="src\utils.h" /> | ||
| 14 | <ClInclude Include="src\renderer_opengl\renderer_opengl.h"> | ||
| 15 | <Filter>renderer_opengl</Filter> | ||
| 16 | </ClInclude> | ||
| 17 | </ItemGroup> | ||
| 18 | <ItemGroup> | ||
| 19 | <Text Include="CMakeLists.txt" /> | ||
| 20 | </ItemGroup> | ||
| 21 | <ItemGroup> | ||
| 22 | <Filter Include="renderer_opengl"> | ||
| 23 | <UniqueIdentifier>{e0245557-dbd4-423e-9399-513d5e99f1e4}</UniqueIdentifier> | ||
| 24 | </Filter> | ||
| 25 | </ItemGroup> | ||
| 26 | </Project> \ No newline at end of file | ||