Commit 3ac0592a authored by Jean-Paul Saman's avatar Jean-Paul Saman

src/xvba_video_glx.c: Use glEnable/glDisable on targets when using OpenGL functions.

Explicitly enable/disable targets when using OpenGL code.
parent c2d0d864
...@@ -302,8 +302,9 @@ static void destroy_hw_image_glx( ...@@ -302,8 +302,9 @@ static void destroy_hw_image_glx(
ASSERT(hwi); ASSERT(hwi);
if (hwi->num_textures > 0) { if (hwi->num_textures > 0) {
glDeleteTextures(hwi->num_textures, hwi->textures);
for (i = 0; i < hwi->num_textures; i++) { for (i = 0; i < hwi->num_textures; i++) {
assert(hwi->textures[i]);
gl_destroy_texture(&hwi->textures[i], hwi->target);
hwi->formats[i] = GL_NONE; hwi->formats[i] = GL_NONE;
hwi->textures[i] = 0; hwi->textures[i] = 0;
} }
...@@ -314,7 +315,6 @@ static void destroy_hw_image_glx( ...@@ -314,7 +315,6 @@ static void destroy_hw_image_glx(
gl_destroy_shader_object(hwi->shader); gl_destroy_shader_object(hwi->shader);
hwi->shader = NULL; hwi->shader = NULL;
} }
free(obj_image->hw.glx); free(obj_image->hw.glx);
obj_image->hw.glx = NULL; obj_image->hw.glx = NULL;
} }
...@@ -432,6 +432,8 @@ commit_hw_image_glx( ...@@ -432,6 +432,8 @@ commit_hw_image_glx(
offsets[0] = obj_image->image.offsets[0]; offsets[0] = obj_image->image.offsets[0];
} }
glEnable(hwi->target);
unsigned int i; unsigned int i;
for (i = 0; i < hwi->num_textures; i++) { for (i = 0; i < hwi->num_textures; i++) {
glBindTexture(hwi->target, hwi->textures[i]); glBindTexture(hwi->target, hwi->textures[i]);
...@@ -448,6 +450,8 @@ commit_hw_image_glx( ...@@ -448,6 +450,8 @@ commit_hw_image_glx(
); );
glBindTexture(hwi->target, 0); glBindTexture(hwi->target, 0);
} }
glDisable(hwi->target);
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
} }
...@@ -493,6 +497,7 @@ render_subpicture( ...@@ -493,6 +497,7 @@ render_subpicture(
hwi->formats[0] != GL_RGBA && hwi->formats[0] != GL_BGRA) hwi->formats[0] != GL_RGBA && hwi->formats[0] != GL_BGRA)
return VA_STATUS_ERROR_INVALID_IMAGE; return VA_STATUS_ERROR_INVALID_IMAGE;
glEnable(hwi->target);
glBindTexture(hwi->target, hwi->textures[0]); glBindTexture(hwi->target, hwi->textures[0]);
glColor4f(1.0f, 1.0f, 1.0f, alpha); glColor4f(1.0f, 1.0f, 1.0f, alpha);
glBegin(GL_QUADS); glBegin(GL_QUADS);
...@@ -565,6 +570,7 @@ render_subpicture( ...@@ -565,6 +570,7 @@ render_subpicture(
} }
glEnd(); glEnd();
glBindTexture(hwi->target, 0); glBindTexture(hwi->target, 0);
glDisable(hwi->target);
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
} }
...@@ -622,7 +628,7 @@ destroy_glx_surface( ...@@ -622,7 +628,7 @@ destroy_glx_surface(
} }
if (obj_glx_surface->tx_texture) { if (obj_glx_surface->tx_texture) {
glDeleteTextures(1, &obj_glx_surface->tx_texture); gl_destroy_texture(&obj_glx_surface->tx_texture, obj_glx_surface->target);
obj_glx_surface->tx_texture = 0; obj_glx_surface->tx_texture = 0;
} }
...@@ -642,7 +648,7 @@ destroy_glx_surface( ...@@ -642,7 +648,7 @@ destroy_glx_surface(
} }
if (obj_glx_surface->evergreen_texture) { if (obj_glx_surface->evergreen_texture) {
glDeleteTextures(1, &obj_glx_surface->evergreen_texture); gl_destroy_texture(&obj_glx_surface->evergreen_texture, obj_glx_surface->target);
obj_glx_surface->evergreen_texture = 0; obj_glx_surface->evergreen_texture = 0;
} }
...@@ -657,7 +663,7 @@ destroy_glx_surface( ...@@ -657,7 +663,7 @@ destroy_glx_surface(
} }
if (obj_glx_surface->hqscaler_texture) { if (obj_glx_surface->hqscaler_texture) {
glDeleteTextures(1, &obj_glx_surface->hqscaler_texture); gl_destroy_texture(&obj_glx_surface->hqscaler_texture, obj_glx_surface->target);
obj_glx_surface->hqscaler_texture = 0; obj_glx_surface->hqscaler_texture = 0;
} }
free(obj_glx_surface); free(obj_glx_surface);
...@@ -731,6 +737,7 @@ create_glx_surface_from_texture( ...@@ -731,6 +737,7 @@ create_glx_surface_from_texture(
obj_glx_surface->evergreen_workaround = -1; obj_glx_surface->evergreen_workaround = -1;
/* XXX: we don't support other textures than RGBA */ /* XXX: we don't support other textures than RGBA */
glEnable(target);
glBindTexture(target, texture); glBindTexture(target, texture);
if (!gl_get_texture_param(target, GL_TEXTURE_INTERNAL_FORMAT, &iformat)) if (!gl_get_texture_param(target, GL_TEXTURE_INTERNAL_FORMAT, &iformat))
goto end; goto end;
...@@ -759,6 +766,8 @@ create_glx_surface_from_texture( ...@@ -759,6 +766,8 @@ create_glx_surface_from_texture(
is_error = 0; is_error = 0;
end: end:
glBindTexture(target, 0); glBindTexture(target, 0);
glDisable(target);
if (is_error && obj_glx_surface) { if (is_error && obj_glx_surface) {
destroy_glx_surface(driver_data, obj_glx_surface); destroy_glx_surface(driver_data, obj_glx_surface);
obj_glx_surface = NULL; obj_glx_surface = NULL;
...@@ -977,9 +986,11 @@ transfer_surface_native( ...@@ -977,9 +986,11 @@ transfer_surface_native(
return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_ERROR_ALLOCATION_FAILED;
/* XXX: some algorithms work modulo the texture size */ /* XXX: some algorithms work modulo the texture size */
glEnable(obj_glx_surface->target);
glBindTexture(GL_TEXTURE_2D, obj_glx_surface->evergreen_texture); glBindTexture(GL_TEXTURE_2D, obj_glx_surface->evergreen_texture);
gl_set_texture_wrapping(GL_TEXTURE_2D, GL_REPEAT); gl_set_texture_wrapping(GL_TEXTURE_2D, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glDisable(obj_glx_surface->target);
} }
if (!obj_glx_surface->evergreen_fbo) { if (!obj_glx_surface->evergreen_fbo) {
...@@ -1137,6 +1148,7 @@ transfer_surface_native( ...@@ -1137,6 +1148,7 @@ transfer_surface_native(
needs_alternate_texture = 1; needs_alternate_texture = 1;
alternate_texture = obj_glx_surface->evergreen_texture; alternate_texture = obj_glx_surface->evergreen_texture;
glEnable(obj_glx_surface->target);
gl_bind_framebuffer_object(obj_glx_surface->evergreen_fbo); gl_bind_framebuffer_object(obj_glx_surface->evergreen_fbo);
glBindTexture(GL_TEXTURE_2D, obj_glx_surface->tx_texture); glBindTexture(GL_TEXTURE_2D, obj_glx_surface->tx_texture);
if (obj_glx_surface->evergreen_shader) { if (obj_glx_surface->evergreen_shader) {
...@@ -1164,6 +1176,7 @@ transfer_surface_native( ...@@ -1164,6 +1176,7 @@ transfer_surface_native(
if (obj_glx_surface->evergreen_shader) if (obj_glx_surface->evergreen_shader)
gl_unbind_shader_object(obj_glx_surface->evergreen_shader); gl_unbind_shader_object(obj_glx_surface->evergreen_shader);
gl_unbind_framebuffer_object(obj_glx_surface->evergreen_fbo); gl_unbind_framebuffer_object(obj_glx_surface->evergreen_fbo);
glDisable(obj_glx_surface->target);
} }
else if (needs_tx_texture) { else if (needs_tx_texture) {
needs_alternate_texture = 1; needs_alternate_texture = 1;
...@@ -1171,6 +1184,7 @@ transfer_surface_native( ...@@ -1171,6 +1184,7 @@ transfer_surface_native(
} }
if (needs_alternate_texture) { if (needs_alternate_texture) {
glEnable(obj_glx_surface->target);
gl_bind_framebuffer_object(obj_glx_surface->fbo); gl_bind_framebuffer_object(obj_glx_surface->fbo);
glBindTexture(GL_TEXTURE_2D, alternate_texture); glBindTexture(GL_TEXTURE_2D, alternate_texture);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
...@@ -1188,6 +1202,7 @@ transfer_surface_native( ...@@ -1188,6 +1202,7 @@ transfer_surface_native(
} }
glEnd(); glEnd();
gl_unbind_framebuffer_object(obj_glx_surface->fbo); gl_unbind_framebuffer_object(obj_glx_surface->fbo);
glDisable(obj_glx_surface->target);
} }
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
} }
...@@ -1229,6 +1244,8 @@ transfer_surface( ...@@ -1229,6 +1244,8 @@ transfer_surface(
if (!obj_buffer) if (!obj_buffer)
return VA_STATUS_ERROR_INVALID_BUFFER; return VA_STATUS_ERROR_INVALID_BUFFER;
glEnable(hwi->target);
GLVTable * const gl_vtable = gl_get_vtable(); GLVTable * const gl_vtable = gl_get_vtable();
unsigned int i; unsigned int i;
for (i = 0; i < hwi->num_textures; i++) { for (i = 0; i < hwi->num_textures; i++) {
...@@ -1286,6 +1303,8 @@ transfer_surface( ...@@ -1286,6 +1303,8 @@ transfer_surface(
gl_vtable->gl_active_texture(GL_TEXTURE0 + i); gl_vtable->gl_active_texture(GL_TEXTURE0 + i);
glBindTexture(hwi->target, 0); glBindTexture(hwi->target, 0);
} while (i > 0); } while (i > 0);
glDisable(hwi->target);
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
} }
...@@ -1380,6 +1399,7 @@ ensure_hqscaler_texture(void) ...@@ -1380,6 +1399,7 @@ ensure_hqscaler_texture(void)
data[i*4 + 3] = g1; data[i*4 + 3] = g1;
} }
glEnable(GL_TEXTURE_1D);
glBindTexture(GL_TEXTURE_1D, tex); glBindTexture(GL_TEXTURE_1D, tex);
gl_set_texture_scaling(GL_TEXTURE_1D, GL_NEAREST); gl_set_texture_scaling(GL_TEXTURE_1D, GL_NEAREST);
gl_set_texture_wrapping(GL_TEXTURE_1D, GL_REPEAT); gl_set_texture_wrapping(GL_TEXTURE_1D, GL_REPEAT);
...@@ -1393,13 +1413,14 @@ ensure_hqscaler_texture(void) ...@@ -1393,13 +1413,14 @@ ensure_hqscaler_texture(void)
data data
); );
glBindTexture(GL_TEXTURE_1D, 0); glBindTexture(GL_TEXTURE_1D, 0);
glDisable(GL_TEXTURE_1D);
free(data); free(data);
return tex; return tex;
/* ERRORS */ /* ERRORS */
error: error:
if (tex) if (tex)
glDeleteTextures(1, &tex); gl_destroy_texture(&tex, GL_TEXTURE_1D);
if (data) if (data)
free(data); free(data);
return 0; return 0;
...@@ -1428,6 +1449,7 @@ ensure_scaler( ...@@ -1428,6 +1449,7 @@ ensure_scaler(
} }
const GLenum target = obj_glx_surface->target; const GLenum target = obj_glx_surface->target;
glEnable(target);
switch (va_scale) { switch (va_scale) {
case VA_FILTER_SCALING_DEFAULT: case VA_FILTER_SCALING_DEFAULT:
glBindTexture(target, obj_glx_surface->texture); glBindTexture(target, obj_glx_surface->texture);
...@@ -1464,8 +1486,9 @@ ensure_scaler( ...@@ -1464,8 +1486,9 @@ ensure_scaler(
if (!obj_glx_surface->hqscaler) if (!obj_glx_surface->hqscaler)
return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_ERROR_ALLOCATION_FAILED;
break; break;
} /* end VA_FILTER_SCALING_HQ */
} }
} glDisable(target);
obj_glx_surface->va_scale = va_scale; obj_glx_surface->va_scale = va_scale;
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
...@@ -1585,6 +1608,8 @@ do_copy_surface_glx( ...@@ -1585,6 +1608,8 @@ do_copy_surface_glx(
/* Create framebuffer surface */ /* Create framebuffer surface */
if (!fbo_ensure(obj_glx_surface)) if (!fbo_ensure(obj_glx_surface))
return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_ERROR_ALLOCATION_FAILED;
glEnable(obj_glx_surface->target);
gl_bind_framebuffer_object(obj_glx_surface->fbo); gl_bind_framebuffer_object(obj_glx_surface->fbo);
/* Re-render the video frame with ProcAmp adjustments */ /* Re-render the video frame with ProcAmp adjustments */
...@@ -1645,6 +1670,7 @@ do_copy_surface_glx( ...@@ -1645,6 +1670,7 @@ do_copy_surface_glx(
status = render_subpictures(driver_data, obj_surface, &surface_rect); status = render_subpictures(driver_data, obj_surface, &surface_rect);
gl_unbind_framebuffer_object(obj_glx_surface->fbo); gl_unbind_framebuffer_object(obj_glx_surface->fbo);
glDisable(obj_glx_surface->target);
return status; return status;
} }
...@@ -2108,6 +2134,7 @@ flip_surface( ...@@ -2108,6 +2134,7 @@ flip_surface(
object_glx_surface_p const obj_glx_surface = obj_output->gl_surface; object_glx_surface_p const obj_glx_surface = obj_output->gl_surface;
/* Draw GL surface to screen */ /* Draw GL surface to screen */
glEnable(obj_glx_surface->target);
glBindTexture(obj_glx_surface->target, obj_glx_surface->texture); glBindTexture(obj_glx_surface->target, obj_glx_surface->texture);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
...@@ -2142,6 +2169,7 @@ flip_surface( ...@@ -2142,6 +2169,7 @@ flip_surface(
gl_swap_buffers(glx_output_surface_get_context(obj_output)); gl_swap_buffers(glx_output_surface_get_context(obj_output));
obj_output->render_ticks++; obj_output->render_ticks++;
glDisable(obj_glx_surface->target);
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
} }
...@@ -2213,6 +2241,7 @@ do_put_surface_glx( ...@@ -2213,6 +2241,7 @@ do_put_surface_glx(
float params[4]; float params[4];
unsigned int i; unsigned int i;
glEnable(obj_glx_surface->target);
gl_bind_framebuffer_object(obj_output->gl_surface->fbo); gl_bind_framebuffer_object(obj_output->gl_surface->fbo);
gl_vtable->gl_active_texture(GL_TEXTURE0); gl_vtable->gl_active_texture(GL_TEXTURE0);
glBindTexture(obj_glx_surface->target, obj_glx_surface->texture); glBindTexture(obj_glx_surface->target, obj_glx_surface->texture);
...@@ -2298,6 +2327,7 @@ do_put_surface_glx( ...@@ -2298,6 +2327,7 @@ do_put_surface_glx(
gl_unbind_shader_object(obj_glx_surface->hqscaler); gl_unbind_shader_object(obj_glx_surface->hqscaler);
} }
gl_unbind_framebuffer_object(obj_output->gl_surface->fbo); gl_unbind_framebuffer_object(obj_output->gl_surface->fbo);
glDisable(obj_glx_surface->target);
/* Queue surface for display */ /* Queue surface for display */
return queue_surface(driver_data, obj_output, obj_surface); return queue_surface(driver_data, obj_output, obj_surface);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment