Kill the hard-coded texture enums (yay).
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 2 Oct 2012 17:34:11 +0000 (19:34 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 2 Oct 2012 17:34:11 +0000 (19:34 +0200)
effect_chain.cpp
effect_chain.h
main.cpp
texture_enum.h [deleted file]
widgets.cpp

index d45c2fc..a6ff90e 100644 (file)
@@ -16,7 +16,6 @@
 #include "saturation_effect.h"
 #include "mirror_effect.h"
 #include "vignette_effect.h"
-#include "texture_enum.h"
 
 EffectChain::EffectChain(unsigned width, unsigned height)
        : width(width), height(height), use_srgb_texture_format(false), finalized(false) {}
@@ -220,7 +219,11 @@ void EffectChain::finalize()
        memset(mapped_pbo, 0, width * height * bytes_per_pixel);
        glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
        
-       glBindTexture(GL_TEXTURE_2D, SOURCE_IMAGE);
+       glGenTextures(1, &source_image_num);
+       check_error();
+       glBindTexture(GL_TEXTURE_2D, source_image_num);
+       check_error();
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        check_error();
        glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
        check_error();
@@ -245,7 +248,7 @@ void EffectChain::render_to_screen(unsigned char *src)
        // Re-upload the texture from the PBO.
        glActiveTexture(GL_TEXTURE0);
        check_error();
-       glBindTexture(GL_TEXTURE_2D, SOURCE_IMAGE);
+       glBindTexture(GL_TEXTURE_2D, source_image_num);
        check_error();
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
        check_error();
index 3fa62ee..5b8ddbc 100644 (file)
@@ -53,6 +53,7 @@ private:
        ImageFormat input_format, output_format;
        std::vector<Effect *> effects;
 
+       GLuint source_image_num;
        bool use_srgb_texture_format;
 
        GLint glsl_program_num;
index 2790bf8..1386a0f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -25,7 +25,6 @@
 #include "effect_chain.h"
 #include "util.h"
 #include "widgets.h"
-#include "texture_enum.h"
 
 unsigned char result[WIDTH * HEIGHT * 4];
 
@@ -36,7 +35,7 @@ float saturation = 1.0f;
 
 float radius = 0.3f;
 float inner_radius = 0.3f;
-
+       
 void update_hsv(Effect *lift_gamma_gain_effect, Effect *saturation_effect)
 {
        RGBTriplet lift(0.0f, 0.0f, 0.0f);
@@ -157,11 +156,6 @@ int main(int argc, char **argv)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
 
-       glBindTexture(GL_TEXTURE_2D, SOURCE_IMAGE);
-       check_error();
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-       check_error();
-
        unsigned img_w, img_h;
        unsigned char *src_img = load_image("blg_wheels_woman_1.jpg", &img_w, &img_h);
 
diff --git a/texture_enum.h b/texture_enum.h
deleted file mode 100644 (file)
index e1e956f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _TEXTURE_ENUM_H
-#define _TEXTURE_ENUM_H 1
-
-enum textures {
-       SOURCE_IMAGE = 1,
-       SRGB_LUT = 2,
-       SRGB_REVERSE_LUT = 3,
-       HSV_WHEEL = 4,
-};
-
-#endif // !defined(_TEXTURE_ENUM_H)
-
index a170391..09d878e 100644 (file)
@@ -6,10 +6,11 @@
 
 #include "widgets.h"
 #include "util.h"
-#include "texture_enum.h"
 
 #define HSV_WHEEL_SIZE 128
 
+GLuint hsv_wheel_num;
+
 void draw_hsv_wheel(float y, float rad, float theta, float value)
 {
        glUseProgram(0);
@@ -18,7 +19,7 @@ void draw_hsv_wheel(float y, float rad, float theta, float value)
        check_error();
        glEnable(GL_TEXTURE_2D);
        check_error();
-       glBindTexture(GL_TEXTURE_2D, HSV_WHEEL);
+       glBindTexture(GL_TEXTURE_2D, hsv_wheel_num);
        check_error();
        glActiveTexture(GL_TEXTURE1);
        check_error();
@@ -110,6 +111,8 @@ void draw_saturation_bar(float y, float saturation)
 
 void make_hsv_wheel_texture()
 {
+       glGenTextures(1, &hsv_wheel_num);
+
        static unsigned char hsv_pix[HSV_WHEEL_SIZE * HSV_WHEEL_SIZE * 4];
        for (int y = 0; y < HSV_WHEEL_SIZE; ++y) {
                for (int x = 0; x < HSV_WHEEL_SIZE; ++x) {
@@ -133,7 +136,7 @@ void make_hsv_wheel_texture()
                printf("\n");
        }
 
-       glBindTexture(GL_TEXTURE_2D, HSV_WHEEL);
+       glBindTexture(GL_TEXTURE_2D, hsv_wheel_num);
        check_error();
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        check_error();