aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/video_core/renderer_opengl/gl_shaders.h
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner <yuriks@yuriks.net>2014-08-28 15:21:54 -0300
committerGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-10-12 14:38:53 +0200
commit11642fd3a218185187bb356f2f446313694d4be4 (patch)
treee8cb0ef9b5e36605b01ec792180873511770f7a1 /src/video_core/renderer_opengl/gl_shaders.h
parentfec7f6b035c1328cefac8a97cd26f3a79d033fa4 (diff)
Rework OpenGL renderer.
The OpenGL renderer has been revised, with the following changes: - Initialization and rendering have been refactored to reduce the number of redundant objects used. - Framebuffer rotation is now done directly, using texture mapping. - Vertex coordinates are now given in pixels, and the projection matrix isn't hardcoded anymore.
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shaders.h')
-rw-r--r--src/video_core/renderer_opengl/gl_shaders.h46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/video_core/renderer_opengl/gl_shaders.h b/src/video_core/renderer_opengl/gl_shaders.h
index 380648f4..0f88ab80 100644
--- a/src/video_core/renderer_opengl/gl_shaders.h
+++ b/src/video_core/renderer_opengl/gl_shaders.h
@@ -6,34 +6,40 @@
namespace GLShaders {
-static const char g_vertex_shader[] = R"(
+const char g_vertex_shader[] = R"(
#version 150 core
-in vec3 position;
-in vec2 texCoord;
-out vec2 UV;
+in vec2 vert_position;
+in vec2 vert_tex_coord;
+out vec2 frag_tex_coord;
-mat3 window_scale = mat3(
- vec3(1.0, 0.0, 0.0),
- vec3(0.0, 5.0/6.0, 0.0), // TODO(princesspeachum): replace hard-coded aspect with uniform
- vec3(0.0, 0.0, 1.0)
- );
+// This is a truncated 3x3 matrix for 2D transformations:
+// The upper-left 2x2 submatrix performs scaling/rotation/mirroring.
+// The third column performs translation.
+// The third row could be used for projection, which we don't need in 2D. It hence is assumed to
+// implicitly be [0, 0, 1]
+uniform mat3x2 modelview_matrix;
void main() {
- gl_Position.xyz = window_scale * position;
- gl_Position.w = 1.0;
-
- UV = texCoord;
-})";
+ // Multiply input position by the rotscale part of the matrix and then manually translate by
+ // the last column. This is equivalent to using a full 3x3 matrix and expanding the vector
+ // to `vec3(vert_position.xy, 1.0)`
+ gl_Position = vec4(mat2(modelview_matrix) * vert_position + modelview_matrix[2], 0.0, 1.0);
+ frag_tex_coord = vert_tex_coord;
+}
+)";
-static const char g_fragment_shader[] = R"(
+const char g_fragment_shader[] = R"(
#version 150 core
-in vec2 UV;
-out vec3 color;
-uniform sampler2D sampler;
+
+in vec2 frag_tex_coord;
+out vec4 color;
+
+uniform sampler2D color_texture;
void main() {
- color = texture(sampler, UV).rgb;
-})";
+ color = texture(color_texture, frag_tex_coord);
+}
+)";
}