render: Add output transforms
parent
a327a2f6dd
commit
a3d4189a0b
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include <GLES2/gl2.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
struct dmabuf_frame;
|
||||
|
||||
|
@ -33,6 +35,7 @@ struct renderer {
|
|||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
enum wl_output_transform transform;
|
||||
|
||||
GLint read_format;
|
||||
GLint read_type;
|
||||
|
@ -45,6 +48,7 @@ struct renderer {
|
|||
};
|
||||
|
||||
int renderer_init(struct renderer* self, uint32_t width, uint32_t height,
|
||||
enum wl_output_transform transform,
|
||||
enum renderer_input_type input_type);
|
||||
void renderer_destroy(struct renderer* self);
|
||||
|
||||
|
|
|
@ -783,7 +783,7 @@ int main(int argc, char* argv[])
|
|||
RENDERER_INPUT_DMABUF : RENDERER_INPUT_FB;
|
||||
if (renderer_init(&self.renderer, self.selected_output->width,
|
||||
self.selected_output->height,
|
||||
renderer_input_type) < 0) {
|
||||
WL_OUTPUT_TRANSFORM_NORMAL, renderer_input_type) < 0) {
|
||||
log_error("Failed to initialise renderer\n");
|
||||
goto failure;
|
||||
}
|
||||
|
|
47
src/render.c
47
src/render.c
|
@ -63,6 +63,41 @@ enum {
|
|||
X_GL_EXTENSIONS
|
||||
#undef X
|
||||
|
||||
static const float transforms[][4] = {
|
||||
[WL_OUTPUT_TRANSFORM_NORMAL] = {
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_90] = {
|
||||
0.0f, -1.0f,
|
||||
1.0f, 0.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_180] = {
|
||||
-1.0f, 0.0f,
|
||||
0.0f, -1.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_270] = {
|
||||
0.0f, 1.0f,
|
||||
-1.0f, 0.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_FLIPPED] = { // TODO
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_FLIPPED_90] = { // TODO
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_FLIPPED_180] = { // TODO
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
},
|
||||
[WL_OUTPUT_TRANSFORM_FLIPPED_270] = { // TODO
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
},
|
||||
};
|
||||
|
||||
int gl_format_from_fourcc(GLenum* result, uint32_t format)
|
||||
{
|
||||
switch (format) {
|
||||
|
@ -333,6 +368,7 @@ void renderer_destroy(struct renderer* self)
|
|||
}
|
||||
|
||||
int renderer_init(struct renderer* self, uint32_t width, uint32_t height,
|
||||
enum wl_output_transform transform,
|
||||
enum renderer_input_type input_type)
|
||||
{
|
||||
if (!eglBindAPI(EGL_OPENGL_ES_API))
|
||||
|
@ -416,6 +452,7 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height,
|
|||
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->transform = transform;
|
||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &self->read_format);
|
||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &self->read_type);
|
||||
|
||||
|
@ -491,10 +528,7 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame)
|
|||
|
||||
glUniform1i(self->shader.u_tex, 0);
|
||||
|
||||
const float proj[] = {
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
};
|
||||
const float* proj = transforms[self->transform];
|
||||
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
|
||||
|
||||
gl_render();
|
||||
|
@ -528,10 +562,7 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format,
|
|||
|
||||
glUniform1i(self->shader.u_tex, 0);
|
||||
|
||||
const float proj[] = {
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
};
|
||||
const float* proj = transforms[self->transform];
|
||||
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
|
||||
|
||||
gl_render();
|
||||
|
|
Loading…
Reference in New Issue