aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-08 11:30:38 -0400
committerDrew DeVault <sir@cmpwn.com>2017-06-08 11:30:38 -0400
commit211488131f675b3f3c59607fb1336b69148023d2 (patch)
treede6bfb2358ccf54f76277b9ffc2773201e8f0f62 /example
parentfc1dc1b5b0e912fd060f257a0c1f6d5b38d6bb75 (diff)
Add wlr_shader to wlr-render
Diffstat (limited to 'example')
-rw-r--r--example/rotation.c54
1 files changed, 8 insertions, 46 deletions
diff --git a/example/rotation.c b/example/rotation.c
index 361cfb8c..656196e0 100644
--- a/example/rotation.c
+++ b/example/rotation.c
@@ -9,6 +9,7 @@
#include <wayland-server-protocol.h>
#include <GLES3/gl3.h>
#include <wlr/render/matrix.h>
+#include <wlr/render.h>
#include <wlr/backend.h>
#include <wlr/session.h>
#include <wlr/types.h>
@@ -40,7 +41,7 @@ struct state {
struct wl_list config;
struct gl {
- GLuint prog;
+ struct wlr_shader *shader;
GLuint vao;
GLuint vbo;
GLuint ebo;
@@ -65,54 +66,15 @@ struct output_config {
struct wl_list link;
};
-static GLuint create_shader(GLenum type, const GLchar *src, GLint len) {
- GLuint shader = glCreateShader(type);
- glShaderSource(shader, 1, &src, &len);
- glCompileShader(shader);
-
- GLint success;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
-
- if (success == GL_FALSE) {
- GLint loglen;
- glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &loglen);
-
- GLchar msg[loglen];
- glGetShaderInfoLog(shader, loglen, &loglen, msg);
-
- fprintf(stderr, "Failed to create shader: %s\n", msg);
+static void init_gl(struct gl *gl) {
+ gl->shader = wlr_shader_init(vert_src);
+ if (!gl->shader) {
exit(1);
}
-
- return shader;
-}
-
-static void init_gl(struct gl *gl) {
- GLuint vert = create_shader(GL_VERTEX_SHADER, vert_src, strlen(vert_src));
- GLuint frag = create_shader(GL_FRAGMENT_SHADER, frag_src, strlen(frag_src));
-
- gl->prog = glCreateProgram();
- glAttachShader(gl->prog, vert);
- glAttachShader(gl->prog, frag);
- glLinkProgram(gl->prog);
-
- GLint success;
- glGetProgramiv(gl->prog, GL_LINK_STATUS, &success);
-
- if (success == GL_FALSE) {
- GLint len;
- glGetProgramiv(gl->prog, GL_INFO_LOG_LENGTH, &len);
-
- GLchar msg[len];
- glGetProgramInfoLog(gl->prog, len, &len, msg);
-
- fprintf(stderr, "Failed to link program: %s\n", msg);
+ if (!wlr_shader_add_format(gl->shader, WL_SHM_FORMAT_RGB332, frag_src)) {
exit(1);
}
- glDeleteProgram(vert);
- glDeleteProgram(frag);
-
GLfloat verticies[] = {
1, 1, 1, 1, // bottom right
1, 0, 1, 0, // top right
@@ -147,7 +109,7 @@ static void init_gl(struct gl *gl) {
}
static void cleanup_gl(struct gl *gl) {
- glDeleteProgram(gl->prog);
+ wlr_shader_destroy(gl->shader);
glDeleteVertexArrays(1, &gl->vao);
glDeleteBuffers(1, &gl->vbo);
glDeleteTextures(1, &gl->tex);
@@ -166,7 +128,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
glViewport(0, 0, width, height);
wlr_output_effective_resolution(output, &width, &height);
- glUseProgram(s->gl.prog);
+ wlr_shader_use(s->gl.shader, WL_SHM_FORMAT_RGB332);
glBindVertexArray(s->gl.vao);
glBindBuffer(GL_ARRAY_BUFFER, s->gl.vbo);