From: Mikko Rasa Date: Sun, 13 Dec 2015 12:58:58 +0000 (+0200) Subject: Add a helper function for creating textures X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7b799ae8d6560bfb8c65e0b4f6ea26efe129559a;p=geometrycompositor.git Add a helper function for creating textures --- diff --git a/source/main.c b/source/main.c index 074477b..adb5827 100644 --- a/source/main.c +++ b/source/main.c @@ -241,6 +241,17 @@ unsigned link_program(unsigned *shaders, unsigned nshaders) return program; } +unsigned create_2d_texture() +{ + unsigned texture; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + return texture; +} + int create_gl_resources(Compositor *compositor, CompositedScreen *screen) { unsigned stride; @@ -273,12 +284,8 @@ int create_gl_resources(Compositor *compositor, CompositedScreen *screen) glBindBuffer(GL_ARRAY_BUFFER, 0); - glGenTextures(1, &screen->fb_texture); - glBindTexture(GL_TEXTURE_2D, screen->fb_texture); + screen->fb_texture = create_2d_texture(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screen->width, screen->height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, 0); glGenFramebuffers(1, &screen->framebuffer); @@ -366,11 +373,7 @@ CompositedWindow *add_window(Compositor *compositor, CompositedScreen *screen, W if(window->map_state==IsViewable) create_window_pixmap(compositor, screen, window); - glGenTextures(1, &window->texture); - glBindTexture(GL_TEXTURE_2D, window->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + window->texture = create_2d_texture(); return window; }