2001-10-07 23:35:59 +02:00
|
|
|
/*
|
|
|
|
* video_out_gl.c, X11/OpenGL interface
|
|
|
|
* based on video_out_x11 by Aaron Holtzman,
|
|
|
|
* and WS opengl window manager by Pontscho/Fresh!
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2002-02-17 09:24:43 +01:00
|
|
|
#include <errno.h>
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
2003-10-12 16:42:27 +02:00
|
|
|
#include "mp_msg.h"
|
2001-10-07 23:35:59 +02:00
|
|
|
#include "video_out.h"
|
|
|
|
#include "video_out_internal.h"
|
2002-11-07 00:54:29 +01:00
|
|
|
#include "sub.h"
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
#include <GL/gl.h>
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <GL/glext.h>
|
|
|
|
#else
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <GL/glx.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
#include "w32_common.h"
|
|
|
|
#else
|
|
|
|
#include "x11_common.h"
|
|
|
|
#endif
|
2001-10-07 23:35:59 +02:00
|
|
|
#include "aspect.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
2001-10-19 12:09:29 +02:00
|
|
|
//#undef NDEBUG
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2003-05-20 21:30:46 +02:00
|
|
|
#undef TEXTUREFORMAT_ALWAYS_RGB24
|
|
|
|
|
2002-11-11 16:22:10 +01:00
|
|
|
static vo_info_t info =
|
2001-10-07 23:35:59 +02:00
|
|
|
{
|
2001-10-07 23:39:47 +02:00
|
|
|
"X11 (OpenGL) - multiple textures version",
|
2001-10-07 23:35:59 +02:00
|
|
|
"gl2",
|
2001-10-07 23:39:47 +02:00
|
|
|
"Arpad Gereoffy & Sven Goethel",
|
2001-10-07 23:35:59 +02:00
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2002-11-11 16:22:10 +01:00
|
|
|
LIBVO_EXTERN(gl2)
|
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
/* private prototypes */
|
|
|
|
|
2003-05-20 21:30:46 +02:00
|
|
|
#define MODE_BGR 1
|
|
|
|
#define MODE_RGB 0
|
2001-10-24 19:04:08 +02:00
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
/* local data */
|
2001-10-19 12:09:29 +02:00
|
|
|
static unsigned char *ImageDataLocal=NULL;
|
2001-10-07 23:35:59 +02:00
|
|
|
static unsigned char *ImageData=NULL;
|
|
|
|
|
|
|
|
/* X11 related variables */
|
2002-05-15 01:44:35 +02:00
|
|
|
//static Window vo_window;
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
//static int texture_id=1;
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifndef GL_WIN32
|
|
|
|
static GLXContext wsGLXContext;
|
|
|
|
#endif
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
static uint32_t image_width;
|
|
|
|
static uint32_t image_height;
|
|
|
|
static uint32_t image_format;
|
|
|
|
static uint32_t image_bpp;
|
2001-10-19 12:09:29 +02:00
|
|
|
static int image_mode;
|
2001-10-07 23:35:59 +02:00
|
|
|
static uint32_t image_bytes;
|
|
|
|
|
2003-09-01 00:27:10 +02:00
|
|
|
static int int_pause;
|
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
static uint32_t texture_width;
|
|
|
|
static uint32_t texture_height;
|
|
|
|
static int texnumx, texnumy, memory_x_len, memory_x_start_offset, raw_line_len;
|
|
|
|
static GLfloat texpercx, texpercy;
|
|
|
|
static struct TexSquare * texgrid;
|
2001-10-19 12:09:29 +02:00
|
|
|
static GLint gl_internal_format;
|
|
|
|
static char * gl_internal_format_s;
|
|
|
|
static int rgb_sz, r_sz, g_sz, b_sz, a_sz;
|
|
|
|
static GLint gl_bitmap_format;
|
|
|
|
static char * gl_bitmap_format_s;
|
|
|
|
static GLint gl_bitmap_type;
|
|
|
|
static char * gl_bitmap_type_s;
|
|
|
|
static int gl_alignment;
|
|
|
|
static int isGL12 = GL_FALSE;
|
|
|
|
|
|
|
|
static int gl_bilinear=1;
|
|
|
|
static int gl_antialias=0;
|
|
|
|
|
|
|
|
static void (*draw_alpha_fnc)
|
|
|
|
(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2003-09-01 00:27:10 +02:00
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
/* The squares that are tiled to make up the game screen polygon */
|
|
|
|
|
|
|
|
struct TexSquare
|
|
|
|
{
|
|
|
|
GLubyte *texture;
|
|
|
|
GLuint texobj;
|
|
|
|
int isTexture;
|
|
|
|
GLfloat fx1, fy1, fx2, fy2, fx3, fy3, fx4, fy4;
|
|
|
|
GLfloat xcov, ycov;
|
2001-10-19 12:09:29 +02:00
|
|
|
int isDirty;
|
|
|
|
int dirtyXoff, dirtyYoff, dirtyWidth, dirtyHeight;
|
2001-10-07 23:35:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void CalcFlatPoint(int x,int y,GLfloat *px,GLfloat *py)
|
|
|
|
{
|
|
|
|
*px=(float)x*texpercx;
|
|
|
|
if(*px>1.0) *px=1.0;
|
|
|
|
*py=(float)y*texpercy;
|
|
|
|
if(*py>1.0) *py=1.0;
|
|
|
|
}
|
|
|
|
|
2003-08-14 03:15:41 +02:00
|
|
|
static int initTextures()
|
2001-10-07 23:35:59 +02:00
|
|
|
{
|
|
|
|
unsigned char *line_1=0, *line_2=0, *mem_start=0;
|
|
|
|
struct TexSquare *tsq=0;
|
|
|
|
int e_x, e_y, s, i=0;
|
|
|
|
int x=0, y=0;
|
|
|
|
GLint format=0;
|
|
|
|
GLenum err;
|
|
|
|
|
|
|
|
/* achieve the 2**e_x:=texture_width, 2**e_y:=texture_height */
|
|
|
|
e_x=0; s=1;
|
|
|
|
while (s<texture_width)
|
|
|
|
{ s*=2; e_x++; }
|
|
|
|
texture_width=s;
|
|
|
|
|
|
|
|
e_y=0; s=1;
|
|
|
|
while (s<texture_height)
|
|
|
|
{ s*=2; e_y++; }
|
|
|
|
texture_height=s;
|
|
|
|
|
|
|
|
|
|
|
|
/* Test the max texture size */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
glTexImage2D (GL_PROXY_TEXTURE_2D, 0,
|
2001-10-19 12:09:29 +02:00
|
|
|
gl_internal_format,
|
2001-10-07 23:35:59 +02:00
|
|
|
texture_width, texture_height,
|
2001-10-19 12:09:29 +02:00
|
|
|
0, gl_bitmap_format, gl_bitmap_type, NULL);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
glGetTexLevelParameteriv
|
|
|
|
(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
if (format != gl_internal_format)
|
2001-10-07 23:35:59 +02:00
|
|
|
{
|
2001-10-19 12:09:29 +02:00
|
|
|
fprintf (stderr, "[gl2] Needed texture [%dx%d] too big, trying ",
|
2001-10-07 23:35:59 +02:00
|
|
|
texture_height, texture_width);
|
|
|
|
|
|
|
|
if (texture_width > texture_height)
|
|
|
|
{
|
|
|
|
e_x--;
|
|
|
|
texture_width = 1;
|
|
|
|
for (i = e_x; i > 0; i--)
|
|
|
|
texture_width *= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e_y--;
|
|
|
|
texture_height = 1;
|
|
|
|
for (i = e_y; i > 0; i--)
|
|
|
|
texture_height *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf (stderr, "[%dx%d] !\n", texture_height, texture_width);
|
|
|
|
|
|
|
|
if(texture_width < 64 || texture_height < 64)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "GLERROR: Give up .. usable texture size not avaiable, or texture config error !\n");
|
2003-08-14 03:15:41 +02:00
|
|
|
return -1;
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-19 12:09:29 +02:00
|
|
|
while (format != gl_internal_format && texture_width > 1 && texture_height > 1);
|
2001-10-07 23:35:59 +02: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++;
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
printf("[gl2] Creating %dx%d textures of size %dx%d ...\n",
|
2001-12-17 18:15:16 +01:00
|
|
|
texnumx, texnumy, texture_width,texture_height);
|
2001-10-19 12:09:29 +02:00
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
/* Allocate the texture memory */
|
|
|
|
|
|
|
|
texpercx = (GLfloat) texture_width / (GLfloat) image_width;
|
|
|
|
if (texpercx > 1.0)
|
|
|
|
texpercx = 1.0;
|
|
|
|
|
|
|
|
texpercy = (GLfloat) texture_height / (GLfloat) image_height;
|
|
|
|
if (texpercy > 1.0)
|
|
|
|
texpercy = 1.0;
|
|
|
|
|
|
|
|
texgrid = (struct TexSquare *)
|
|
|
|
calloc (texnumx * texnumy, sizeof (struct TexSquare));
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
line_1 = (unsigned char *) ImageDataLocal;
|
|
|
|
line_2 = (unsigned char *) ImageDataLocal+(image_width*image_bytes);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
mem_start = (unsigned char *) ImageDataLocal;
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
raw_line_len = line_2 - line_1;
|
|
|
|
|
|
|
|
memory_x_len = raw_line_len / image_bytes;
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2001-10-19 12:09:29 +02:00
|
|
|
fprintf (stderr, "[gl2] texture-usage %d*width=%d, %d*height=%d\n",
|
2001-10-07 23:35:59 +02:00
|
|
|
(int) texnumx, (int) texture_width, (int) texnumy,
|
|
|
|
(int) texture_height);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y = 0; y < texnumy; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < texnumx; x++)
|
|
|
|
{
|
|
|
|
tsq = texgrid + y * texnumx + x;
|
|
|
|
|
|
|
|
if (x == texnumx - 1 && image_width % texture_width)
|
|
|
|
tsq->xcov =
|
|
|
|
(GLfloat) (image_width % texture_width) / (GLfloat) texture_width;
|
|
|
|
else
|
|
|
|
tsq->xcov = 1.0;
|
|
|
|
|
|
|
|
if (y == texnumy - 1 && image_height % texture_height)
|
|
|
|
tsq->ycov =
|
|
|
|
(GLfloat) (image_height % texture_height) / (GLfloat) texture_height;
|
|
|
|
else
|
|
|
|
tsq->ycov = 1.0;
|
|
|
|
|
|
|
|
CalcFlatPoint (x, y, &(tsq->fx1), &(tsq->fy1));
|
|
|
|
CalcFlatPoint (x + 1, y, &(tsq->fx2), &(tsq->fy2));
|
|
|
|
CalcFlatPoint (x + 1, y + 1, &(tsq->fx3), &(tsq->fy3));
|
|
|
|
CalcFlatPoint (x, y + 1, &(tsq->fx4), &(tsq->fy4));
|
|
|
|
|
|
|
|
/* calculate the pixel store data,
|
|
|
|
to use the machine-bitmap for our texture
|
|
|
|
*/
|
|
|
|
memory_x_start_offset = 0 * image_bytes +
|
|
|
|
x * texture_width * image_bytes;
|
|
|
|
|
|
|
|
tsq->texture = line_1 +
|
|
|
|
y * texture_height * raw_line_len +
|
|
|
|
memory_x_start_offset;
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
tsq->isDirty=GL_TRUE;
|
2001-10-07 23:35:59 +02:00
|
|
|
tsq->isTexture=GL_FALSE;
|
|
|
|
tsq->texobj=0;
|
2001-10-19 12:09:29 +02:00
|
|
|
tsq->dirtyXoff=0; tsq->dirtyYoff=0; tsq->dirtyWidth=-1; tsq->dirtyHeight=-1;
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
glGenTextures (1, &(tsq->texobj));
|
|
|
|
|
|
|
|
glBindTexture (GL_TEXTURE_2D, tsq->texobj);
|
|
|
|
err = glGetError ();
|
|
|
|
if(err==GL_INVALID_ENUM)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "GLERROR glBindTexture (glGenText) := GL_INVALID_ENUM, texnum x=%d, y=%d, texture=%d\n", x, y, tsq->texobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(glIsTexture(tsq->texobj) == GL_FALSE)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "GLERROR ain't a texture (glGenText): texnum x=%d, y=%d, texture=%d\n",
|
|
|
|
x, y, tsq->texobj);
|
|
|
|
} else {
|
|
|
|
tsq->isTexture=GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0,
|
2001-10-19 12:09:29 +02:00
|
|
|
gl_internal_format,
|
2001-10-07 23:35:59 +02:00
|
|
|
texture_width, texture_height,
|
2001-10-19 12:09:29 +02:00
|
|
|
0, gl_bitmap_format, gl_bitmap_type, NULL);
|
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 1.0);
|
|
|
|
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
|
|
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
|
|
|
} /* for all texnumx */
|
|
|
|
} /* for all texnumy */
|
2003-08-14 03:15:41 +02:00
|
|
|
|
|
|
|
return 0;
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
static void resetTexturePointers(unsigned char *imageSource)
|
|
|
|
{
|
|
|
|
unsigned char *line_1=0, *line_2=0, *mem_start=0;
|
|
|
|
struct TexSquare *tsq=0;
|
|
|
|
int x=0, y=0;
|
|
|
|
|
|
|
|
line_1 = (unsigned char *) imageSource;
|
|
|
|
line_2 = (unsigned char *) imageSource+(image_width*image_bytes);
|
|
|
|
|
|
|
|
mem_start = (unsigned char *) imageSource;
|
|
|
|
|
|
|
|
for (y = 0; y < texnumy; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < texnumx; x++)
|
|
|
|
{
|
|
|
|
tsq = texgrid + y * texnumx + x;
|
|
|
|
|
|
|
|
/* calculate the pixel store data,
|
|
|
|
to use the machine-bitmap for our texture
|
|
|
|
*/
|
|
|
|
memory_x_start_offset = 0 * image_bytes +
|
|
|
|
x * texture_width * image_bytes;
|
|
|
|
|
|
|
|
tsq->texture = line_1 +
|
|
|
|
y * texture_height * raw_line_len +
|
|
|
|
memory_x_start_offset;
|
|
|
|
|
|
|
|
} /* for all texnumx */
|
|
|
|
} /* for all texnumy */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setupTextureDirtyArea(int x, int y, int w,int h)
|
|
|
|
{
|
|
|
|
struct TexSquare *square;
|
|
|
|
int xi, yi, wd, ht, wh, hh;
|
|
|
|
int wdecr, hdecr, xh, yh;
|
|
|
|
|
|
|
|
wdecr=w; hdecr=h; xh=x; yh=y;
|
|
|
|
|
|
|
|
for (yi = 0; hdecr>0 && yi < texnumy; yi++)
|
|
|
|
{
|
|
|
|
if (yi < texnumy - 1)
|
|
|
|
ht = texture_height;
|
|
|
|
else
|
|
|
|
ht = image_height - texture_height * yi;
|
|
|
|
|
|
|
|
xh =x;
|
|
|
|
wdecr =w;
|
|
|
|
|
|
|
|
for (xi = 0; wdecr>0 && xi < texnumx; xi++)
|
|
|
|
{
|
|
|
|
square = texgrid + yi * texnumx + xi;
|
|
|
|
|
|
|
|
if (xi < texnumx - 1)
|
|
|
|
wd = texture_width;
|
|
|
|
else
|
|
|
|
wd = image_width - texture_width * xi;
|
|
|
|
|
|
|
|
if( 0 <= xh && xh < wd &&
|
|
|
|
0 <= yh && yh < ht
|
|
|
|
)
|
|
|
|
{
|
|
|
|
square->isDirty=GL_TRUE;
|
|
|
|
|
|
|
|
wh=(wdecr<wd)?wdecr:wd-xh;
|
|
|
|
if(wh<0) wh=0;
|
|
|
|
|
|
|
|
hh=(hdecr<ht)?hdecr:ht-yh;
|
|
|
|
if(hh<0) hh=0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
#ifndef NDEBUG
|
|
|
|
printf("\t %dx%d, %d/%d (%dx%d): %d/%d (%dx%d)\n",
|
|
|
|
xi, yi, xh, yh, wdecr, hdecr, xh, yh, wh, hh);
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(xh<square->dirtyXoff)
|
|
|
|
square->dirtyXoff=xh;
|
|
|
|
|
|
|
|
if(yh<square->dirtyYoff)
|
|
|
|
square->dirtyYoff=yh;
|
|
|
|
|
|
|
|
square->dirtyWidth = wd-square->dirtyXoff;
|
|
|
|
square->dirtyHeight = ht-square->dirtyYoff;
|
|
|
|
|
|
|
|
wdecr-=wh;
|
|
|
|
|
|
|
|
if ( xi == texnumx - 1 )
|
|
|
|
hdecr-=hh;
|
|
|
|
}
|
|
|
|
|
|
|
|
xh-=wd;
|
|
|
|
if(xh<0) xh=0;
|
|
|
|
}
|
|
|
|
yh-=ht;
|
|
|
|
if(yh<0) yh=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_bilinear (int val)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
if(val>=0)
|
|
|
|
gl_bilinear = val;
|
|
|
|
else
|
|
|
|
gl_bilinear++;
|
|
|
|
|
|
|
|
gl_bilinear=gl_bilinear%2;
|
|
|
|
/* no mipmap yet .. */
|
|
|
|
|
|
|
|
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);
|
|
|
|
printf("[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);
|
|
|
|
printf("[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);
|
|
|
|
printf("[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);
|
|
|
|
printf("[gl2] bilinear mipmap linear\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fflush(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_antialias (int val)
|
|
|
|
{
|
|
|
|
gl_antialias=val;
|
|
|
|
|
|
|
|
if (gl_antialias)
|
|
|
|
{
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
glEnable (GL_POLYGON_SMOOTH);
|
|
|
|
glEnable (GL_LINE_SMOOTH);
|
|
|
|
glEnable (GL_POINT_SMOOTH);
|
|
|
|
printf("[gl2] antialiasing on\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glShadeModel (GL_FLAT);
|
|
|
|
glDisable (GL_POLYGON_SMOOTH);
|
|
|
|
glDisable (GL_LINE_SMOOTH);
|
|
|
|
glDisable (GL_POINT_SMOOTH);
|
|
|
|
printf("[gl2] antialiasing off\n");
|
|
|
|
}
|
|
|
|
fflush(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
static void drawTextureDisplay ()
|
|
|
|
{
|
|
|
|
struct TexSquare *square;
|
2002-11-23 11:58:14 +01:00
|
|
|
int x, y/*, xoff=0, yoff=0, wd, ht*/;
|
2001-10-07 23:35:59 +02:00
|
|
|
GLenum err;
|
|
|
|
|
|
|
|
glColor3f(1.0,1.0,1.0);
|
|
|
|
|
|
|
|
for (y = 0; y < texnumy; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < texnumx; x++)
|
|
|
|
{
|
|
|
|
square = texgrid + y * texnumx + x;
|
|
|
|
|
|
|
|
if(square->isTexture==GL_FALSE)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
2001-10-19 12:09:29 +02:00
|
|
|
fprintf (stderr, "[gl2] ain't a texture(update): texnum x=%d, y=%d, texture=%d\n",
|
2001-10-07 23:35:59 +02:00
|
|
|
x, y, square->texobj);
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture (GL_TEXTURE_2D, square->texobj);
|
|
|
|
err = glGetError ();
|
|
|
|
if(err==GL_INVALID_ENUM)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "GLERROR glBindTexture := GL_INVALID_ENUM, texnum x=%d, y=%d, texture=%d\n", x, y, square->texobj);
|
|
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
else if(err==GL_INVALID_OPERATION) {
|
|
|
|
fprintf (stderr, "GLERROR glBindTexture := GL_INVALID_OPERATION, texnum x=%d, y=%d, texture=%d\n", x, y, square->texobj);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(glIsTexture(square->texobj) == GL_FALSE)
|
|
|
|
{
|
|
|
|
square->isTexture=GL_FALSE;
|
|
|
|
fprintf (stderr, "GLERROR ain't a texture(update): texnum x=%d, y=%d, texture=%d\n",
|
|
|
|
x, y, square->texobj);
|
|
|
|
}
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
if(square->isDirty)
|
|
|
|
{
|
2001-10-07 23:35:59 +02:00
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0,
|
2001-10-19 12:09:29 +02:00
|
|
|
square->dirtyXoff, square->dirtyYoff,
|
|
|
|
square->dirtyWidth, square->dirtyHeight,
|
|
|
|
gl_bitmap_format, gl_bitmap_type, square->texture);
|
|
|
|
|
|
|
|
square->isDirty=GL_FALSE;
|
|
|
|
square->dirtyXoff=0; square->dirtyYoff=0; square->dirtyWidth=-1; square->dirtyHeight=-1;
|
|
|
|
}
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2001-10-19 12:09:29 +02:00
|
|
|
fprintf (stdout, "[gl2] glTexSubImage2D texnum x=%d, y=%d, %d/%d - %d/%d\n",
|
|
|
|
x, y, square->dirtyXoff, square->dirtyYoff, square->dirtyWidth, square->dirtyHeight);
|
2001-10-07 23:35:59 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
|
|
|
glTexCoord2f (0, 0);
|
|
|
|
glVertex2f (square->fx1, square->fy1);
|
|
|
|
|
|
|
|
glTexCoord2f (0, square->ycov);
|
|
|
|
glVertex2f (square->fx4, square->fy4);
|
|
|
|
|
|
|
|
glTexCoord2f (square->xcov, square->ycov);
|
|
|
|
glVertex2f (square->fx3, square->fy3);
|
|
|
|
|
|
|
|
glTexCoord2f (square->xcov, 0);
|
|
|
|
glVertex2f (square->fx2, square->fy2);
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
glEnd();
|
|
|
|
/*
|
2001-10-07 23:35:59 +02:00
|
|
|
#ifndef NDEBUG
|
2001-10-19 12:09:29 +02:00
|
|
|
fprintf (stdout, "[gl2] GL_QUADS texnum x=%d, y=%d, %f/%f %f/%f %f/%f %f/%f\n\n", x, y, square->fx1, square->fy1, square->fx4, square->fy4,
|
2001-10-07 23:35:59 +02:00
|
|
|
square->fx3, square->fy3, square->fx2, square->fy2);
|
|
|
|
#endif
|
2001-10-19 12:09:29 +02:00
|
|
|
*/
|
2001-10-07 23:35:59 +02:00
|
|
|
} /* for all texnumx */
|
|
|
|
} /* for all texnumy */
|
|
|
|
|
2003-10-04 19:29:08 +02:00
|
|
|
/* YES - let's catch this error ...
|
2001-10-07 23:35:59 +02:00
|
|
|
*/
|
|
|
|
(void) glGetError ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-12 16:42:27 +02:00
|
|
|
static void resize(int *x,int *y){
|
|
|
|
mp_msg(MSGT_VO,MSGL_V,"[gl2] Resize: %dx%d\n",*x,*y);
|
2003-09-19 16:33:51 +02:00
|
|
|
if( vo_fs )
|
2003-09-21 13:27:11 +02:00
|
|
|
{
|
2003-10-12 16:42:27 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
aspect(x, y, A_ZOOM);
|
|
|
|
glViewport( (vo_screenwidth-*x)/2, (vo_screenheight-*y)/2, *x, *y);
|
2003-09-21 13:27:11 +02:00
|
|
|
} else {
|
2003-10-12 16:42:27 +02:00
|
|
|
//aspect(x, y, A_NOZOOM);
|
|
|
|
glViewport( 0, 0, *x, *y );
|
2003-09-21 13:27:11 +02:00
|
|
|
}
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho (0, 1, 1, 0, -1.0, 1.0);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
2001-10-19 12:09:29 +02: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){
|
|
|
|
}
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
|
|
|
|
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) {
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
int pf;
|
|
|
|
|
|
|
|
o_dwidth = d_width;
|
|
|
|
o_dheight = d_height;
|
|
|
|
vo_fs = flags & VOFLAG_FULLSCREEN;
|
|
|
|
vo_vm = flags & VOFLAG_MODESWITCHING;
|
|
|
|
|
|
|
|
vo_dwidth = d_width;
|
|
|
|
vo_dheight = d_height;
|
|
|
|
|
|
|
|
destroyRenderingContext();
|
|
|
|
if (!createRenderingContext())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (vo_fs)
|
|
|
|
aspect(&d_width, &d_height, A_ZOOM);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2002-10-29 21:27:47 +01:00
|
|
|
static int choose_glx_visual(Display *dpy, int scr, XVisualInfo *res_vi)
|
|
|
|
{
|
|
|
|
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;
|
2002-11-07 00:54:29 +01:00
|
|
|
best_weight = 1000000; best_i=0;
|
2002-10-29 21:27:47 +01:00
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
static uint32_t config_glx(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
|
2001-10-07 23:35:59 +02:00
|
|
|
XSizeHints hint;
|
2002-10-29 21:27:47 +01:00
|
|
|
XVisualInfo *vinfo, vinfo_buf;
|
2001-10-07 23:35:59 +02:00
|
|
|
XEvent xev;
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
if( flags&0x01 )
|
|
|
|
{
|
2003-09-19 16:33:51 +02:00
|
|
|
vo_fs = VO_TRUE;
|
2001-10-19 12:51:04 +02:00
|
|
|
aspect(&d_width,&d_height,A_ZOOM);
|
2001-10-19 12:09:29 +02:00
|
|
|
hint.x = 0;
|
|
|
|
hint.y = 0;
|
|
|
|
hint.width = vo_screenwidth;
|
|
|
|
hint.height = vo_screenheight;
|
|
|
|
hint.flags = PPosition | PSize;
|
|
|
|
} else {
|
2003-09-19 16:33:51 +02:00
|
|
|
vo_fs = VO_FALSE;
|
2001-10-19 12:09:29 +02:00
|
|
|
hint.x = 0;
|
|
|
|
hint.y = 0;
|
|
|
|
hint.width = d_width;
|
|
|
|
hint.height = d_height;
|
|
|
|
hint.flags = PPosition | PSize;
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make the window */
|
|
|
|
|
|
|
|
// XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
|
|
|
|
|
|
|
|
// XMatchVisualInfo(mDisplay, screen, depth, TrueColor, &vinfo);
|
2002-10-29 21:27:47 +01:00
|
|
|
vinfo = choose_glx_visual(mDisplay,mScreen,&vinfo_buf) < 0 ? NULL : &vinfo_buf;
|
2001-10-07 23:35:59 +02:00
|
|
|
if (vinfo == NULL)
|
|
|
|
{
|
2001-10-19 12:09:29 +02:00
|
|
|
printf("[gl2] no GLX support present\n");
|
2001-10-07 23:35:59 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-10-16 23:32:03 +02:00
|
|
|
if ( vo_window == None )
|
|
|
|
{
|
2003-09-01 00:27:10 +02:00
|
|
|
vo_window = vo_x11_create_smooth_window(mDisplay, RootWindow(mDisplay,mScreen),
|
|
|
|
vinfo->visual, hint.x, hint.y, hint.width, hint.height, vinfo->depth, vo_x11_create_colormap(vinfo));
|
2002-05-15 01:44:35 +02:00
|
|
|
if ( flags&0x01 ) vo_x11_decoration( mDisplay,vo_window,0 );
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2002-05-15 01:44:35 +02:00
|
|
|
XSelectInput(mDisplay, vo_window, StructureNotifyMask);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
/* Tell other applications about this window */
|
|
|
|
|
2003-05-20 21:30:46 +02:00
|
|
|
XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
/* Map window. */
|
2002-05-15 01:44:35 +02:00
|
|
|
XMapWindow(mDisplay, vo_window);
|
2002-01-06 22:07:20 +01:00
|
|
|
#ifdef HAVE_XINERAMA
|
2002-05-15 01:44:35 +02:00
|
|
|
vo_x11_xinerama_move(mDisplay,vo_window);
|
2002-01-06 22:07:20 +01:00
|
|
|
#endif
|
2003-10-12 16:42:27 +02:00
|
|
|
vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
|
2002-05-15 01:44:35 +02:00
|
|
|
XClearWindow(mDisplay,vo_window);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
/* Wait for map. */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
XNextEvent(mDisplay, &xev);
|
|
|
|
}
|
2002-05-15 01:44:35 +02:00
|
|
|
while (xev.type != MapNotify || xev.xmap.event != vo_window);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2002-05-15 01:44:35 +02:00
|
|
|
XSelectInput(mDisplay, vo_window, NoEventMask);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2002-10-16 23:32:03 +02:00
|
|
|
}
|
2003-10-12 16:42:27 +02:00
|
|
|
else {
|
|
|
|
vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
|
|
|
|
if ( !(flags&1) ) XMoveResizeWindow( mDisplay,vo_window,hint.x,hint.y,hint.width,hint.height );
|
|
|
|
}
|
2002-10-16 23:32:03 +02:00
|
|
|
|
|
|
|
vo_x11_classhint( mDisplay,vo_window,"gl2" );
|
|
|
|
vo_hidecursor(mDisplay,vo_window);
|
|
|
|
|
|
|
|
if ( vo_config_count ) glXDestroyContext( mDisplay,wsGLXContext );
|
|
|
|
|
|
|
|
wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True );
|
|
|
|
|
|
|
|
glXMakeCurrent( mDisplay,vo_window,wsGLXContext );
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
XFlush(mDisplay);
|
|
|
|
XSync(mDisplay, False);
|
|
|
|
|
2002-05-15 01:44:35 +02:00
|
|
|
//XSelectInput(mDisplay, vo_window, StructureNotifyMask); // !!!!
|
2002-08-09 19:43:49 +02:00
|
|
|
vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask
|
2003-09-01 00:27:10 +02:00
|
|
|
| ButtonPressMask | ButtonReleaseMask | ExposureMask
|
2002-02-11 12:44:50 +01:00
|
|
|
);
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
if(glXGetConfig(mDisplay,vinfo,GLX_RED_SIZE, &r_sz)!=0)
|
|
|
|
r_sz=0;
|
|
|
|
if(glXGetConfig(mDisplay,vinfo,GLX_GREEN_SIZE, &g_sz)!=0)
|
|
|
|
g_sz=0;
|
|
|
|
if(glXGetConfig(mDisplay,vinfo,GLX_BLUE_SIZE, &b_sz)!=0)
|
|
|
|
b_sz=0;
|
|
|
|
if(glXGetConfig(mDisplay,vinfo,GLX_ALPHA_SIZE, &a_sz)!=0)
|
|
|
|
a_sz=0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int initGl(uint32_t d_width, uint32_t d_height)
|
|
|
|
{
|
|
|
|
ImageDataLocal=malloc(image_width*image_height*image_bytes);
|
|
|
|
memset(ImageDataLocal,128,image_width*image_height*image_bytes);
|
|
|
|
|
|
|
|
ImageData=ImageDataLocal;
|
|
|
|
|
|
|
|
texture_width=image_width;
|
|
|
|
texture_height=image_height;
|
|
|
|
|
|
|
|
if (initTextures() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, memory_x_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* may give a little speed up for a kinda burst read ..
|
|
|
|
*/
|
|
|
|
if( (image_width*image_bpp)%8 == 0 )
|
|
|
|
gl_alignment=8;
|
|
|
|
else if( (image_width*image_bpp)%4 == 0 )
|
|
|
|
gl_alignment=4;
|
|
|
|
else if( (image_width*image_bpp)%2 == 0 )
|
|
|
|
gl_alignment=2;
|
|
|
|
else
|
|
|
|
gl_alignment=1;
|
|
|
|
|
|
|
|
glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment);
|
|
|
|
|
|
|
|
glEnable (GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
gl_set_antialias(0);
|
|
|
|
gl_set_bilinear(1);
|
|
|
|
|
|
|
|
drawTextureDisplay ();
|
|
|
|
|
|
|
|
printf("[gl2] Using image_bpp=%d, image_bytes=%d, isBGR=%d, \n\tgl_bitmap_format=%s, gl_bitmap_type=%s, \n\tgl_alignment=%d, rgb_size=%d (%d,%d,%d), a_sz=%d, \n\tgl_internal_format=%s\n",
|
|
|
|
image_bpp, image_bytes, image_mode==MODE_BGR,
|
|
|
|
gl_bitmap_format_s, gl_bitmap_type_s, gl_alignment,
|
|
|
|
rgb_sz, r_sz, g_sz, b_sz, a_sz, gl_internal_format_s);
|
|
|
|
|
2003-10-12 16:42:27 +02:00
|
|
|
resize(&d_width, &d_height);
|
2003-09-19 16:33:51 +02:00
|
|
|
|
|
|
|
glClearColor( 0.0f,0.0f,0.0f,0.0f );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect to server, create and map window,
|
|
|
|
* allocate colors and (shared) memory
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
|
|
|
|
{
|
|
|
|
const unsigned char * glVersion;
|
|
|
|
|
|
|
|
image_height = height;
|
|
|
|
image_width = width;
|
2003-09-21 17:44:23 +02:00
|
|
|
vo_dwidth = d_width;
|
|
|
|
vo_dheight = d_height;
|
2003-09-19 16:33:51 +02:00
|
|
|
image_format = format;
|
|
|
|
|
|
|
|
int_pause = 0;
|
|
|
|
|
|
|
|
aspect_save_orig(width,height);
|
|
|
|
aspect_save_prescale(d_width,d_height);
|
|
|
|
aspect_save_screenres(vo_screenwidth,vo_screenheight);
|
|
|
|
|
|
|
|
aspect(&d_width,&d_height,A_NOZOOM);
|
|
|
|
|
|
|
|
#ifdef GL_WIN32
|
|
|
|
if (config_w32(width, height, d_width, d_height, flags, title, format) == -1)
|
|
|
|
#else
|
|
|
|
if (config_glx(width, height, d_width, d_height, flags, title, format) == -1)
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
glVersion = glGetString(GL_VERSION);
|
|
|
|
|
|
|
|
printf("[gl2] OpenGL Driver Information:\n");
|
|
|
|
printf("\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;
|
|
|
|
else
|
|
|
|
isGL12 = GL_FALSE;
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
if(isGL12)
|
|
|
|
{
|
2003-09-19 16:33:51 +02:00
|
|
|
printf("[gl2] You have OpenGL >= 1.2 capable drivers, GOOD (16bpp and BGR is ok!)\n");
|
2001-10-19 12:09:29 +02:00
|
|
|
} else {
|
2003-09-19 16:33:51 +02:00
|
|
|
printf("[gl2] You have OpenGL < 1.2 drivers, BAD (16bpp and BGR may be damaged!)\n");
|
2001-10-19 12:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rgb_sz=r_sz+g_sz+b_sz;
|
|
|
|
if(rgb_sz<=0) rgb_sz=24;
|
|
|
|
|
|
|
|
if(r_sz==3 && g_sz==3 && b_sz==2 && a_sz==0) {
|
|
|
|
gl_internal_format=GL_R3_G3_B2;
|
|
|
|
gl_internal_format_s="GL_R3_G3_B2";
|
|
|
|
} else if(r_sz==4 && g_sz==4 && b_sz==4 && a_sz==0) {
|
|
|
|
gl_internal_format=GL_RGB4;
|
|
|
|
gl_internal_format_s="GL_RGB4";
|
|
|
|
} else if(r_sz==5 && g_sz==5 && b_sz==5 && a_sz==0) {
|
|
|
|
gl_internal_format=GL_RGB5;
|
|
|
|
gl_internal_format_s="GL_RGB5";
|
|
|
|
} else if(r_sz==8 && g_sz==8 && b_sz==8 && a_sz==0) {
|
|
|
|
gl_internal_format=GL_RGB8;
|
|
|
|
gl_internal_format_s="GL_RGB8";
|
|
|
|
} else if(r_sz==10 && g_sz==10 && b_sz==10 && a_sz==0) {
|
|
|
|
gl_internal_format=GL_RGB10;
|
|
|
|
gl_internal_format_s="GL_RGB10";
|
|
|
|
} else if(r_sz==2 && g_sz==2 && b_sz==2 && a_sz==2) {
|
|
|
|
gl_internal_format=GL_RGBA2;
|
|
|
|
gl_internal_format_s="GL_RGBA2";
|
|
|
|
} else if(r_sz==4 && g_sz==4 && b_sz==4 && a_sz==4) {
|
|
|
|
gl_internal_format=GL_RGBA4;
|
|
|
|
gl_internal_format_s="GL_RGBA4";
|
|
|
|
} else if(r_sz==5 && g_sz==5 && b_sz==5 && a_sz==1) {
|
|
|
|
gl_internal_format=GL_RGB5_A1;
|
|
|
|
gl_internal_format_s="GL_RGB5_A1";
|
|
|
|
} else if(r_sz==8 && g_sz==8 && b_sz==8 && a_sz==8) {
|
|
|
|
gl_internal_format=GL_RGBA8;
|
|
|
|
gl_internal_format_s="GL_RGBA8";
|
|
|
|
} else if(r_sz==10 && g_sz==10 && b_sz==10 && a_sz==2) {
|
|
|
|
gl_internal_format=GL_RGB10_A2;
|
|
|
|
gl_internal_format_s="GL_RGB10_A2";
|
|
|
|
} else {
|
|
|
|
gl_internal_format=GL_RGB;
|
|
|
|
gl_internal_format_s="GL_RGB";
|
|
|
|
}
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2003-05-20 21:30:46 +02:00
|
|
|
#ifdef TEXTUREFORMAT_ALWAYS_RGB24
|
|
|
|
gl_internal_format=GL_RGB8;
|
|
|
|
gl_internal_format_s="GL_RGB8";
|
|
|
|
#endif
|
2001-10-19 12:09:29 +02:00
|
|
|
|
2003-05-20 21:30:46 +02:00
|
|
|
if (IMGFMT_IS_BGR(format))
|
|
|
|
{
|
|
|
|
image_mode=MODE_BGR;
|
|
|
|
image_bpp=IMGFMT_BGR_DEPTH(format);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image_mode=MODE_RGB;
|
|
|
|
image_bpp=IMGFMT_RGB_DEPTH(format);
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
image_bytes=(image_bpp+7)/8;
|
|
|
|
|
|
|
|
draw_alpha_fnc=draw_alpha_null;
|
|
|
|
|
|
|
|
switch(image_bpp)
|
|
|
|
{
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
if(image_mode!=MODE_BGR)
|
|
|
|
{
|
|
|
|
gl_bitmap_format = GL_RGB;
|
|
|
|
gl_bitmap_format_s ="GL_RGB";
|
|
|
|
gl_bitmap_type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
gl_bitmap_type_s ="GL_UNSIGNED_SHORT_5_6_5";
|
|
|
|
} else {
|
|
|
|
gl_bitmap_format = GL_BGR;
|
|
|
|
gl_bitmap_format_s ="GL_BGR";
|
|
|
|
gl_bitmap_type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
gl_bitmap_type_s ="GL_UNSIGNED_SHORT_5_6_5";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image_bpp==15)
|
|
|
|
draw_alpha_fnc=draw_alpha_15;
|
|
|
|
else
|
|
|
|
draw_alpha_fnc=draw_alpha_16;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
if(image_mode!=MODE_BGR)
|
|
|
|
{
|
|
|
|
/* RGB888 */
|
|
|
|
gl_bitmap_format = GL_RGB;
|
|
|
|
gl_bitmap_format_s ="GL_RGB";
|
|
|
|
} else {
|
|
|
|
/* BGR888 */
|
|
|
|
gl_bitmap_format = GL_BGR;
|
|
|
|
gl_bitmap_format_s ="GL_BGR";
|
|
|
|
}
|
|
|
|
gl_bitmap_type = GL_UNSIGNED_BYTE;
|
|
|
|
gl_bitmap_type_s ="GL_UNSIGNED_BYTE";
|
|
|
|
|
|
|
|
draw_alpha_fnc=draw_alpha_24; break;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
/* RGBA8888 */
|
|
|
|
gl_bitmap_format = GL_BGRA;
|
|
|
|
gl_bitmap_format_s ="GL_BGRA";
|
|
|
|
|
|
|
|
if(image_mode!=MODE_BGR)
|
|
|
|
{
|
|
|
|
gl_bitmap_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
|
|
|
gl_bitmap_type_s ="GL_UNSIGNED_INT_8_8_8_8_REV";
|
|
|
|
} else {
|
|
|
|
gl_bitmap_type = GL_UNSIGNED_INT_8_8_8_8;
|
|
|
|
gl_bitmap_type_s ="GL_UNSIGNED_INT_8_8_8_8";
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_alpha_fnc=draw_alpha_32; break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
if (initGl(d_width, d_height) == -1)
|
|
|
|
return -1;
|
|
|
|
#ifndef GL_WIN32
|
|
|
|
saver_off(mDisplay);
|
|
|
|
#endif
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
static int gl_handlekey(int key)
|
|
|
|
{
|
|
|
|
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-07 23:35:59 +02:00
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
|
|
|
|
static void check_events(void) {
|
|
|
|
int e=vo_w32_check_events();
|
2003-10-12 16:42:27 +02:00
|
|
|
if(e&VO_EVENT_RESIZE) resize(&vo_dwidth, &vo_dheight);
|
2003-09-19 16:33:51 +02:00
|
|
|
if(e&VO_EVENT_EXPOSE && int_pause) flip_page();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
static void check_events(void)
|
|
|
|
{
|
2001-10-19 12:09:29 +02:00
|
|
|
XEvent Event;
|
|
|
|
char buf[100];
|
|
|
|
KeySym keySym;
|
|
|
|
int key;
|
|
|
|
static XComposeStatus stat;
|
|
|
|
int e;
|
2003-09-01 00:27:10 +02:00
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2003-09-01 00:27:10 +02:00
|
|
|
e=vo_x11_check_events(mDisplay);
|
2003-10-12 16:42:27 +02:00
|
|
|
if(e&VO_EVENT_RESIZE) resize(&vo_dwidth, &vo_dheight);
|
2003-09-01 00:27:10 +02:00
|
|
|
if(e&VO_EVENT_EXPOSE && int_pause) flip_page();
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
2003-09-19 16:33:51 +02:00
|
|
|
#endif
|
|
|
|
|
2001-10-07 23:35:59 +02:00
|
|
|
static void draw_osd(void)
|
2001-10-19 12:09:29 +02:00
|
|
|
{ vo_draw_text(image_width,image_height,draw_alpha_fnc); }
|
2001-10-07 23:35:59 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
flip_page(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
drawTextureDisplay();
|
|
|
|
|
|
|
|
// glFlush();
|
|
|
|
glFinish();
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
SwapBuffers(vo_hdc);
|
|
|
|
#else
|
2002-05-15 01:44:35 +02:00
|
|
|
glXSwapBuffers( mDisplay,vo_window );
|
2003-09-19 16:33:51 +02:00
|
|
|
#endif
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
|
|
|
|
static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
|
|
|
|
{
|
2001-10-19 12:09:29 +02:00
|
|
|
return 0;
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
draw_frame_x11_bgr(uint8_t *src[])
|
|
|
|
{
|
2001-10-19 12:09:29 +02:00
|
|
|
resetTexturePointers((unsigned char *)src[0]);
|
|
|
|
ImageData=(unsigned char *)src[0];
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
// for(i=0;i<image_height;i++) ImageData[image_width*image_bytes*i+20]=128;
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
setupTextureDirtyArea(0, 0, image_width, image_height);
|
2001-10-07 23:35:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
draw_frame_x11_rgb(uint8_t *src[])
|
|
|
|
{
|
2001-10-19 12:09:29 +02:00
|
|
|
resetTexturePointers((unsigned char *)src[0]);
|
|
|
|
ImageData=(unsigned char *)src[0];
|
2001-10-07 23:35:59 +02:00
|
|
|
|
2001-10-19 12:09:29 +02:00
|
|
|
setupTextureDirtyArea(0, 0, image_width, image_height);
|
|
|
|
return 0;
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
draw_frame(uint8_t *src[])
|
|
|
|
{
|
|
|
|
uint32_t res = 0;
|
|
|
|
|
2003-05-20 21:30:46 +02:00
|
|
|
if (IMGFMT_IS_RGB(image_format))
|
2001-10-07 23:35:59 +02:00
|
|
|
res = draw_frame_x11_rgb(src);
|
|
|
|
else
|
|
|
|
res = draw_frame_x11_bgr(src);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
query_format(uint32_t format)
|
|
|
|
{
|
|
|
|
switch(format){
|
2003-05-20 21:30:46 +02:00
|
|
|
case IMGFMT_RGB24:
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
// case IMGFMT_RGB32:
|
|
|
|
// case IMGFMT_BGR32:
|
2002-05-27 19:56:52 +02:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD;
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
uninit(void)
|
|
|
|
{
|
2002-05-15 01:44:35 +02:00
|
|
|
if ( !vo_config_count ) return;
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
vo_w32_uninit();
|
|
|
|
#else
|
2002-05-15 01:44:35 +02:00
|
|
|
vo_x11_uninit();
|
2003-09-19 16:33:51 +02:00
|
|
|
#endif
|
2001-10-07 23:35:59 +02:00
|
|
|
}
|
2002-01-26 17:01:26 +01:00
|
|
|
|
|
|
|
static uint32_t preinit(const char *arg)
|
|
|
|
{
|
2002-02-17 09:24:43 +01:00
|
|
|
if(arg)
|
|
|
|
{
|
|
|
|
printf("[gl2] Unknown subdevice: %s\n",arg);
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
2002-10-27 04:16:21 +01:00
|
|
|
if( !vo_init() ) return -1; // Can't open X11
|
2002-02-17 09:24:43 +01:00
|
|
|
return 0;
|
2002-01-26 17:01:26 +01:00
|
|
|
}
|
|
|
|
|
2002-02-09 02:21:48 +01:00
|
|
|
static uint32_t control(uint32_t request, void *data, ...)
|
2002-01-26 17:01:26 +01:00
|
|
|
{
|
2002-02-09 01:47:26 +01:00
|
|
|
switch (request) {
|
2003-09-01 00:27:10 +02:00
|
|
|
case VOCTRL_PAUSE: return (int_pause=1);
|
|
|
|
case VOCTRL_RESUME: return (int_pause=0);
|
2002-02-09 01:47:26 +01:00
|
|
|
case VOCTRL_QUERY_FORMAT:
|
|
|
|
return query_format(*((uint32_t*)data));
|
2003-05-20 21:30:46 +02:00
|
|
|
case VOCTRL_FULLSCREEN:
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifdef GL_WIN32
|
|
|
|
vo_w32_fullscreen();
|
|
|
|
initGl(vo_dwidth, vo_dheight);
|
|
|
|
#else
|
2003-05-20 21:30:46 +02:00
|
|
|
vo_x11_fullscreen();
|
2003-09-19 16:33:51 +02:00
|
|
|
#endif
|
2003-05-20 21:30:46 +02:00
|
|
|
return VO_TRUE;
|
2003-09-19 16:33:51 +02:00
|
|
|
#ifndef GL_WIN32
|
2002-10-29 21:27:47 +01:00
|
|
|
case VOCTRL_SET_EQUALIZER:
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
va_start(ap, data);
|
|
|
|
value = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
|
|
|
return vo_x11_set_equalizer(data, value);
|
|
|
|
}
|
|
|
|
case VOCTRL_GET_EQUALIZER:
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int *value;
|
|
|
|
|
|
|
|
va_start(ap, data);
|
|
|
|
value = va_arg(ap, int *);
|
|
|
|
va_end(ap);
|
|
|
|
return vo_x11_get_equalizer(data, value);
|
|
|
|
}
|
2003-09-19 16:33:51 +02:00
|
|
|
#endif
|
2002-02-09 01:47:26 +01:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
2002-01-26 17:01:26 +01:00
|
|
|
}
|