]> git.tdb.fi Git - geometrycompositor.git/commitdiff
Add a helper function for creating textures
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2015 12:58:58 +0000 (14:58 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2015 12:58:58 +0000 (14:58 +0200)
source/main.c

index 074477bd35dca4e556b0c2cc113ddaf759d2127a..adb582799936b0d75d504c7d183cd608e046dd81 100644 (file)
@@ -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;
 }