From 1727b0714398fc4f318048d457a35ca58bc30b59 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 13 Oct 2012 21:56:43 +0200 Subject: [PATCH] Be better at cleaning up at destruction time. Still stuff to do. --- effect_chain.cpp | 24 ++++++++++++++++++++++++ effect_chain.h | 3 ++- gtest_sdl_main.cpp | 4 +++- test_util.cpp | 6 ++++++ test_util.h | 2 ++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/effect_chain.cpp b/effect_chain.cpp index d509fba..9ea2c03 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -21,8 +21,29 @@ 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; diff --git a/effect_chain.h b/effect_chain.h index 989a019..741b83d 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -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. diff --git a/gtest_sdl_main.cpp b/gtest_sdl_main.cpp index 47d7c67..4a1c747 100644 --- a/gtest_sdl_main.cpp +++ b/gtest_sdl_main.cpp @@ -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); } diff --git a/test_util.cpp b/test_util.cpp index 1f7dc1f..ab10f7b 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -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; diff --git a/test_util.h b/test_util.h index 1de5d25..5dac7b2 100644 --- a/test_util.h +++ b/test_util.h @@ -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); -- 2.39.2