]> git.sesse.net Git - movit/commitdiff
Be better at cleaning up at destruction time. Still stuff to do.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Oct 2012 19:56:43 +0000 (21:56 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Oct 2012 19:56:43 +0000 (21:56 +0200)
effect_chain.cpp
effect_chain.h
gtest_sdl_main.cpp
test_util.cpp
test_util.h

index d509fba391029866cb36c3288f2969c8c5b4baab..9ea2c03a828d2ea6861b504c33512fa713d2cdea 100644 (file)
 EffectChain::EffectChain(float aspect_nom, float aspect_denom)
        : aspect_nom(aspect_nom),
          aspect_denom(aspect_denom),
+         fbo(0),
          finalized(false) {}
 
+EffectChain::~EffectChain()
+{
+       for (unsigned i = 0; i < nodes.size(); ++i) {
+               if (nodes[i]->output_texture != 0) {
+                       glDeleteTextures(1, &nodes[i]->output_texture);
+               }
+               delete nodes[i]->effect;
+               delete nodes[i];
+       }
+       for (unsigned i = 0; i < phases.size(); ++i) {
+               glDeleteProgram(phases[i]->glsl_program_num);
+               glDeleteShader(phases[i]->vertex_shader);
+               glDeleteShader(phases[i]->fragment_shader);
+               delete phases[i];
+       }
+       if (fbo != 0) {
+               glDeleteFramebuffers(1, &fbo);
+       }
+}
+
 Input *EffectChain::add_input(Input *input)
 {
        inputs.push_back(input);
@@ -49,6 +70,7 @@ Node *EffectChain::add_node(Effect *effect)
        node->effect_id = effect_id;
        node->output_color_space = COLORSPACE_INVALID;
        node->output_gamma_curve = GAMMA_INVALID;
+       node->output_texture = 0;
 
        nodes.push_back(node);
        node_map[effect] = node;
@@ -267,6 +289,8 @@ Phase *EffectChain::compile_glsl_program(
 
        Phase *phase = new Phase;
        phase->glsl_program_num = glsl_program_num;
+       phase->vertex_shader = vs_obj;
+       phase->fragment_shader = fs_obj;
        phase->input_needs_mipmaps = input_needs_mipmaps;
        phase->inputs = true_inputs;
        phase->effects = effects;
index 989a0199e460689110a709c5d508284bc9e35f4a..741b83d75954b1d9737f5870260504a6b6980a36 100644 (file)
@@ -48,7 +48,7 @@ private:
 
 // A rendering phase; a single GLSL program rendering a single quad.
 struct Phase {
-       GLint glsl_program_num;
+       GLint glsl_program_num, vertex_shader, fragment_shader;
        bool input_needs_mipmaps;
 
        // Inputs are only inputs from other phases (ie., those that come from RTT);
@@ -62,6 +62,7 @@ struct Phase {
 class EffectChain {
 public:
        EffectChain(float aspect_nom, float aspect_denom);  // E.g., 16.0f, 9.0f for 16:9.
+       ~EffectChain();
 
        // User API:
        // input, effects, output, finalize need to come in that specific order.
index 47d7c679107c093cdda8530ef4d9ce42cee6a71a..4a1c74762445522b7ac02e012008c247db404a00 100644 (file)
@@ -11,5 +11,7 @@ int main(int argc, char **argv) {
        SDL_WM_SetCaption("OpenGL window for unit test", NULL);
 
        testing::InitGoogleTest(&argc, argv);
-       return RUN_ALL_TESTS();
+       int err = RUN_ALL_TESTS();
+       SDL_Quit();
+       exit(err);
 }
index 1f7dc1fe8629a2191df3f35123cffb1892875be9..ab10f7b82be0fd3a4528d54eb406cdd6ce09f733 100644 (file)
@@ -34,6 +34,12 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned
        check_error();
 }
 
+EffectChainTester::~EffectChainTester()
+{
+       glDeleteFramebuffers(1, &fbo);
+       glDeleteTextures(1, &texnum);
+}
+
 Input *EffectChainTester::add_input(const float *data, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve)
 {
        ImageFormat format;
index 1de5d2582ad0058c10b4156707fe19cdbc3da090..5dac7b2022dafb76d7cf84beaad0acb8a02111f0 100644 (file)
@@ -6,6 +6,8 @@
 class EffectChainTester {
 public:
        EffectChainTester(const float *data, unsigned width, unsigned height, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve);
+       ~EffectChainTester();
+       
        EffectChain *get_chain() { return &chain; }
        Input *add_input(const float *data, MovitPixelFormat pixel_format, ColorSpace color_space, GammaCurve gamma_curve);
        void run(float *out_data, GLenum format, ColorSpace color_space, GammaCurve gamma_curve);