diff options
| author | 2019-11-28 20:25:56 -0300 | |
|---|---|---|
| committer | 2019-11-28 20:25:56 -0300 | |
| commit | 3a44faff11892861cb7782750dd7e78079ec40bd (patch) | |
| tree | c55568060ca7b41acc05edd7559c4cdb0d01f015 /src | |
| parent | renderer_opengl: Drop macros for message decorations (diff) | |
| download | yuzu-3a44faff11892861cb7782750dd7e78079ec40bd.tar.gz yuzu-3a44faff11892861cb7782750dd7e78079ec40bd.tar.xz yuzu-3a44faff11892861cb7782750dd7e78079ec40bd.zip | |
renderer_opengl: Use explicit binding for presentation shaders
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 46 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 8 |
2 files changed, 20 insertions, 34 deletions
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 23b60dbf4..9e66dea60 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -27,18 +27,18 @@ namespace OpenGL { | |||
| 27 | namespace { | 27 | namespace { |
| 28 | 28 | ||
| 29 | constexpr char vertex_shader[] = R"( | 29 | constexpr char vertex_shader[] = R"( |
| 30 | #version 150 core | 30 | #version 430 core |
| 31 | 31 | ||
| 32 | in vec2 vert_position; | 32 | layout (location = 0) in vec2 vert_position; |
| 33 | in vec2 vert_tex_coord; | 33 | layout (location = 1) in vec2 vert_tex_coord; |
| 34 | out vec2 frag_tex_coord; | 34 | layout (location = 0) out vec2 frag_tex_coord; |
| 35 | 35 | ||
| 36 | // This is a truncated 3x3 matrix for 2D transformations: | 36 | // This is a truncated 3x3 matrix for 2D transformations: |
| 37 | // The upper-left 2x2 submatrix performs scaling/rotation/mirroring. | 37 | // The upper-left 2x2 submatrix performs scaling/rotation/mirroring. |
| 38 | // The third column performs translation. | 38 | // The third column performs translation. |
| 39 | // The third row could be used for projection, which we don't need in 2D. It hence is assumed to | 39 | // The third row could be used for projection, which we don't need in 2D. It hence is assumed to |
| 40 | // implicitly be [0, 0, 1] | 40 | // implicitly be [0, 0, 1] |
| 41 | uniform mat3x2 modelview_matrix; | 41 | layout (location = 0) uniform mat3x2 modelview_matrix; |
| 42 | 42 | ||
| 43 | void main() { | 43 | void main() { |
| 44 | // Multiply input position by the rotscale part of the matrix and then manually translate by | 44 | // Multiply input position by the rotscale part of the matrix and then manually translate by |
| @@ -50,20 +50,22 @@ void main() { | |||
| 50 | )"; | 50 | )"; |
| 51 | 51 | ||
| 52 | constexpr char fragment_shader[] = R"( | 52 | constexpr char fragment_shader[] = R"( |
| 53 | #version 150 core | 53 | #version 430 core |
| 54 | 54 | ||
| 55 | in vec2 frag_tex_coord; | 55 | layout (location = 0) in vec2 frag_tex_coord; |
| 56 | out vec4 color; | 56 | layout (location = 0) out vec4 color; |
| 57 | 57 | ||
| 58 | uniform sampler2D color_texture; | 58 | layout (binding = 0) uniform sampler2D color_texture; |
| 59 | 59 | ||
| 60 | void main() { | 60 | void main() { |
| 61 | // Swap RGBA -> ABGR so we don't have to do this on the CPU. This needs to change if we have to | ||
| 62 | // support more framebuffer pixel formats. | ||
| 63 | color = texture(color_texture, frag_tex_coord); | 61 | color = texture(color_texture, frag_tex_coord); |
| 64 | } | 62 | } |
| 65 | )"; | 63 | )"; |
| 66 | 64 | ||
| 65 | constexpr GLint PositionLocation = 0; | ||
| 66 | constexpr GLint TexCoordLocation = 1; | ||
| 67 | constexpr GLint ModelViewMatrixLocation = 0; | ||
| 68 | |||
| 67 | /// Vertex structure that the drawn screen rectangles are composed of. | 69 | /// Vertex structure that the drawn screen rectangles are composed of. |
| 68 | struct ScreenRectVertex { | 70 | struct ScreenRectVertex { |
| 69 | ScreenRectVertex(GLfloat x, GLfloat y, GLfloat u, GLfloat v) { | 71 | ScreenRectVertex(GLfloat x, GLfloat y, GLfloat u, GLfloat v) { |
| @@ -257,10 +259,6 @@ void RendererOpenGL::InitOpenGLObjects() { | |||
| 257 | state.draw.shader_program = shader.handle; | 259 | state.draw.shader_program = shader.handle; |
| 258 | state.AllDirty(); | 260 | state.AllDirty(); |
| 259 | state.Apply(); | 261 | state.Apply(); |
| 260 | uniform_modelview_matrix = glGetUniformLocation(shader.handle, "modelview_matrix"); | ||
| 261 | uniform_color_texture = glGetUniformLocation(shader.handle, "color_texture"); | ||
| 262 | attrib_position = glGetAttribLocation(shader.handle, "vert_position"); | ||
| 263 | attrib_tex_coord = glGetAttribLocation(shader.handle, "vert_tex_coord"); | ||
| 264 | 262 | ||
| 265 | // Generate VBO handle for drawing | 263 | // Generate VBO handle for drawing |
| 266 | vertex_buffer.Create(); | 264 | vertex_buffer.Create(); |
| @@ -271,14 +269,14 @@ void RendererOpenGL::InitOpenGLObjects() { | |||
| 271 | 269 | ||
| 272 | // Attach vertex data to VAO | 270 | // Attach vertex data to VAO |
| 273 | glNamedBufferData(vertex_buffer.handle, sizeof(ScreenRectVertex) * 4, nullptr, GL_STREAM_DRAW); | 271 | glNamedBufferData(vertex_buffer.handle, sizeof(ScreenRectVertex) * 4, nullptr, GL_STREAM_DRAW); |
| 274 | glVertexArrayAttribFormat(vertex_array.handle, attrib_position, 2, GL_FLOAT, GL_FALSE, | 272 | glVertexArrayAttribFormat(vertex_array.handle, PositionLocation, 2, GL_FLOAT, GL_FALSE, |
| 275 | offsetof(ScreenRectVertex, position)); | 273 | offsetof(ScreenRectVertex, position)); |
| 276 | glVertexArrayAttribFormat(vertex_array.handle, attrib_tex_coord, 2, GL_FLOAT, GL_FALSE, | 274 | glVertexArrayAttribFormat(vertex_array.handle, TexCoordLocation, 2, GL_FLOAT, GL_FALSE, |
| 277 | offsetof(ScreenRectVertex, tex_coord)); | 275 | offsetof(ScreenRectVertex, tex_coord)); |
| 278 | glVertexArrayAttribBinding(vertex_array.handle, attrib_position, 0); | 276 | glVertexArrayAttribBinding(vertex_array.handle, PositionLocation, 0); |
| 279 | glVertexArrayAttribBinding(vertex_array.handle, attrib_tex_coord, 0); | 277 | glVertexArrayAttribBinding(vertex_array.handle, TexCoordLocation, 0); |
| 280 | glEnableVertexArrayAttrib(vertex_array.handle, attrib_position); | 278 | glEnableVertexArrayAttrib(vertex_array.handle, PositionLocation); |
| 281 | glEnableVertexArrayAttrib(vertex_array.handle, attrib_tex_coord); | 279 | glEnableVertexArrayAttrib(vertex_array.handle, TexCoordLocation); |
| 282 | glVertexArrayVertexBuffer(vertex_array.handle, 0, vertex_buffer.handle, 0, | 280 | glVertexArrayVertexBuffer(vertex_array.handle, 0, vertex_buffer.handle, 0, |
| 283 | sizeof(ScreenRectVertex)); | 281 | sizeof(ScreenRectVertex)); |
| 284 | 282 | ||
| @@ -420,11 +418,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) { | |||
| 420 | // Set projection matrix | 418 | // Set projection matrix |
| 421 | std::array<GLfloat, 3 * 2> ortho_matrix = | 419 | std::array<GLfloat, 3 * 2> ortho_matrix = |
| 422 | MakeOrthographicMatrix((float)layout.width, (float)layout.height); | 420 | MakeOrthographicMatrix((float)layout.width, (float)layout.height); |
| 423 | glUniformMatrix3x2fv(uniform_modelview_matrix, 1, GL_FALSE, ortho_matrix.data()); | 421 | glUniformMatrix3x2fv(ModelViewMatrixLocation, 1, GL_FALSE, ortho_matrix.data()); |
| 424 | |||
| 425 | // Bind texture in Texture Unit 0 | ||
| 426 | glActiveTexture(GL_TEXTURE0); | ||
| 427 | glUniform1i(uniform_color_texture, 0); | ||
| 428 | 422 | ||
| 429 | DrawScreenTriangles(screen_info, (float)screen.left, (float)screen.top, | 423 | DrawScreenTriangles(screen_info, (float)screen.left, (float)screen.top, |
| 430 | (float)screen.GetWidth(), (float)screen.GetHeight()); | 424 | (float)screen.GetWidth(), (float)screen.GetHeight()); |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 6bb620a31..b56328a7f 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h | |||
| @@ -104,14 +104,6 @@ private: | |||
| 104 | /// OpenGL framebuffer data | 104 | /// OpenGL framebuffer data |
| 105 | std::vector<u8> gl_framebuffer_data; | 105 | std::vector<u8> gl_framebuffer_data; |
| 106 | 106 | ||
| 107 | // Shader uniform location indices | ||
| 108 | GLuint uniform_modelview_matrix; | ||
| 109 | GLuint uniform_color_texture; | ||
| 110 | |||
| 111 | // Shader attribute input indices | ||
| 112 | GLuint attrib_position; | ||
| 113 | GLuint attrib_tex_coord; | ||
| 114 | |||
| 115 | /// Used for transforming the framebuffer orientation | 107 | /// Used for transforming the framebuffer orientation |
| 116 | Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags; | 108 | Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags; |
| 117 | Common::Rectangle<int> framebuffer_crop_rect; | 109 | Common::Rectangle<int> framebuffer_crop_rect; |