2007-06-26 16:33:43 +00:00
|
|
|
/*
|
2009-02-08 03:27:30 +00:00
|
|
|
* X11/OpenGL interface
|
2001-10-07 21:35:59 +00:00
|
|
|
* based on video_out_x11 by Aaron Holtzman,
|
|
|
|
* and WS opengl window manager by Pontscho/Fresh!
|
2009-02-08 03:27:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-10-07 21:35:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2003-10-12 14:42:27 +00:00
|
|
|
#include "mp_msg.h"
|
2005-09-13 16:16:13 +00:00
|
|
|
#include "subopt-helper.h"
|
2001-10-07 21:35:59 +00:00
|
|
|
#include "video_out.h"
|
|
|
|
#include "video_out_internal.h"
|
2002-11-06 23:54:29 +00:00
|
|
|
#include "sub.h"
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2006-06-17 19:43:13 +00:00
|
|
|
#include "gl_common.h"
|
|
|
|
#include "aspect.h"
|
2004-05-01 19:37:09 +00:00
|
|
|
|
2004-07-02 16:18:24 +00:00
|
|
|
#undef TEXTUREFORMAT_ALWAYS
|
2007-12-16 23:50:05 +00:00
|
|
|
#ifdef __APPLE__
|
2004-07-17 14:18:29 +00:00
|
|
|
#define TEXTUREFORMAT_ALWAYS GL_RGBA8
|
2004-07-02 16:18:24 +00:00
|
|
|
#endif
|
2003-05-20 19:30:46 +00:00
|
|
|
|
2005-09-25 16:33:03 +00:00
|
|
|
//! force texture height, useful for debugging
|
|
|
|
#define TEXTURE_HEIGHT 128
|
|
|
|
#undef TEXTURE_HEIGHT
|
|
|
|
//! force texture width, useful for debugging
|
|
|
|
#define TEXTURE_WIDTH 128
|
|
|
|
#undef TEXTURE_WIDTH
|
|
|
|
|
2007-12-02 14:06:03 +00:00
|
|
|
static const vo_info_t info =
|
2001-10-07 21:35:59 +00:00
|
|
|
{
|
2007-06-26 16:33:43 +00:00
|
|
|
"X11 (OpenGL) - multiple textures version",
|
|
|
|
"gl2",
|
|
|
|
"Arpad Gereoffy & Sven Goethel",
|
|
|
|
""
|
2001-10-07 21:35:59 +00:00
|
|
|
};
|
|
|
|
|
2007-12-02 14:39:15 +00:00
|
|
|
const LIBVO_EXTERN(gl2)
|
2002-11-11 15:22:10 +00:00
|
|
|
|
2001-10-07 21:35:59 +00:00
|
|
|
/* local data */
|
|
|
|
static unsigned char *ImageData=NULL;
|
|
|
|
|
2009-12-08 06:42:46 +00:00
|
|
|
static MPGLContext glctx;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
static uint32_t image_width;
|
|
|
|
static uint32_t image_height;
|
|
|
|
static uint32_t image_format;
|
|
|
|
static uint32_t image_bpp;
|
|
|
|
static uint32_t image_bytes;
|
|
|
|
|
2003-08-31 22:27:10 +00:00
|
|
|
static int int_pause;
|
|
|
|
|
2001-10-07 21:35:59 +00:00
|
|
|
static uint32_t texture_width;
|
|
|
|
static uint32_t texture_height;
|
2004-05-08 23:53:20 +00:00
|
|
|
static int texnumx, texnumy, raw_line_len;
|
2007-06-26 15:51:49 +00:00
|
|
|
static int texdirty;
|
2004-10-03 21:42:31 +00:00
|
|
|
static struct TexSquare * texgrid = NULL;
|
2005-09-14 22:08:04 +00:00
|
|
|
static GLuint fragprog;
|
|
|
|
static GLuint lookupTex;
|
2001-10-19 10:09:29 +00:00
|
|
|
static GLint gl_internal_format;
|
|
|
|
static int rgb_sz, r_sz, g_sz, b_sz, a_sz;
|
2005-08-25 12:45:57 +00:00
|
|
|
static GLenum gl_bitmap_format;
|
|
|
|
static GLenum gl_bitmap_type;
|
2001-10-19 10:09:29 +00:00
|
|
|
static int isGL12 = GL_FALSE;
|
|
|
|
|
|
|
|
static int gl_bilinear=1;
|
|
|
|
static int gl_antialias=0;
|
2005-09-14 22:08:04 +00:00
|
|
|
static int use_yuv;
|
2009-12-30 11:32:24 +00:00
|
|
|
static int is_yuv;
|
2005-09-13 16:16:13 +00:00
|
|
|
static int use_glFinish;
|
2001-10-19 10:09:29 +00:00
|
|
|
|
|
|
|
static void (*draw_alpha_fnc)
|
|
|
|
(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2003-08-31 22:27:10 +00:00
|
|
|
|
2001-10-07 21:35:59 +00:00
|
|
|
/* The squares that are tiled to make up the game screen polygon */
|
|
|
|
|
|
|
|
struct TexSquare
|
|
|
|
{
|
|
|
|
GLubyte *texture;
|
|
|
|
GLuint texobj;
|
2005-09-14 22:08:04 +00:00
|
|
|
GLuint uvtexobjs[2];
|
2005-08-14 13:44:14 +00:00
|
|
|
GLfloat fx, fy, fw, fh;
|
2001-10-07 21:35:59 +00:00
|
|
|
};
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static GLint getInternalFormat(void)
|
2004-12-03 00:11:28 +00:00
|
|
|
{
|
2009-12-08 06:42:46 +00:00
|
|
|
switch (glctx.type) {
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifdef CONFIG_GL_WIN32
|
2009-12-08 06:42:46 +00:00
|
|
|
case GLTYPE_W32:
|
|
|
|
{
|
2004-12-03 00:11:28 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2009-11-21 22:27:40 +00:00
|
|
|
HDC vo_hdc = vo_w32_get_dc(vo_w32_window);
|
2004-12-03 00:11:28 +00:00
|
|
|
int pf = GetPixelFormat(vo_hdc);
|
|
|
|
if (!DescribePixelFormat(vo_hdc, pf, sizeof pfd, &pfd)) {
|
|
|
|
r_sz = g_sz = b_sz = a_sz = 0;
|
|
|
|
} else {
|
|
|
|
r_sz = pfd.cRedBits;
|
|
|
|
g_sz = pfd.cGreenBits;
|
|
|
|
b_sz = pfd.cBlueBits;
|
|
|
|
a_sz = pfd.cAlphaBits;
|
|
|
|
}
|
2009-11-21 22:27:40 +00:00
|
|
|
vo_w32_release_dc(vo_w32_window, vo_hdc);
|
2009-12-08 06:42:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-12-03 00:11:28 +00:00
|
|
|
#endif
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifdef CONFIG_GL_X11
|
2009-12-08 06:42:46 +00:00
|
|
|
case GLTYPE_X11:
|
|
|
|
if (glXGetConfig(mDisplay, glctx.vinfo.x11, GLX_RED_SIZE, &r_sz) != 0) r_sz = 0;
|
|
|
|
if (glXGetConfig(mDisplay, glctx.vinfo.x11, GLX_GREEN_SIZE, &g_sz) != 0) g_sz = 0;
|
|
|
|
if (glXGetConfig(mDisplay, glctx.vinfo.x11, GLX_BLUE_SIZE, &b_sz) != 0) b_sz = 0;
|
|
|
|
if (glXGetConfig(mDisplay, glctx.vinfo.x11, GLX_ALPHA_SIZE, &a_sz) != 0) a_sz = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2004-12-03 00:11:28 +00:00
|
|
|
|
|
|
|
rgb_sz=r_sz+g_sz+b_sz;
|
|
|
|
if(rgb_sz<=0) rgb_sz=24;
|
|
|
|
|
|
|
|
#ifdef TEXTUREFORMAT_ALWAYS
|
|
|
|
return TEXTUREFORMAT_ALWAYS;
|
|
|
|
#else
|
|
|
|
if(r_sz==3 && g_sz==3 && b_sz==2 && a_sz==0)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_R3_G3_B2;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==4 && g_sz==4 && b_sz==4 && a_sz==0)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGB4;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==5 && g_sz==5 && b_sz==5 && a_sz==0)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGB5;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==8 && g_sz==8 && b_sz==8 && a_sz==0)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGB8;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==10 && g_sz==10 && b_sz==10 && a_sz==0)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGB10;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==2 && g_sz==2 && b_sz==2 && a_sz==2)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGBA2;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==4 && g_sz==4 && b_sz==4 && a_sz==4)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGBA4;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==5 && g_sz==5 && b_sz==5 && a_sz==1)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGB5_A1;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==8 && g_sz==8 && b_sz==8 && a_sz==8)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGBA8;
|
2004-12-03 00:11:28 +00:00
|
|
|
if(r_sz==10 && g_sz==10 && b_sz==10 && a_sz==2)
|
2007-06-26 16:33:43 +00:00
|
|
|
return GL_RGB10_A2;
|
2004-12-03 00:11:28 +00:00
|
|
|
#endif
|
|
|
|
return GL_RGB;
|
|
|
|
}
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static int initTextures(void)
|
2001-10-07 21:35:59 +00:00
|
|
|
{
|
|
|
|
struct TexSquare *tsq=0;
|
2005-08-14 13:44:14 +00:00
|
|
|
GLfloat texpercx, texpercy;
|
2005-08-14 19:24:49 +00:00
|
|
|
int s;
|
2001-10-07 21:35:59 +00:00
|
|
|
int x=0, y=0;
|
|
|
|
GLint format=0;
|
|
|
|
|
2005-08-14 19:36:34 +00:00
|
|
|
// textures smaller than 64x64 might not be supported
|
|
|
|
s=64;
|
2005-08-14 18:36:01 +00:00
|
|
|
while (s<image_width)
|
2005-08-14 13:44:14 +00:00
|
|
|
s*=2;
|
2001-10-07 21:35:59 +00:00
|
|
|
texture_width=s;
|
|
|
|
|
2005-08-14 19:36:34 +00:00
|
|
|
s=64;
|
2005-08-14 18:36:01 +00:00
|
|
|
while (s<image_height)
|
2005-08-14 13:44:14 +00:00
|
|
|
s*=2;
|
2001-10-07 21:35:59 +00:00
|
|
|
texture_height=s;
|
|
|
|
|
2009-12-30 11:32:24 +00:00
|
|
|
if (!is_yuv)
|
2004-12-03 00:11:28 +00:00
|
|
|
gl_internal_format = getInternalFormat();
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
/* Test the max texture size */
|
2007-06-26 16:33:43 +00:00
|
|
|
do {
|
2001-10-07 21:35:59 +00:00
|
|
|
glTexImage2D (GL_PROXY_TEXTURE_2D, 0,
|
2007-06-26 16:33:43 +00:00
|
|
|
gl_internal_format,
|
|
|
|
texture_width, texture_height,
|
|
|
|
0, gl_bitmap_format, gl_bitmap_type, NULL);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
glGetTexLevelParameteriv
|
|
|
|
(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
|
|
|
|
|
2001-10-19 10:09:29 +00:00
|
|
|
if (format != gl_internal_format)
|
2001-10-07 21:35:59 +00:00
|
|
|
{
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg (MSGT_VO, MSGL_V, "[gl2] Needed texture [%dx%d] too big, trying ",
|
2007-06-26 16:33:43 +00:00
|
|
|
texture_height, texture_width);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
if (texture_width > texture_height)
|
2005-08-14 13:44:14 +00:00
|
|
|
texture_width /= 2;
|
2001-10-07 21:35:59 +00:00
|
|
|
else
|
2005-08-14 13:44:14 +00:00
|
|
|
texture_height /= 2;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg (MSGT_VO, MSGL_V, "[%dx%d] !\n", texture_height, texture_width);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
if(texture_width < 64 || texture_height < 64) {
|
|
|
|
mp_msg (MSGT_VO, MSGL_FATAL, "[gl2] Give up .. usable texture size not avaiable, or texture config error !\n");
|
|
|
|
return -1;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-19 10:09:29 +00:00
|
|
|
while (format != gl_internal_format && texture_width > 1 && texture_height > 1);
|
2005-09-25 16:33:03 +00:00
|
|
|
#ifdef TEXTURE_WIDTH
|
|
|
|
texture_width = TEXTURE_WIDTH;
|
|
|
|
#endif
|
|
|
|
#ifdef TEXTURE_HEIGHT
|
|
|
|
texture_height = TEXTURE_HEIGHT;
|
|
|
|
#endif
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
texnumx = image_width / texture_width;
|
|
|
|
if ((image_width % texture_width) > 0)
|
|
|
|
texnumx++;
|
|
|
|
|
|
|
|
texnumy = image_height / texture_height;
|
|
|
|
if ((image_height % texture_height) > 0)
|
|
|
|
texnumy++;
|
|
|
|
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[gl2] Creating %dx%d textures of size %dx%d ...\n",
|
2007-06-26 16:33:43 +00:00
|
|
|
texnumx, texnumy, texture_width,texture_height);
|
2001-10-19 10:09:29 +00:00
|
|
|
|
2001-10-07 21:35:59 +00:00
|
|
|
/* Allocate the texture memory */
|
|
|
|
|
|
|
|
texpercx = (GLfloat) texture_width / (GLfloat) image_width;
|
|
|
|
texpercy = (GLfloat) texture_height / (GLfloat) image_height;
|
|
|
|
|
2004-10-03 21:42:31 +00:00
|
|
|
if (texgrid)
|
|
|
|
free(texgrid);
|
2007-06-26 15:51:43 +00:00
|
|
|
texgrid = calloc (texnumx * texnumy, sizeof (struct TexSquare));
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2004-05-08 23:53:20 +00:00
|
|
|
raw_line_len = image_width * image_bytes;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg (MSGT_VO, MSGL_DBG2, "[gl2] texture-usage %d*width=%d, %d*height=%d\n",
|
2007-06-26 16:33:43 +00:00
|
|
|
(int) texnumx, (int) texture_width, (int) texnumy,
|
|
|
|
(int) texture_height);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2005-08-14 13:44:14 +00:00
|
|
|
tsq = texgrid;
|
2007-06-26 16:33:43 +00:00
|
|
|
for (y = 0; y < texnumy; y++) {
|
|
|
|
for (x = 0; x < texnumx; x++) {
|
2005-08-14 13:44:14 +00:00
|
|
|
tsq->fx = x * texpercx;
|
|
|
|
tsq->fy = y * texpercy;
|
|
|
|
tsq->fw = texpercx;
|
|
|
|
tsq->fh = texpercy;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
tsq->texobj=0;
|
2005-09-14 22:08:04 +00:00
|
|
|
tsq->uvtexobjs[0] = tsq->uvtexobjs[1] = 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
glGenTextures (1, &(tsq->texobj));
|
|
|
|
|
|
|
|
glBindTexture (GL_TEXTURE_2D, tsq->texobj);
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv) {
|
2005-09-14 22:08:04 +00:00
|
|
|
glGenTextures(2, tsq->uvtexobjs);
|
|
|
|
ActiveTexture(GL_TEXTURE1);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, tsq->uvtexobjs[0]);
|
|
|
|
ActiveTexture(GL_TEXTURE2);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, tsq->uvtexobjs[1]);
|
|
|
|
ActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2008-09-20 17:48:01 +00:00
|
|
|
glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format, gl_bitmap_type, GL_LINEAR,
|
2005-08-14 13:44:14 +00:00
|
|
|
texture_width, texture_height, 0);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv) {
|
|
|
|
int xs, ys;
|
|
|
|
mp_get_chroma_shift(image_format, &xs, &ys);
|
2005-09-14 22:08:04 +00:00
|
|
|
ActiveTexture(GL_TEXTURE1);
|
2008-09-20 17:48:01 +00:00
|
|
|
glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format, gl_bitmap_type, GL_LINEAR,
|
2009-12-30 11:32:24 +00:00
|
|
|
texture_width >> xs, texture_height >> ys, 128);
|
2005-09-14 22:08:04 +00:00
|
|
|
ActiveTexture(GL_TEXTURE2);
|
2008-09-20 17:48:01 +00:00
|
|
|
glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format, gl_bitmap_type, GL_LINEAR,
|
2009-12-30 11:32:24 +00:00
|
|
|
texture_width >> xs, texture_height >> ys, 128);
|
2005-09-14 22:08:04 +00:00
|
|
|
ActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2005-08-14 13:44:14 +00:00
|
|
|
tsq++;
|
2007-06-26 16:33:43 +00:00
|
|
|
} /* for all texnumx */
|
2001-10-07 21:35:59 +00:00
|
|
|
} /* for all texnumy */
|
2007-06-26 16:33:43 +00:00
|
|
|
|
2003-08-14 01:15:41 +00:00
|
|
|
return 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 10:09:29 +00:00
|
|
|
static void resetTexturePointers(unsigned char *imageSource)
|
|
|
|
{
|
2004-05-08 23:53:20 +00:00
|
|
|
unsigned char *texdata_start, *line_start;
|
|
|
|
struct TexSquare *tsq = texgrid;
|
2001-10-19 10:09:29 +00:00
|
|
|
int x=0, y=0;
|
|
|
|
|
2004-05-08 23:53:20 +00:00
|
|
|
line_start = (unsigned char *) imageSource;
|
2001-10-19 10:09:29 +00:00
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
for (y = 0; y < texnumy; y++) {
|
2004-05-08 23:53:20 +00:00
|
|
|
texdata_start = line_start;
|
2007-06-26 16:33:43 +00:00
|
|
|
for (x = 0; x < texnumx; x++) {
|
2004-05-08 23:53:20 +00:00
|
|
|
tsq->texture = texdata_start;
|
|
|
|
texdata_start += texture_width * image_bytes;
|
|
|
|
tsq++;
|
2007-06-26 16:33:43 +00:00
|
|
|
} /* for all texnumx */
|
2004-05-08 23:53:20 +00:00
|
|
|
line_start += texture_height * raw_line_len;
|
2001-10-19 10:09:29 +00:00
|
|
|
} /* for all texnumy */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_bilinear (int val)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
if(val>=0)
|
2007-06-26 16:33:43 +00:00
|
|
|
gl_bilinear = val;
|
|
|
|
else
|
|
|
|
gl_bilinear++;
|
2001-10-19 10:09:29 +00:00
|
|
|
|
|
|
|
gl_bilinear=gl_bilinear%2;
|
|
|
|
/* no mipmap yet .. */
|
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
for (y = 0; y < texnumy; y++) {
|
|
|
|
for (x = 0; x < texnumx; x++) {
|
|
|
|
glBindTexture (GL_TEXTURE_2D, texgrid[y * texnumx + x].texobj);
|
|
|
|
|
|
|
|
switch (gl_bilinear) {
|
|
|
|
case 0:
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] bilinear off\n");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] bilinear linear\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] bilinear mipmap nearest\n");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] bilinear mipmap linear\n");
|
|
|
|
break;
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
2007-06-26 16:33:43 +00:00
|
|
|
}
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_antialias (int val)
|
|
|
|
{
|
|
|
|
gl_antialias=val;
|
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
if (gl_antialias) {
|
2001-10-19 10:09:29 +00:00
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
glEnable (GL_POLYGON_SMOOTH);
|
|
|
|
glEnable (GL_LINE_SMOOTH);
|
|
|
|
glEnable (GL_POINT_SMOOTH);
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] antialiasing on\n");
|
2007-06-26 16:33:43 +00:00
|
|
|
} else {
|
2001-10-19 10:09:29 +00:00
|
|
|
glShadeModel (GL_FLAT);
|
|
|
|
glDisable (GL_POLYGON_SMOOTH);
|
|
|
|
glDisable (GL_LINE_SMOOTH);
|
|
|
|
glDisable (GL_POINT_SMOOTH);
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] antialiasing off\n");
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static void drawTextureDisplay (void)
|
2001-10-07 21:35:59 +00:00
|
|
|
{
|
2005-08-14 13:44:14 +00:00
|
|
|
struct TexSquare *square = texgrid;
|
2007-06-26 15:01:09 +00:00
|
|
|
int x, y;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
glColor3f(1.0,1.0,1.0);
|
|
|
|
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv)
|
2005-09-14 22:08:04 +00:00
|
|
|
glEnableYUVConversion(GL_TEXTURE_2D, use_yuv);
|
2007-06-26 16:33:43 +00:00
|
|
|
for (y = 0; y < texnumy; y++) {
|
2007-06-26 15:51:49 +00:00
|
|
|
int thish = texture_height;
|
|
|
|
if (y == texnumy - 1 && image_height % texture_height)
|
|
|
|
thish = image_height % texture_height;
|
2007-06-26 16:33:43 +00:00
|
|
|
for (x = 0; x < texnumx; x++) {
|
2007-06-26 15:51:49 +00:00
|
|
|
int thisw = texture_width;
|
|
|
|
if (x == texnumx - 1 && image_width % texture_width)
|
|
|
|
thisw = image_width % texture_width;
|
2001-10-07 21:35:59 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, square->texobj);
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv) {
|
2005-09-14 22:08:04 +00:00
|
|
|
ActiveTexture(GL_TEXTURE1);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, square->uvtexobjs[0]);
|
|
|
|
ActiveTexture(GL_TEXTURE2);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, square->uvtexobjs[1]);
|
|
|
|
ActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2007-06-26 15:51:49 +00:00
|
|
|
if (texdirty) {
|
2007-06-26 16:33:43 +00:00
|
|
|
glUploadTex(GL_TEXTURE_2D, gl_bitmap_format, gl_bitmap_type,
|
|
|
|
square->texture, image_width * image_bytes,
|
|
|
|
0, 0, thisw, thish, 0);
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2005-08-14 13:44:14 +00:00
|
|
|
glDrawTex(square->fx, square->fy, square->fw, square->fh,
|
|
|
|
0, 0, texture_width, texture_height,
|
2005-12-18 12:04:08 +00:00
|
|
|
texture_width, texture_height,
|
2009-12-30 11:32:24 +00:00
|
|
|
0, is_yuv, 0);
|
2005-08-14 13:44:14 +00:00
|
|
|
square++;
|
2001-10-07 21:35:59 +00:00
|
|
|
} /* for all texnumx */
|
|
|
|
} /* for all texnumy */
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv)
|
2005-09-14 22:08:04 +00:00
|
|
|
glDisableYUVConversion(GL_TEXTURE_2D, use_yuv);
|
2007-06-26 15:51:49 +00:00
|
|
|
texdirty = 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 14:10:38 +00:00
|
|
|
static void resize(int x,int y){
|
|
|
|
mp_msg(MSGT_VO,MSGL_V,"[gl2] Resize: %dx%d\n",x,y);
|
2009-08-27 18:42:08 +00:00
|
|
|
if(aspect_scaling()) {
|
2007-06-26 16:33:43 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2009-08-27 18:42:08 +00:00
|
|
|
aspect(&x, &y, A_WINZOOM);
|
|
|
|
panscan_calc_windowed();
|
2009-08-27 14:10:38 +00:00
|
|
|
x += vo_panscan_x;
|
|
|
|
y += vo_panscan_y;
|
2009-08-27 14:12:38 +00:00
|
|
|
glViewport( (vo_dwidth-x)/2, (vo_dheight-y)/2, x, y);
|
2007-06-26 16:33:43 +00:00
|
|
|
} else {
|
|
|
|
//aspect(x, y, A_NOZOOM);
|
|
|
|
if (WinID >= 0) {
|
2009-08-27 14:10:38 +00:00
|
|
|
int top = 0, left = 0, w = x, h = y;
|
2007-06-26 16:33:43 +00:00
|
|
|
geometry(&top, &left, &w, &h, vo_screenwidth, vo_screenheight);
|
|
|
|
glViewport(top, left, w, h);
|
|
|
|
} else
|
2009-08-27 14:10:38 +00:00
|
|
|
glViewport( 0, 0, x, y );
|
2003-09-21 11:27:11 +00:00
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho (0, 1, 1, 0, -1.0, 1.0);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
2001-10-19 10:09:29 +00:00
|
|
|
static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
|
|
|
vo_draw_alpha_rgb32(w,h,src,srca,stride,ImageData+4*(y0*image_width+x0),4*image_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
|
|
|
vo_draw_alpha_rgb24(w,h,src,srca,stride,ImageData+3*(y0*image_width+x0),3*image_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
|
|
|
vo_draw_alpha_rgb16(w,h,src,srca,stride,ImageData+2*(y0*image_width+x0),2*image_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
|
|
|
vo_draw_alpha_rgb15(w,h,src,srca,stride,ImageData+2*(y0*image_width+x0),2*image_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
|
|
|
}
|
|
|
|
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifdef CONFIG_GL_WIN32
|
2003-09-19 14:33:51 +00:00
|
|
|
|
|
|
|
static int config_w32(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
|
2007-06-26 16:33:43 +00:00
|
|
|
if (!vo_w32_config(d_width, d_height, flags))
|
|
|
|
return -1;
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
return 0;
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2002-10-29 20:27:47 +00:00
|
|
|
static int choose_glx_visual(Display *dpy, int scr, XVisualInfo *res_vi)
|
|
|
|
{
|
2007-06-26 16:33:43 +00:00
|
|
|
XVisualInfo template, *vi_list;
|
|
|
|
int vi_num, i, best_i, best_weight;
|
|
|
|
|
|
|
|
template.screen = scr;
|
|
|
|
vi_list = XGetVisualInfo(dpy, VisualScreenMask, &template, &vi_num);
|
|
|
|
if (!vi_list) return -1;
|
|
|
|
best_weight = 1000000; best_i=0;
|
|
|
|
for (i = 0; i < vi_num; i++) {
|
|
|
|
int val, res, w = 0;
|
|
|
|
/* of course, the visual must support OpenGL rendering... */
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_USE_GL, &val);
|
|
|
|
if (res || val == False) continue;
|
|
|
|
/* also it must be doublebuffered ... */
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_DOUBLEBUFFER, &val);
|
|
|
|
if (res || val == False) continue;
|
|
|
|
/* furthermore it must be RGBA (not color indexed) ... */
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_RGBA, &val);
|
|
|
|
if (res || val == False) continue;
|
|
|
|
/* prefer less depth buffer size, */
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_DEPTH_SIZE, &val);
|
|
|
|
if (res) continue;
|
|
|
|
w += val*2;
|
|
|
|
/* stencil buffer size */
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_STENCIL_SIZE, &val);
|
|
|
|
if (res) continue;
|
|
|
|
w += val*2;
|
|
|
|
/* and colorbuffer alpha size */
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_ALPHA_SIZE, &val);
|
|
|
|
if (res) continue;
|
|
|
|
w += val;
|
|
|
|
/* and finally, prefer DirectColor-ed visuals to allow color corrections */
|
|
|
|
if (vi_list[i].class != DirectColor) w += 100;
|
|
|
|
|
|
|
|
// avoid bad-looking visual with less that 8bit per color
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_RED_SIZE, &val);
|
|
|
|
if (res) continue;
|
|
|
|
if (val < 8) w += 50;
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_GREEN_SIZE, &val);
|
|
|
|
if (res) continue;
|
|
|
|
if (val < 8) w += 70;
|
|
|
|
res = glXGetConfig(dpy, vi_list + i, GLX_BLUE_SIZE, &val);
|
|
|
|
if (res) continue;
|
|
|
|
if (val < 8) w += 50;
|
|
|
|
|
|
|
|
if (w < best_weight) {
|
|
|
|
best_weight = w;
|
|
|
|
best_i = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best_weight < 1000000) *res_vi = vi_list[best_i];
|
|
|
|
XFree(vi_list);
|
|
|
|
return (best_weight < 1000000) ? 0 : -1;
|
2002-10-29 20:27:47 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 16:18:24 +00:00
|
|
|
static int config_glx(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
|
2007-06-27 10:26:13 +00:00
|
|
|
XVisualInfo *vinfo, vinfo_buf;
|
2007-06-26 16:33:43 +00:00
|
|
|
vinfo = choose_glx_visual(mDisplay,mScreen,&vinfo_buf) < 0 ? NULL : &vinfo_buf;
|
|
|
|
if (vinfo == NULL) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "[gl2] no GLX support present\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2007-06-27 10:26:13 +00:00
|
|
|
vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height,
|
|
|
|
flags, vo_x11_create_colormap(vinfo), "gl2", title);
|
2004-11-04 18:31:55 +00:00
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
return 0;
|
2003-09-19 14:33:51 +00:00
|
|
|
}
|
2006-07-08 15:00:37 +00:00
|
|
|
#endif
|
2003-09-19 14:33:51 +00:00
|
|
|
|
|
|
|
static int initGl(uint32_t d_width, uint32_t d_height)
|
|
|
|
{
|
2005-09-14 22:08:04 +00:00
|
|
|
fragprog = lookupTex = 0;
|
2003-09-19 14:33:51 +00:00
|
|
|
if (initTextures() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
glDisable(GL_BLEND);
|
2003-09-19 14:33:51 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glEnable (GL_TEXTURE_2D);
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv) {
|
|
|
|
int xs, ys;
|
2008-05-24 11:03:00 +00:00
|
|
|
gl_conversion_params_t params = {GL_TEXTURE_2D, use_yuv,
|
2010-01-16 19:59:31 +00:00
|
|
|
{-1, -1, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0},
|
2009-12-30 11:32:24 +00:00
|
|
|
texture_width, texture_height, 0, 0, 0};
|
2005-09-14 22:08:04 +00:00
|
|
|
switch (use_yuv) {
|
|
|
|
case YUV_CONVERSION_FRAGMENT_LOOKUP:
|
|
|
|
glGenTextures(1, &lookupTex);
|
|
|
|
ActiveTexture(GL_TEXTURE3);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lookupTex);
|
|
|
|
ActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
case YUV_CONVERSION_FRAGMENT_POW:
|
|
|
|
case YUV_CONVERSION_FRAGMENT:
|
2006-06-05 20:21:25 +00:00
|
|
|
if (!GenPrograms || !BindProgram) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[gl] fragment program functions missing!\n");
|
|
|
|
break;
|
|
|
|
}
|
2005-09-14 22:08:04 +00:00
|
|
|
GenPrograms(1, &fragprog);
|
|
|
|
BindProgram(GL_FRAGMENT_PROGRAM, fragprog);
|
|
|
|
break;
|
|
|
|
}
|
2009-12-30 11:32:24 +00:00
|
|
|
mp_get_chroma_shift(image_format, &xs, &ys);
|
|
|
|
params.chrom_texw = params.texw >> xs;
|
|
|
|
params.chrom_texh = params.texh >> ys;
|
2008-05-24 11:03:00 +00:00
|
|
|
glSetupYUVConversion(¶ms);
|
2005-09-14 22:08:04 +00:00
|
|
|
}
|
2003-09-19 14:33:51 +00:00
|
|
|
|
|
|
|
gl_set_antialias(0);
|
|
|
|
gl_set_bilinear(1);
|
2007-06-26 16:33:43 +00:00
|
|
|
|
2004-12-01 17:05:58 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[gl2] Using image_bpp=%d, image_bytes=%d, \n\tgl_bitmap_format=%s, gl_bitmap_type=%s, \n\trgb_size=%d (%d,%d,%d), a_sz=%d, \n\tgl_internal_format=%s\n",
|
2007-06-26 16:33:43 +00:00
|
|
|
image_bpp, image_bytes,
|
2004-12-01 17:05:58 +00:00
|
|
|
glValName(gl_bitmap_format), glValName(gl_bitmap_type),
|
|
|
|
rgb_sz, r_sz, g_sz, b_sz, a_sz, glValName(gl_internal_format));
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2009-08-27 14:10:38 +00:00
|
|
|
resize(d_width, d_height);
|
2003-09-19 14:33:51 +00:00
|
|
|
|
|
|
|
glClearColor( 0.0f,0.0f,0.0f,0.0f );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT );
|
|
|
|
|
2004-11-13 12:01:20 +00:00
|
|
|
drawTextureDisplay ();
|
|
|
|
|
2003-09-19 14:33:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect to server, create and map window,
|
|
|
|
* allocate colors and (shared) memory
|
|
|
|
*/
|
2007-06-26 16:33:43 +00:00
|
|
|
static int
|
2003-09-19 14:33:51 +00:00
|
|
|
config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
|
|
|
|
{
|
2009-12-30 11:32:24 +00:00
|
|
|
int xs, ys;
|
2007-06-26 16:33:43 +00:00
|
|
|
const unsigned char * glVersion;
|
|
|
|
|
|
|
|
image_height = height;
|
|
|
|
image_width = width;
|
|
|
|
image_format = format;
|
2009-12-30 11:32:24 +00:00
|
|
|
is_yuv = mp_get_chroma_shift(image_format, &xs, &ys) > 0;
|
|
|
|
is_yuv |= (xs << 8) | (ys << 16);
|
2003-09-19 14:33:51 +00:00
|
|
|
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifdef CONFIG_GL_WIN32
|
2007-06-26 16:33:43 +00:00
|
|
|
if (config_w32(width, height, d_width, d_height, flags, title, format) == -1)
|
2003-09-19 14:33:51 +00:00
|
|
|
#else
|
2007-06-26 16:33:43 +00:00
|
|
|
if (config_glx(width, height, d_width, d_height, flags, title, format) == -1)
|
2003-09-19 14:33:51 +00:00
|
|
|
#endif
|
2007-06-26 16:33:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-12-08 06:42:46 +00:00
|
|
|
if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
|
2009-09-01 15:20:05 +00:00
|
|
|
return -1;
|
2004-12-11 16:57:42 +00:00
|
|
|
|
2001-10-19 10:09:29 +00:00
|
|
|
glVersion = glGetString(GL_VERSION);
|
|
|
|
|
2004-02-22 15:30:01 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[gl2] OpenGL Driver Information:\n");
|
2007-06-26 16:33:43 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "\tvendor: %s,\n\trenderer %s,\n\tversion %s\n",
|
|
|
|
glGetString(GL_VENDOR), glGetString(GL_RENDERER), glVersion);
|
|
|
|
|
|
|
|
if(glVersion[0]>'1' || (glVersion[0]=='1' && glVersion[2]>='2') )
|
|
|
|
isGL12 = GL_TRUE;
|
2001-10-19 10:09:29 +00:00
|
|
|
else
|
2007-06-26 16:33:43 +00:00
|
|
|
isGL12 = GL_FALSE;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
if(isGL12) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] You have OpenGL >= 1.2 capable drivers, GOOD (16bpp and BGR is ok!)\n");
|
2001-10-19 10:09:29 +00:00
|
|
|
} else {
|
2007-06-26 16:33:43 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[gl2] You have OpenGL < 1.2 drivers, BAD (16bpp and BGR may be damaged!)\n");
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
|
|
|
|
2005-09-14 22:08:04 +00:00
|
|
|
glFindFormat(format, &image_bpp, &gl_internal_format, &gl_bitmap_format, &gl_bitmap_type);
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2001-10-19 10:09:29 +00:00
|
|
|
image_bytes=(image_bpp+7)/8;
|
|
|
|
|
|
|
|
draw_alpha_fnc=draw_alpha_null;
|
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
switch(image_bpp) {
|
|
|
|
case 15:
|
|
|
|
draw_alpha_fnc=draw_alpha_15; break;
|
|
|
|
case 16:
|
|
|
|
draw_alpha_fnc=draw_alpha_16; break;
|
|
|
|
case 24:
|
|
|
|
draw_alpha_fnc=draw_alpha_24; break;
|
|
|
|
case 32:
|
|
|
|
draw_alpha_fnc=draw_alpha_32; break;
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
|
|
|
|
2005-06-18 18:32:29 +00:00
|
|
|
if (initGl(vo_dwidth, vo_dheight) == -1)
|
2007-06-26 16:33:43 +00:00
|
|
|
return -1;
|
2001-10-07 21:35:59 +00:00
|
|
|
|
2007-06-26 16:33:43 +00:00
|
|
|
return 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifndef CONFIG_GL_WIN32
|
2001-10-19 10:09:29 +00:00
|
|
|
static int gl_handlekey(int key)
|
|
|
|
{
|
2007-06-26 16:33:43 +00:00
|
|
|
if(key=='a'||key=='A') {
|
|
|
|
gl_set_antialias(!gl_antialias);
|
|
|
|
return 0;
|
|
|
|
} else if(key=='b'||key=='B') {
|
|
|
|
gl_set_bilinear(-1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2001-10-19 10:09:29 +00:00
|
|
|
}
|
2008-10-13 14:40:58 +00:00
|
|
|
#endif
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
static void check_events(void)
|
|
|
|
{
|
2007-06-26 16:33:43 +00:00
|
|
|
int e;
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifndef CONFIG_GL_WIN32
|
2007-06-26 16:33:43 +00:00
|
|
|
XEvent Event;
|
|
|
|
char buf[100];
|
|
|
|
KeySym keySym;
|
|
|
|
int key;
|
|
|
|
static XComposeStatus stat;
|
|
|
|
|
|
|
|
while ( XPending( mDisplay ) ) {
|
|
|
|
XNextEvent( mDisplay,&Event );
|
|
|
|
if( Event.type == KeyPress ) {
|
|
|
|
XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
|
|
|
|
key = (keySym&0xff00) != 0 ? (keySym&0x00ff) + 256 : keySym;
|
|
|
|
if(gl_handlekey(key))
|
|
|
|
XPutBackEvent(mDisplay, &Event);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
XPutBackEvent(mDisplay, &Event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-12-06 22:23:06 +00:00
|
|
|
#endif
|
2009-12-08 06:42:46 +00:00
|
|
|
e=glctx.check_events();
|
2009-08-27 14:10:38 +00:00
|
|
|
if(e&VO_EVENT_RESIZE) resize(vo_dwidth, vo_dheight);
|
2007-06-26 16:33:43 +00:00
|
|
|
if(e&VO_EVENT_EXPOSE && int_pause) flip_page();
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_osd(void)
|
2004-05-08 21:40:20 +00:00
|
|
|
{
|
|
|
|
if (ImageData)
|
|
|
|
vo_draw_text(image_width,image_height,draw_alpha_fnc);
|
|
|
|
}
|
2001-10-07 21:35:59 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
flip_page(void)
|
|
|
|
{
|
|
|
|
drawTextureDisplay();
|
|
|
|
|
|
|
|
// glFlush();
|
2005-09-13 16:16:13 +00:00
|
|
|
if (use_glFinish)
|
2001-10-07 21:35:59 +00:00
|
|
|
glFinish();
|
2009-12-08 06:42:46 +00:00
|
|
|
glctx.swapGlBuffers(&glctx);
|
2004-05-02 14:16:13 +00:00
|
|
|
|
2009-08-27 18:42:08 +00:00
|
|
|
if (aspect_scaling()) // Avoid flickering borders in fullscreen mode
|
2004-05-02 14:16:13 +00:00
|
|
|
glClear (GL_COLOR_BUFFER_BIT);
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
|
2001-10-07 21:35:59 +00:00
|
|
|
{
|
2005-09-25 13:58:18 +00:00
|
|
|
uint8_t *yptr = src[0], *uptr = src[1], *vptr = src[2];
|
|
|
|
int ystride = stride[0], ustride = stride[1], vstride = stride[2];
|
2005-09-14 22:08:04 +00:00
|
|
|
int rem_h = h;
|
|
|
|
struct TexSquare *texline = &texgrid[y / texture_height * texnumx];
|
|
|
|
int subtex_y = y % texture_width;
|
2009-12-30 11:32:24 +00:00
|
|
|
int xs, ys;
|
|
|
|
mp_get_chroma_shift(image_format, &xs, &ys);
|
2005-09-14 22:08:04 +00:00
|
|
|
while (rem_h > 0) {
|
|
|
|
int rem_w = w;
|
|
|
|
struct TexSquare *tsq = &texline[x / texture_width];
|
|
|
|
int subtex_x = x % texture_height;
|
|
|
|
int subtex_h = rem_h;
|
|
|
|
if (subtex_y + subtex_h > texture_height)
|
|
|
|
subtex_h = texture_height - subtex_y;
|
|
|
|
while (rem_w > 0) {
|
|
|
|
int subtex_w = rem_w;
|
|
|
|
if (subtex_x + subtex_w > texture_width)
|
|
|
|
subtex_w = texture_width - subtex_x;
|
|
|
|
ActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tsq->texobj);
|
|
|
|
glUploadTex(GL_TEXTURE_2D, gl_bitmap_format, gl_bitmap_type,
|
2005-09-25 13:58:18 +00:00
|
|
|
yptr, ystride, subtex_x, subtex_y,
|
2005-09-14 22:08:04 +00:00
|
|
|
subtex_w, subtex_h, 0);
|
|
|
|
ActiveTexture(GL_TEXTURE1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tsq->uvtexobjs[0]);
|
|
|
|
glUploadTex(GL_TEXTURE_2D, gl_bitmap_format, gl_bitmap_type,
|
2009-12-30 11:32:24 +00:00
|
|
|
uptr, ustride, subtex_x >> xs, subtex_y >> ys,
|
|
|
|
subtex_w >> xs, subtex_h >> ys, 0);
|
2005-09-14 22:08:04 +00:00
|
|
|
ActiveTexture(GL_TEXTURE2);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tsq->uvtexobjs[1]);
|
|
|
|
glUploadTex(GL_TEXTURE_2D, gl_bitmap_format, gl_bitmap_type,
|
2009-12-30 11:32:24 +00:00
|
|
|
vptr, vstride, subtex_x >> xs, subtex_y >> ys,
|
|
|
|
subtex_w >> xs, subtex_h >> ys, 0);
|
2005-09-14 22:08:04 +00:00
|
|
|
subtex_x = 0;
|
2005-09-25 13:58:18 +00:00
|
|
|
yptr += subtex_w;
|
2009-12-30 11:32:24 +00:00
|
|
|
uptr += subtex_w >> xs;
|
|
|
|
vptr += subtex_w >> xs;
|
2005-09-14 22:08:04 +00:00
|
|
|
tsq++;
|
|
|
|
rem_w -= subtex_w;
|
|
|
|
}
|
|
|
|
subtex_y = 0;
|
2005-09-25 13:58:18 +00:00
|
|
|
yptr += subtex_h * ystride - w;
|
2009-12-30 11:32:24 +00:00
|
|
|
uptr += (subtex_h >> ys) * ustride - (w >> xs);
|
|
|
|
vptr += (subtex_h >> ys) * vstride - (w >> xs);
|
2005-09-14 22:08:04 +00:00
|
|
|
texline += texnumx;
|
|
|
|
rem_h -= subtex_h;
|
|
|
|
}
|
|
|
|
ActiveTexture(GL_TEXTURE0);
|
2001-10-19 10:09:29 +00:00
|
|
|
return 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int
|
2001-10-07 21:35:59 +00:00
|
|
|
draw_frame(uint8_t *src[])
|
|
|
|
{
|
2009-12-30 11:32:24 +00:00
|
|
|
if (is_yuv) {
|
2005-09-14 22:08:04 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[gl2] error: draw_frame called for YV12!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-08-14 13:44:14 +00:00
|
|
|
ImageData=(unsigned char *)src[0];
|
|
|
|
resetTexturePointers(ImageData);
|
2007-06-26 15:51:49 +00:00
|
|
|
texdirty = 1;
|
2005-08-14 13:44:14 +00:00
|
|
|
return 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int
|
2001-10-07 21:35:59 +00:00
|
|
|
query_format(uint32_t format)
|
|
|
|
{
|
2009-12-31 22:53:25 +00:00
|
|
|
if (use_yuv && mp_get_chroma_shift(format, NULL, NULL) &&
|
|
|
|
(IMGFMT_IS_YUVP16_NE(format) || !IMGFMT_IS_YUVP16(format)))
|
2009-12-30 11:32:24 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD |
|
|
|
|
VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
|
2007-06-26 16:33:43 +00:00
|
|
|
switch(format) {
|
2007-12-16 23:50:05 +00:00
|
|
|
#ifdef __APPLE__
|
2004-07-02 16:18:24 +00:00
|
|
|
case IMGFMT_RGB32:
|
|
|
|
#else
|
2003-05-20 19:30:46 +00:00
|
|
|
case IMGFMT_RGB24:
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
// case IMGFMT_RGB32:
|
|
|
|
// case IMGFMT_BGR32:
|
2004-07-02 16:18:24 +00:00
|
|
|
#endif
|
2002-05-27 17:56:52 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD;
|
2007-06-26 16:33:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
uninit(void)
|
|
|
|
{
|
2002-05-14 23:44:35 +00:00
|
|
|
if ( !vo_config_count ) return;
|
2004-10-03 21:42:31 +00:00
|
|
|
if (texgrid) {
|
|
|
|
free(texgrid);
|
|
|
|
texgrid = NULL;
|
|
|
|
}
|
2009-12-08 06:42:46 +00:00
|
|
|
uninit_mpglcontext(&glctx);
|
2001-10-07 21:35:59 +00:00
|
|
|
}
|
2002-01-26 16:01:26 +00:00
|
|
|
|
2009-03-07 08:51:40 +00:00
|
|
|
static const opt_t subopts[] = {
|
2010-01-01 13:18:49 +00:00
|
|
|
{"yuv", OPT_ARG_INT, &use_yuv, int_non_neg},
|
2005-09-13 16:16:13 +00:00
|
|
|
{"glfinish", OPT_ARG_BOOL, &use_glFinish, NULL},
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int preinit(const char *arg)
|
2002-01-26 16:01:26 +00:00
|
|
|
{
|
2009-12-08 06:42:46 +00:00
|
|
|
enum MPGLType gltype = GLTYPE_X11;
|
2005-09-13 16:16:13 +00:00
|
|
|
// set defaults
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifdef CONFIG_GL_WIN32
|
2009-12-08 06:42:46 +00:00
|
|
|
gltype = GLTYPE_W32;
|
|
|
|
#endif
|
2005-09-14 22:08:04 +00:00
|
|
|
use_yuv = 0;
|
2005-09-13 16:16:13 +00:00
|
|
|
use_glFinish = 1;
|
|
|
|
if (subopt_parse(arg, subopts) != 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL,
|
|
|
|
"\n-vo gl2 command line help:\n"
|
|
|
|
"Example: mplayer -vo gl2:noglfinish\n"
|
|
|
|
"\nOptions:\n"
|
|
|
|
" noglfinish\n"
|
|
|
|
" Do not call glFinish() before swapping buffers\n"
|
2005-09-14 22:08:04 +00:00
|
|
|
" yuv=<n>\n"
|
|
|
|
" 0: use software YUV to RGB conversion.\n"
|
2005-10-01 12:53:49 +00:00
|
|
|
" 1: use register combiners (nVidia only, for older cards).\n"
|
2005-09-14 22:08:04 +00:00
|
|
|
" 2: use fragment program.\n"
|
|
|
|
" 3: use fragment program with gamma correction.\n"
|
|
|
|
" 4: use fragment program with gamma correction via lookup.\n"
|
2005-10-01 12:53:49 +00:00
|
|
|
" 5: use ATI-specific method (for older cards).\n"
|
2005-09-13 16:16:13 +00:00
|
|
|
"\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
2009-12-08 06:42:46 +00:00
|
|
|
if(!init_mpglcontext(&glctx, gltype)) return -1;
|
2002-02-17 08:24:43 +00:00
|
|
|
return 0;
|
2002-01-26 16:01:26 +00:00
|
|
|
}
|
|
|
|
|
2008-04-02 16:38:34 +00:00
|
|
|
static int control(uint32_t request, void *data)
|
2002-01-26 16:01:26 +00:00
|
|
|
{
|
2002-02-09 00:47:26 +00:00
|
|
|
switch (request) {
|
2008-05-22 20:21:19 +00:00
|
|
|
case VOCTRL_PAUSE:
|
|
|
|
case VOCTRL_RESUME:
|
|
|
|
int_pause = (request == VOCTRL_PAUSE);
|
|
|
|
return VO_TRUE;
|
2007-06-26 16:33:43 +00:00
|
|
|
case VOCTRL_QUERY_FORMAT:
|
|
|
|
return query_format(*((uint32_t*)data));
|
|
|
|
case VOCTRL_ONTOP:
|
2009-12-08 06:42:46 +00:00
|
|
|
glctx.ontop();
|
2007-06-26 16:33:43 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
2009-12-08 06:42:46 +00:00
|
|
|
glctx.fullscreen();
|
|
|
|
if (glctx.setGlWindow(&glctx) == SET_WINDOW_REINIT)
|
2007-06-26 16:33:43 +00:00
|
|
|
initGl(vo_dwidth, vo_dheight);
|
2009-08-27 14:10:38 +00:00
|
|
|
resize(vo_dwidth, vo_dheight);
|
2007-06-26 16:33:43 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_BORDER:
|
2009-12-08 06:42:46 +00:00
|
|
|
glctx.border();
|
2007-06-26 16:33:43 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_GET_PANSCAN:
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_SET_PANSCAN:
|
2009-08-27 14:10:38 +00:00
|
|
|
resize(vo_dwidth, vo_dheight);
|
2007-06-26 16:33:43 +00:00
|
|
|
return VO_TRUE;
|
2009-12-19 13:49:44 +00:00
|
|
|
#ifndef CONFIG_GL_WIN32
|
2007-06-26 16:33:43 +00:00
|
|
|
case VOCTRL_SET_EQUALIZER:
|
2002-10-29 20:27:47 +00:00
|
|
|
{
|
2008-04-02 15:51:38 +00:00
|
|
|
struct voctrl_set_equalizer_args *args = data;
|
|
|
|
return vo_x11_set_equalizer(args->name, args->value);
|
2007-06-26 16:33:43 +00:00
|
|
|
}
|
|
|
|
case VOCTRL_GET_EQUALIZER:
|
2002-10-29 20:27:47 +00:00
|
|
|
{
|
2008-04-02 15:51:38 +00:00
|
|
|
struct voctrl_get_equalizer_args *args = data;
|
|
|
|
return vo_x11_get_equalizer(args->name, args->valueptr);
|
2002-10-29 20:27:47 +00:00
|
|
|
}
|
2003-09-19 14:33:51 +00:00
|
|
|
#endif
|
2007-06-26 16:33:43 +00:00
|
|
|
case VOCTRL_UPDATE_SCREENINFO:
|
2009-12-08 06:42:46 +00:00
|
|
|
glctx.update_xinerama_info();
|
2007-06-26 16:33:43 +00:00
|
|
|
return VO_TRUE;
|
2002-02-09 00:47:26 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
2002-01-26 16:01:26 +00:00
|
|
|
}
|