[vlc-devel] [PATCH] opengl: enables shaders for macos opengl.
Laurent Aimar
fenrir at elivagar.org
Tue Sep 13 20:50:53 CEST 2011
Hi,
On Tue, Sep 13, 2011 at 08:08:18PM +0200, Sebastien Zwickert wrote:
> A patch in attachment that enables shaders for mac opengl.
> diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
> index 236b0d2..73396de 100644
> --- a/modules/video_output/opengl.c
> +++ b/modules/video_output/opengl.c
> @@ -166,12 +166,19 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
> /* Load extensions */
> bool supports_fp = false;
> if (HasExtension(extensions, "GL_ARB_fragment_program")) {
> +#if !defined(MACOS_OPENGL)
> vgl->GenProgramsARB = (PFNGLGENPROGRAMSARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glGenProgramsARB");
> vgl->BindProgramARB = (PFNGLBINDPROGRAMARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glBindProgramARB");
> vgl->ProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glProgramStringARB");
> vgl->DeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteProgramsARB");
> vgl->ProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glProgramLocalParameter4fvARB");
> -
> +#else
> + vgl->GenProgramsARB = glGenProgramsARB;
> + vgl->BindProgramARB = glBindProgramARB;
> + vgl->ProgramStringARB = glProgramStringARB;
> + vgl->DeleteProgramsARB = glDeleteProgramsARB;
> + vgl->ProgramLocalParameter4fvARB = glProgramLocalParameter4fvARB;
> +#endif
> supports_fp = vgl->GenProgramsARB &&
> vgl->BindProgramARB &&
> vgl->ProgramStringARB &&
> @@ -182,9 +189,13 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
> bool supports_multitexture = false;
> GLint max_texture_units = 0;
> if (HasExtension(extensions, "GL_ARB_multitexture")) {
> +#if !defined(MACOS_OPENGL)
> vgl->ActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glActiveTextureARB");
> vgl->MultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC)vlc_gl_GetProcAddress(vgl->gl, "glMultiTexCoord2fARB");
> -
> +#else
> + vgl->ActiveTextureARB = glActiveTextureARB;
> + vgl->MultiTexCoord2fARB = glMultiTexCoord2fARB;
> +#endif
I would prefer that the macosx opengl provider implements
it through the vlc_gl_t::getProcAddress() callback. It would reduce
the number #ifdef that are cluttering the code.
> supports_multitexture = vgl->ActiveTextureARB &&
> vgl->MultiTexCoord2fARB;
> if (supports_multitexture)
> @@ -209,15 +220,11 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
> vgl->tex_internal = GL_RGB;
> vgl->tex_type = GL_UNSIGNED_SHORT_5_6_5;
> #elif defined(MACOS_OPENGL)
> -# if defined(WORDS_BIGENDIAN)
> - vgl->fmt.i_chroma = VLC_CODEC_YUYV;
> -# else
> - vgl->fmt.i_chroma = VLC_CODEC_UYVY;
> -# endif
> - vgl->tex_target = GL_TEXTURE_RECTANGLE_EXT;
> - vgl->tex_format = GL_YCBCR_422_APPLE;
> + vgl->fmt.i_chroma = VLC_CODEC_RGB32;
> + vgl->tex_target = GL_TEXTURE_2D;
> + vgl->tex_format = GL_BGRA;
> vgl->tex_internal = GL_RGBA;
> - vgl->tex_type = GL_UNSIGNED_SHORT_8_8_APPLE;
> + vgl->tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
> #else
> vgl->fmt.i_chroma = VLC_CODEC_RGB32;
> # if defined(WORDS_BIGENDIAN)
> @@ -395,7 +402,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
> *fmt = vgl->fmt;
> if (subpicture_chromas) {
> *subpicture_chromas = NULL;
> -#if !defined(MACOS_OPENGL) && !USE_OPENGL_ES
> +#if !USE_OPENGL_ES
> if (supports_npot)
> *subpicture_chromas = gl_subpicture_chromas;
> #endif
> @@ -434,12 +441,6 @@ struct picture_sys_t {
> GLuint *texture;
> };
>
> -/* Small helper */
> -static inline GLuint PictureGetTexture(picture_t *picture)
> -{
> - return *picture->p_sys->texture;
> -}
> -
> static int PictureLock(picture_t *picture)
> {
> if (!picture->p_sys)
> @@ -447,12 +448,17 @@ static int PictureLock(picture_t *picture)
>
> vout_display_opengl_t *vgl = picture->p_sys->vgl;
> if (!vlc_gl_Lock(vgl->gl)) {
> - glBindTexture(vgl->tex_target, PictureGetTexture(picture));
> - glPixelStorei(GL_UNPACK_ROW_LENGTH, picture->p->i_pitch / picture->p->i_pixel_pitch);
> - glTexSubImage2D(vgl->tex_target, 0,
> - 0, 0, vgl->fmt.i_width, vgl->fmt.i_height,
> - vgl->tex_format, vgl->tex_type, picture->p[0].p_pixels);
> -
> + for (unsigned j = 0; j < vgl->chroma->plane_count; j++) {
> + if (vgl->use_multitexture)
> + vgl->ActiveTextureARB(GL_TEXTURE0_ARB + j);
> + glBindTexture(vgl->tex_target, vgl->texture[0][j]);
> + glPixelStorei(GL_UNPACK_ROW_LENGTH, picture->p[j].i_pitch / picture->p[j].i_pixel_pitch);
> + glTexSubImage2D(vgl->tex_target, 0,
> + 0, 0,
> + vgl->fmt.i_width * vgl->chroma->p[j].w.num / vgl->chroma->p[j].w.den,
> + vgl->fmt.i_height * vgl->chroma->p[j].h.num / vgl->chroma->p[j].h.den,
> + vgl->tex_format, vgl->tex_type, picture->p[j].p_pixels);
> + }
> vlc_gl_Unlock(vgl->gl);
> }
> return VLC_SUCCESS;
> @@ -579,7 +585,11 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
>
> #ifdef MACOS_OPENGL
> /* Bind to the texture for drawing */
> - glBindTexture(vgl->tex_target, PictureGetTexture(picture));
> + for (unsigned j = 0; j < vgl->chroma->plane_count; j++) {
> + if (vgl->use_multitexture)
> + vgl->ActiveTextureARB(GL_TEXTURE0_ARB + j);
> + glBindTexture(vgl->tex_target, vgl->texture[0][j]);
> + }
> #else
> /* Update the texture */
> for (unsigned j = 0; j < vgl->chroma->plane_count; j++) {
> @@ -739,13 +749,11 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
>
> glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
> #else
> -#if !defined(MACOS_OPENGL)
> for (unsigned j = 0; j < vgl->chroma->plane_count; j++) {
> if (vgl->use_multitexture)
> vgl->ActiveTextureARB(GL_TEXTURE0_ARB + j);
> glBindTexture(vgl->tex_target, vgl->texture[0][j]);
> }
> -#endif
Couldn't we simply remove all the specific macosx part? Is there
a performance loss?
Regards,
--
fenrir
More information about the vlc-devel
mailing list