X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=flat_input.cpp;h=0f6f39565a2ccd6282679043e747f30c927594ee;hp=e99eba3b0f562469e6d17086d34726fd152db209;hb=1349c2cabb17a3637aa5bc2520c058333d8d48d7;hpb=67b2debafd624d3be66588171d6ec677b54247ba diff --git a/flat_input.cpp b/flat_input.cpp index e99eba3..0f6f395 100644 --- a/flat_input.cpp +++ b/flat_input.cpp @@ -21,6 +21,7 @@ FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format_in, width(width), height(height), pitch(width), + owns_texture(false), pixel_data(NULL), fixup_swap_rb(false), fixup_red_to_grayscale(false) @@ -28,6 +29,7 @@ FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format_in, assert(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_BYTE); register_int("output_linear_gamma", &output_linear_gamma); register_int("needs_mipmaps", &needs_mipmaps); + register_uniform_sampler2d("tex", &uniform_tex); // Some types are not supported in all GL versions (e.g. GLES), // and will corrected into the right format in the shader. @@ -56,9 +58,7 @@ FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format_in, FlatInput::~FlatInput() { - if (texture_num != 0) { - resource_pool->release_2d_texture(texture_num); - } + possibly_release_texture(); } void FlatInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num) @@ -102,7 +102,13 @@ void FlatInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsi } } else if (output_linear_gamma) { assert(type == GL_UNSIGNED_BYTE); - internal_format = GL_SRGB8_ALPHA8; + if (pixel_format == FORMAT_RGB) { + internal_format = GL_SRGB8; + } else if (pixel_format == FORMAT_RGBA_POSTMULTIPLIED_ALPHA) { + internal_format = GL_SRGB8_ALPHA8; + } else { + assert(false); + } } else { assert(type == GL_UNSIGNED_BYTE); if (pixel_format == FORMAT_R) { @@ -156,13 +162,14 @@ void FlatInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsi check_error(); glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); check_error(); + owns_texture = true; } else { glBindTexture(GL_TEXTURE_2D, texture_num); check_error(); } // Bind it to a sampler. - set_uniform_int(glsl_program_num, prefix, "tex", *sampler_num); + uniform_tex = *sampler_num; ++*sampler_num; } @@ -176,9 +183,15 @@ string FlatInput::output_fragment_shader() void FlatInput::invalidate_pixel_data() { - if (texture_num != 0) { + possibly_release_texture(); +} + +void FlatInput::possibly_release_texture() +{ + if (texture_num != 0 && owns_texture) { resource_pool->release_2d_texture(texture_num); texture_num = 0; + owns_texture = false; } }