render: Add 2D projections

pull/20/head
Andri Yngvason 2020-03-05 18:46:27 +00:00
parent 1bf618a098
commit a327a2f6dd
4 changed files with 24 additions and 2 deletions

View File

@ -40,6 +40,7 @@ struct renderer {
struct { struct {
GLuint program; GLuint program;
GLint u_tex; GLint u_tex;
GLint u_proj;
} shader; } shader;
}; };

View File

@ -1,3 +1,5 @@
uniform mat2 u_proj;
attribute vec2 pos; attribute vec2 pos;
attribute vec2 texture; attribute vec2 texture;
@ -6,5 +8,5 @@ varying vec2 v_texture;
void main() void main()
{ {
v_texture = vec2(texture.s, 1.0 - texture.t); v_texture = vec2(texture.s, 1.0 - texture.t);
gl_Position = vec4(pos, 0, 1); gl_Position = vec4(u_proj * pos, 0, 1);
} }

View File

@ -1,3 +1,5 @@
uniform mat2 u_proj;
attribute vec2 pos; attribute vec2 pos;
attribute vec2 texture; attribute vec2 texture;
@ -6,5 +8,5 @@ varying vec2 v_texture;
void main() void main()
{ {
v_texture = texture; v_texture = texture;
gl_Position = vec4(pos, 0, 1); gl_Position = vec4(u_proj * pos, 0, 1);
} }

View File

@ -412,6 +412,7 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height,
} }
self->shader.u_tex = glGetUniformLocation(self->shader.program, "u_tex"); self->shader.u_tex = glGetUniformLocation(self->shader.program, "u_tex");
self->shader.u_proj = glGetUniformLocation(self->shader.program, "u_proj");
self->width = width; self->width = width;
self->height = height; self->height = height;
@ -487,7 +488,15 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame)
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image); glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
glUseProgram(self->shader.program); glUseProgram(self->shader.program);
glUniform1i(self->shader.u_tex, 0); glUniform1i(self->shader.u_tex, 0);
const float proj[] = {
1.0f, 0.0f,
0.0f, 1.0f,
};
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
gl_render(); gl_render();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
@ -516,7 +525,15 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format,
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
glUseProgram(self->shader.program); glUseProgram(self->shader.program);
glUniform1i(self->shader.u_tex, 0); glUniform1i(self->shader.u_tex, 0);
const float proj[] = {
1.0f, 0.0f,
0.0f, 1.0f,
};
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
gl_render(); gl_render();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);