render: Add 2D projections
parent
1bf618a098
commit
a327a2f6dd
|
@ -40,6 +40,7 @@ struct renderer {
|
|||
struct {
|
||||
GLuint program;
|
||||
GLint u_tex;
|
||||
GLint u_proj;
|
||||
} shader;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
uniform mat2 u_proj;
|
||||
|
||||
attribute vec2 pos;
|
||||
attribute vec2 texture;
|
||||
|
||||
|
@ -6,5 +8,5 @@ varying vec2 v_texture;
|
|||
void main()
|
||||
{
|
||||
v_texture = vec2(texture.s, 1.0 - texture.t);
|
||||
gl_Position = vec4(pos, 0, 1);
|
||||
gl_Position = vec4(u_proj * pos, 0, 1);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
uniform mat2 u_proj;
|
||||
|
||||
attribute vec2 pos;
|
||||
attribute vec2 texture;
|
||||
|
||||
|
@ -6,5 +8,5 @@ varying vec2 v_texture;
|
|||
void main()
|
||||
{
|
||||
v_texture = texture;
|
||||
gl_Position = vec4(pos, 0, 1);
|
||||
gl_Position = vec4(u_proj * pos, 0, 1);
|
||||
}
|
||||
|
|
17
src/render.c
17
src/render.c
|
@ -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_proj = glGetUniformLocation(self->shader.program, "u_proj");
|
||||
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
|
@ -487,7 +488,15 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame)
|
|||
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
|
||||
|
||||
glUseProgram(self->shader.program);
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
glUseProgram(self->shader.program);
|
||||
|
||||
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();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
|
Loading…
Reference in New Issue