void schro_opengl_frame_setup (SchroOpenGL *opengl, SchroFrame *frame) { int i; int components; int width, height; SchroFrameFormat format; SchroOpenGLCanvasPool *canvas_pool; SchroOpenGLCanvas *canvas; SCHRO_ASSERT (frame != NULL); SCHRO_ASSERT (SCHRO_FRAME_IS_OPENGL (frame)); components = SCHRO_FRAME_IS_PACKED (frame->format) ? 1 : 3; schro_opengl_lock (opengl); canvas_pool = schro_opengl_get_canvas_pool (opengl); for (i = 0; i < components; ++i) { format = frame->components[i].format; width = frame->components[i].width; height = frame->components[i].height; SCHRO_ASSERT (frame->format == format); canvas = schro_opengl_canvas_pool_pull_or_new (canvas_pool, opengl, format, width, height); // FIXME: hack to store custom data per frame component *((SchroOpenGLCanvas **) frame->components[i].data) = canvas; } schro_opengl_unlock (opengl); }
void schro_opengl_clear (SchroOpenGL * display) { schro_opengl_lock (display); glDepthFunc (GL_LESS); glEnable (GL_DEPTH_TEST); glClearColor (0.2, 0.2, 0.2, 1.0); glViewport (0, 0, display->win_width, display->win_height); schro_opengl_unlock (display); }
void schro_opengl_frame_inverse_iwt_transform (SchroFrame *frame, SchroParams *params) { int i; int width, height; int level; SchroOpenGL *opengl; SchroOpenGLCanvas *canvas; // FIXME: hack to store custom data per frame component canvas = *((SchroOpenGLCanvas **) frame->components[0].data); SCHRO_ASSERT (canvas != NULL); opengl = canvas->opengl; schro_opengl_lock (opengl); for (i = 0; i < 3; ++i) { // FIXME: hack to store custom data per frame component canvas = *((SchroOpenGLCanvas **) frame->components[i].data); SCHRO_ASSERT (canvas != NULL); SCHRO_ASSERT (canvas->opengl == opengl); if (i == 0) { width = params->iwt_luma_width; height = params->iwt_luma_height; } else { width = params->iwt_chroma_width; height = params->iwt_chroma_height; } for (level = params->transform_depth - 1; level >= 0; --level) { SchroFrameData frame_data; frame_data.format = frame->format; frame_data.data = frame->components[i].data; frame_data.width = width >> level; frame_data.height = height >> level; frame_data.stride = frame->components[i].stride << level; schro_opengl_wavelet_inverse_transform (&frame_data, params->wavelet_filter_index); } } schro_opengl_unlock (opengl); }
void schro_opengl_frame_cleanup (SchroFrame *frame) { int i; int components; SchroOpenGL *opengl; SchroOpenGLCanvasPool *canvas_pool; SchroOpenGLCanvas *canvas; SCHRO_ASSERT (frame != NULL); SCHRO_ASSERT (SCHRO_FRAME_IS_OPENGL (frame)); components = SCHRO_FRAME_IS_PACKED (frame->format) ? 1 : 3; // FIXME: hack to store custom data per frame component canvas = *((SchroOpenGLCanvas **) frame->components[0].data); SCHRO_ASSERT (canvas != NULL); opengl = canvas->opengl; schro_opengl_lock (opengl); canvas_pool = schro_opengl_get_canvas_pool (opengl); for (i = 0; i < components; ++i) { // FIXME: hack to store custom data per frame component canvas = *((SchroOpenGLCanvas **) frame->components[i].data); SCHRO_ASSERT (canvas != NULL); SCHRO_ASSERT (canvas->opengl == opengl); schro_opengl_canvas_pool_push_or_free (canvas_pool, canvas); } schro_opengl_unlock (opengl); }
static void schro_opengl_frame_combine_with_shader (SchroFrame *dest, SchroFrame *src, int shader_index) { int i; int width, height; SchroOpenGLCanvas *dest_canvas = NULL; SchroOpenGLCanvas *src_canvas = NULL; SchroOpenGL *opengl = NULL; SchroOpenGLShader *shader_copy_u8; SchroOpenGLShader *shader_copy_s16; SchroOpenGLShader *shader_combine; SCHRO_ASSERT (dest != NULL); SCHRO_ASSERT (src != NULL); SCHRO_ASSERT (SCHRO_FRAME_IS_OPENGL (dest)); SCHRO_ASSERT (SCHRO_FRAME_IS_OPENGL (src)); // FIXME: hack to store custom data per frame component dest_canvas = *((SchroOpenGLCanvas **) dest->components[0].data); src_canvas = *((SchroOpenGLCanvas **) src->components[0].data); SCHRO_ASSERT (dest_canvas != NULL); SCHRO_ASSERT (src_canvas != NULL); SCHRO_ASSERT (dest_canvas->opengl == src_canvas->opengl); opengl = src_canvas->opengl; schro_opengl_lock (opengl); shader_copy_u8 = schro_opengl_shader_get (opengl, SCHRO_OPENGL_SHADER_COPY_U8); shader_copy_s16 = schro_opengl_shader_get (opengl, SCHRO_OPENGL_SHADER_COPY_S16); shader_combine = schro_opengl_shader_get (opengl, shader_index); SCHRO_ASSERT (shader_copy_u8); SCHRO_ASSERT (shader_copy_s16); SCHRO_ASSERT (shader_combine); for (i = 0; i < 3; ++i) { // FIXME: hack to store custom data per frame component dest_canvas = *((SchroOpenGLCanvas **) dest->components[i].data); src_canvas = *((SchroOpenGLCanvas **) src->components[i].data); SCHRO_ASSERT (dest_canvas != NULL); SCHRO_ASSERT (src_canvas != NULL); width = MIN (dest->components[i].width, src->components[i].width); height = MIN (dest->components[i].height, src->components[i].height); schro_opengl_setup_viewport (width, height); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, dest_canvas->framebuffers[1]); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, dest_canvas->texture.handles[0]); switch (SCHRO_FRAME_FORMAT_DEPTH (dest_canvas->format)) { case SCHRO_FRAME_FORMAT_DEPTH_U8: glUseProgramObjectARB (shader_copy_u8->program); glUniform1iARB (shader_copy_u8->textures[0], 0); break; case SCHRO_FRAME_FORMAT_DEPTH_S16: glUseProgramObjectARB (shader_copy_s16->program); glUniform1iARB (shader_copy_s16->textures[0], 0); break; default: SCHRO_ASSERT (0); break; } schro_opengl_render_quad (0, 0, width, height); SCHRO_OPENGL_CHECK_ERROR glFlush (); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, dest_canvas->framebuffers[0]); glUseProgramObjectARB (shader_combine->program); //glActiveTextureARB (GL_TEXTURE0_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, dest_canvas->texture.handles[1]); glUniform1iARB (shader_combine->textures[0], 0); glActiveTextureARB (GL_TEXTURE1_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, src_canvas->texture.handles[0]); glUniform1iARB (shader_combine->textures[1], 1); glActiveTextureARB (GL_TEXTURE0_ARB); schro_opengl_render_quad (0, 0, width, height); glUseProgramObjectARB (0); SCHRO_OPENGL_CHECK_ERROR glFlush (); } #if SCHRO_OPENGL_UNBIND_TEXTURES glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0); glActiveTextureARB (GL_TEXTURE1_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0); glActiveTextureARB (GL_TEXTURE0_ARB); #endif glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); schro_opengl_unlock (opengl); }
void schro_opengl_draw_texture (SchroOpenGL * display, GLuint texture, int width, int height, int sync) { //g_return_if_fail (width > 0); //g_return_if_fail (height > 0); //g_return_if_fail (texture != None); schro_opengl_lock (display); //g_assert (display->window != None); //g_assert (display->context != NULL); //schro_opengl_update_attributes (display); #if 0 /* Doesn't work */ { int64_t ust = 1234; int64_t mst = 1234; int64_t sbc = 1234; int ret; ret = glXGetSyncValuesOML (display->display, display->window, &ust, &mst, &sbc); SCHRO_ERROR ("sync values %d %lld %lld %lld", ret, ust, mst, sbc); } #endif if (sync) { glXSwapIntervalSGI (1); } else { glXSwapIntervalSGI (0); } glViewport (0, 0, display->win_width, display->win_height); glClearColor (0.3, 0.3, 0.3, 1.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glDisable (GL_CULL_FACE); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glColor4f (1, 1, 1, 1); glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor4f (1, 0, 1, 1); schro_opengl_check_error (display, __LINE__); glBegin (GL_QUADS); glNormal3f (0, 0, -1); glTexCoord2f (width, 0); glVertex3f (1.0, 1.0, 0); glTexCoord2f (0, 0); glVertex3f (-1.0, 1.0, 0); glTexCoord2f (0, height); glVertex3f (-1.0, -1.0, 0); glTexCoord2f (width, height); glVertex3f (1.0, -1.0, 0); glEnd (); schro_opengl_check_error (display, __LINE__); glXSwapBuffers (display->display, display->window); schro_opengl_unlock (display); }
void schro_opengl_upsampled_frame_upsample (SchroFrame *upsampled_frame) { int i; int width, height; SchroOpenGLCanvas *canvases[4]; SchroOpenGL *opengl; SchroOpenGLShader *shader = NULL; SCHRO_ASSERT (upsampled_frame->frames[0] != NULL); SCHRO_ASSERT (upsampled_frame->frames[1] == NULL); SCHRO_ASSERT (upsampled_frame->frames[2] == NULL); SCHRO_ASSERT (upsampled_frame->frames[3] == NULL); SCHRO_ASSERT (SCHRO_FRAME_IS_OPENGL (upsampled_frame->frames[0])); SCHRO_ASSERT (!SCHRO_FRAME_IS_PACKED (upsampled_frame->frames[0]->format)); // FIXME: hack to store custom data per frame component canvases[0] = *((SchroOpenGLCanvas **) upsampled_frame->frames[0]->components[0].data); SCHRO_ASSERT (canvases[0] != NULL); opengl = canvases[0]->opengl; schro_opengl_lock (opengl); upsampled_frame->frames[1] = schro_opengl_frame_clone (upsampled_frame->frames[0]); upsampled_frame->frames[2] = schro_opengl_frame_clone (upsampled_frame->frames[0]); upsampled_frame->frames[3] = schro_opengl_frame_clone (upsampled_frame->frames[0]); shader = schro_opengl_shader_get (opengl, SCHRO_OPENGL_SHADER_UPSAMPLE_U8); SCHRO_ASSERT (shader != NULL); glUseProgramObjectARB (shader->program); glUniform1iARB (shader->textures[0], 0); SCHRO_OPENGL_CHECK_ERROR for (i = 0; i < 3; ++i) { // FIXME: hack to store custom data per frame component canvases[0] = *((SchroOpenGLCanvas **) upsampled_frame->frames[0]->components[i].data); canvases[1] = *((SchroOpenGLCanvas **) upsampled_frame->frames[1]->components[i].data); canvases[2] = *((SchroOpenGLCanvas **) upsampled_frame->frames[2]->components[i].data); canvases[3] = *((SchroOpenGLCanvas **) upsampled_frame->frames[3]->components[i].data); SCHRO_ASSERT (canvases[0] != NULL); SCHRO_ASSERT (canvases[1] != NULL); SCHRO_ASSERT (canvases[2] != NULL); SCHRO_ASSERT (canvases[3] != NULL); SCHRO_ASSERT (canvases[0]->opengl == opengl); SCHRO_ASSERT (canvases[1]->opengl == opengl); SCHRO_ASSERT (canvases[2]->opengl == opengl); SCHRO_ASSERT (canvases[3]->opengl == opengl); width = upsampled_frame->frames[0]->components[i].width; height = upsampled_frame->frames[0]->components[i].height; SCHRO_ASSERT (width >= 2); SCHRO_ASSERT (height >= 2); SCHRO_ASSERT (width % 2 == 0); SCHRO_ASSERT (height % 2 == 0); schro_opengl_setup_viewport (width, height); /* horizontal filter 0 -> 1 */ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, canvases[1]->framebuffers[0]); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, canvases[0]->texture.handles[0]); SCHRO_OPENGL_CHECK_ERROR #define RENDER_QUAD_HORIZONTAL(_x, _quad_width) \ schro_opengl_upsampled_frame_render_quad (shader, _x, 0, _quad_width,\ height, width, height) RENDER_QUAD_HORIZONTAL (0, 1); if (width > 2) { RENDER_QUAD_HORIZONTAL (1, 1); if (width > 4) { RENDER_QUAD_HORIZONTAL (2, 1); if (width > 6) { RENDER_QUAD_HORIZONTAL (3, 1); if (width > 8) { RENDER_QUAD_HORIZONTAL (4, width - 8); } RENDER_QUAD_HORIZONTAL (width - 4, 1); } RENDER_QUAD_HORIZONTAL (width - 3, 1); } RENDER_QUAD_HORIZONTAL (width - 2, 1); } RENDER_QUAD_HORIZONTAL (width - 1, 1); #undef RENDER_QUAD_HORIZONTAL /* vertical filter 0 -> 2 */ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, canvases[2]->framebuffers[0]); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, canvases[0]->texture.handles[0]); SCHRO_OPENGL_CHECK_ERROR #define RENDER_QUAD_VERTICAL(_y, _quad_height) \ schro_opengl_upsampled_frame_render_quad (shader, 0, _y, width,\ _quad_height, width, height) RENDER_QUAD_VERTICAL (0, 1); if (height > 2) { RENDER_QUAD_VERTICAL (1, 1); if (height > 4) { RENDER_QUAD_VERTICAL (2, 1); if (height > 6) { RENDER_QUAD_VERTICAL (3, 1); if (height > 8) { RENDER_QUAD_VERTICAL (4, height - 8); } RENDER_QUAD_VERTICAL (height - 4, 1); } RENDER_QUAD_VERTICAL (height - 3, 1); } RENDER_QUAD_VERTICAL (height - 2, 1); } RENDER_QUAD_VERTICAL (height - 1, 1); #undef RENDER_QUAD_VERTICAL /* horizontal filter 2 -> 3 */ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, canvases[3]->framebuffers[0]); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, canvases[2]->texture.handles[0]); SCHRO_OPENGL_CHECK_ERROR #define RENDER_QUAD_HORIZONTAL(_x, _quad_width) \ schro_opengl_upsampled_frame_render_quad (shader, _x, 0, _quad_width,\ height, width, height) RENDER_QUAD_HORIZONTAL (0, 1); if (width > 2) { RENDER_QUAD_HORIZONTAL (1, 1); if (width > 4) { RENDER_QUAD_HORIZONTAL (2, 1); if (width > 6) { RENDER_QUAD_HORIZONTAL (3, 1); if (width > 8) { RENDER_QUAD_HORIZONTAL (4, width - 8); } RENDER_QUAD_HORIZONTAL (width - 4, 1); } RENDER_QUAD_HORIZONTAL (width - 3, 1); } RENDER_QUAD_HORIZONTAL (width - 2, 1); } RENDER_QUAD_HORIZONTAL (width - 1, 1); #undef RENDER_QUAD_HORIZONTAL } glUseProgramObjectARB (0); #if SCHRO_OPENGL_UNBIND_TEXTURES glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0); #endif glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); schro_opengl_unlock (opengl); }