1
mirror of https://github.com/mpv-player/mpv synced 2024-09-12 23:45:53 +02:00

More similar code from gl and gl2 moved to gl_common

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14079 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2004-12-01 17:05:58 +00:00
parent e6524e5b09
commit c977dab456
4 changed files with 177 additions and 159 deletions

View File

@ -17,6 +17,167 @@ void glAdjustAlignment(int stride) {
glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment);
}
#include "img_format.h"
struct gl_name_map_struct {
GLint value;
char *name;
};
#undef MAP
#define MAP(a) {a, #a}
static const struct gl_name_map_struct gl_name_map[] = {
// internal format
MAP(GL_R3_G3_B2), MAP(GL_RGB4), MAP(GL_RGB5), MAP(GL_RGB8),
MAP(GL_RGB10), MAP(GL_RGB12), MAP(GL_RGB16), MAP(GL_RGBA2),
MAP(GL_RGBA4), MAP(GL_RGB5_A1), MAP(GL_RGBA8), MAP(GL_RGB10_A2),
MAP(GL_RGBA12), MAP(GL_RGBA16), MAP(GL_LUMINANCE8),
// format
MAP(GL_RGB), MAP(GL_RGBA), MAP(GL_RED), MAP(GL_GREEN), MAP(GL_BLUE),
MAP(GL_ALPHA), MAP(GL_LUMINANCE), MAP(GL_LUMINANCE_ALPHA),
MAP(GL_COLOR_INDEX),
// rest 1.2 only
#ifdef GL_VERSION_1_2
MAP(GL_BGR), MAP(GL_BGRA),
#endif
//type
MAP(GL_BYTE), MAP(GL_UNSIGNED_BYTE), MAP(GL_SHORT), MAP(GL_UNSIGNED_SHORT),
MAP(GL_INT), MAP(GL_UNSIGNED_INT), MAP(GL_FLOAT), MAP(GL_DOUBLE),
MAP(GL_2_BYTES), MAP(GL_3_BYTES), MAP(GL_4_BYTES),
// rest 1.2 only
#ifdef GL_VERSION_1_2
MAP(GL_UNSIGNED_BYTE_3_3_2), MAP(GL_UNSIGNED_BYTE_2_3_3_REV),
MAP(GL_UNSIGNED_SHORT_5_6_5), MAP(GL_UNSIGNED_SHORT_5_6_5_REV),
MAP(GL_UNSIGNED_SHORT_4_4_4_4), MAP(GL_UNSIGNED_SHORT_4_4_4_4_REV),
MAP(GL_UNSIGNED_SHORT_5_5_5_1), MAP(GL_UNSIGNED_SHORT_1_5_5_5_REV),
MAP(GL_UNSIGNED_INT_8_8_8_8), MAP(GL_UNSIGNED_INT_8_8_8_8_REV),
MAP(GL_UNSIGNED_INT_10_10_10_2), MAP(GL_UNSIGNED_INT_2_10_10_10_REV),
#endif
{0, 0}
};
#undef MAP
/**
* \brief return the name of an OpenGL constant
* \param value the constant
* \return name of the constant or "Unknown format!"
*/
const char *glValName(GLint value)
{
int i = 0;
while (gl_name_map[i].name) {
if (gl_name_map[i].value == value)
return gl_name_map[i].name;
i++;
}
return "Unknown format!";
}
#undef TEXTUREFORMAT_ALWAYS
//! always return this format as internal texture format in glFindFormat
#define TEXTUREFORMAT_ALWAYS GL_RGB8
/**
* \brief find the OpenGL settings coresponding to format.
*
* All parameters may be NULL.
* \param fmt MPlayer format to analyze.
* \param bpp [OUT] bits per pixel of that format.
* \param gl_texfmt [OUT] internal texture format that fits the
* image format, not necessarily the best for performance.
* \param gl_format [OUT] OpenGL format for this image format.
* \param gl_type [OUT] OpenGL type for this image format.
* \return 1 if format is supported by OpenGL, 0 if not.
*/
int glFindFormat(uint32_t fmt, uint32_t *bpp, GLenum *gl_texfmt,
GLenum *gl_format, GLenum *gl_type)
{
int dummy1;
GLenum dummy2;
if (bpp == NULL) bpp = &dummy1;
if (gl_texfmt == NULL) gl_texfmt = &dummy2;
if (gl_format == NULL) gl_format = &dummy2;
if (gl_type == NULL) gl_type = &dummy2;
*bpp = IMGFMT_IS_BGR(fmt)?IMGFMT_BGR_DEPTH(fmt):IMGFMT_RGB_DEPTH(fmt);
*gl_texfmt = 3;
switch (fmt) {
case IMGFMT_RGB24:
*gl_format = GL_RGB;
*gl_type = GL_UNSIGNED_BYTE;
break;
case IMGFMT_RGBA:
*gl_texfmt = 4;
*gl_format = GL_RGBA;
*gl_type = GL_UNSIGNED_BYTE;
break;
case IMGFMT_Y800:
case IMGFMT_Y8:
*gl_texfmt = 1;
*bpp = 8;
*gl_format = GL_LUMINANCE;
*gl_type = GL_UNSIGNED_BYTE;
break;
#ifdef GL_VERSION_1_2
#if 0
// we do not support palettized formats, although the format the
// swscale produces works
case IMGFMT_RGB8:
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE_2_3_3_REV;
break;
#endif
case IMGFMT_RGB15:
*gl_format = GL_RGBA;
*gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
case IMGFMT_RGB16:
*gl_format = GL_RGB;
*gl_type = GL_UNSIGNED_SHORT_5_6_5_REV;
break;
#if 0
case IMGFMT_BGR8:
// special case as red and blue have a differen number of bits.
// GL_BGR and GL_UNSIGNED_BYTE_3_3_2 isn't supported at least
// by nVidia drivers, and in addition would give more bits to
// blue than to red, which isn't wanted
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE_3_3_2;
break;
#endif
case IMGFMT_BGR15:
*gl_format = GL_BGRA;
*gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
case IMGFMT_BGR16:
*gl_format = GL_RGB;
*gl_type = GL_UNSIGNED_SHORT_5_6_5;
break;
case IMGFMT_BGR24:
*gl_format = GL_BGR;
*gl_type = GL_UNSIGNED_BYTE;
break;
case IMGFMT_BGRA:
*gl_texfmt = 4;
*gl_format = GL_BGRA;
*gl_type = GL_UNSIGNED_BYTE;
break;
#endif
default:
*gl_texfmt = 4;
*gl_format = GL_RGBA;
*gl_type = GL_UNSIGNED_BYTE;
return 0;
}
#ifdef TEXTUREFORMAT_ALWAYS
*gl_texfmt = TEXTUREFORMAT_ALWAYS;
#endif
return 1;
}
#ifndef GL_WIN32
/**
* Returns the XVisualInfo associated with Window win.

View File

@ -15,6 +15,11 @@
void glAdjustAlignment(int stride);
const char *glValName(GLint value);
int glFindFormat(uint32_t format, uint32_t *bpp, GLenum *gl_texfmt,
GLenum *gl_format, GLenum *gl_type);
//! could not set new window, will continue drawing into the old one.
#define SET_WINDOW_FAILED -1
//! new window is set, could even transfer the OpenGL context.

View File

@ -1,5 +1,3 @@
#define TEXTUREFORMAT_ALWAYS GL_RGB8
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -104,84 +102,6 @@ static void resize(int x,int y){
}
}
static int find_gl_format (uint32_t format)
{
image_bytes = (IMGFMT_RGB_DEPTH(format)+7)/8;
gl_texfmt = 3;
switch (format) {
case IMGFMT_RGB24:
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE;
break;
case IMGFMT_RGBA:
gl_texfmt = 4;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
break;
case IMGFMT_Y800:
case IMGFMT_Y8:
gl_texfmt = 1;
image_bytes = 1;
gl_format = GL_LUMINANCE;
gl_type = GL_UNSIGNED_BYTE;
break;
#ifdef GL_VERSION_1_2
#if 0
// we do not support palettized formats, although the format the
// swscale produces works
case IMGFMT_RGB8:
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE_2_3_3_REV;
break;
#endif
case IMGFMT_RGB15:
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
case IMGFMT_RGB16:
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_SHORT_5_6_5_REV;
break;
#if 0
case IMGFMT_BGR8:
// special case as red and blue have a differen number of bits.
// GL_BGR and GL_UNSIGNED_BYTE_3_3_2 isn't supported at least
// by nVidia drivers, and in addition would give more bits to
// blue than to red, which isn't wanted
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE_3_3_2;
break;
#endif
case IMGFMT_BGR15:
gl_format = GL_BGRA;
gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
case IMGFMT_BGR16:
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_SHORT_5_6_5;
break;
case IMGFMT_BGR24:
gl_format = GL_BGR;
gl_type = GL_UNSIGNED_BYTE;
break;
case IMGFMT_BGRA:
gl_texfmt = 4;
gl_format = GL_BGRA;
gl_type = GL_UNSIGNED_BYTE;
break;
#endif
default:
gl_texfmt = 4;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
return 0;
}
#ifdef TEXTUREFORMAT_ALWAYS
gl_texfmt = TEXTUREFORMAT_ALWAYS;
#endif
return 1;
}
/**
* \brief Initialize a (new or reused) OpenGL context.
*/
@ -230,7 +150,8 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
{
image_height = height;
image_width = width;
find_gl_format (format);
glFindFormat(format, &image_bytes, &gl_texfmt, &gl_format, &gl_type);
image_bytes = (image_bytes + 7) / 8;
sub_bg_alpha = 255; // We need alpha = 255 for invisible part of the OSD
int_pause = 0;
@ -529,7 +450,8 @@ query_format(uint32_t format)
caps |= VFCAP_OSD;
if ((format == IMGFMT_RGB24) || (format == IMGFMT_RGBA))
return caps;
if (many_fmts && find_gl_format(format))
if (many_fmts &&
glFindFormat(format, NULL, NULL, NULL, NULL))
return caps;
return 0;
}

View File

@ -43,10 +43,8 @@
//#undef NDEBUG
#undef TEXTUREFORMAT_ALWAYS
#undef TEXTUREFORMAT_ALWAYS_S
#ifdef SYS_DARWIN
#define TEXTUREFORMAT_ALWAYS GL_RGBA8
#define TEXTUREFORMAT_ALWAYS_S "GL_RGBA8"
#endif
static vo_info_t info =
@ -81,7 +79,6 @@ static uint32_t image_width;
static uint32_t image_height;
static uint32_t image_format;
static uint32_t image_bpp;
static int image_mode;
static uint32_t image_bytes;
static int int_pause;
@ -92,12 +89,9 @@ static int texnumx, texnumy, raw_line_len;
static GLfloat texpercx, texpercy;
static struct TexSquare * texgrid = NULL;
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 isGL12 = GL_FALSE;
static int gl_bilinear=1;
@ -794,10 +788,10 @@ static int initGl(uint32_t d_width, uint32_t d_height)
gl_set_antialias(0);
gl_set_bilinear(1);
mp_msg(MSGT_VO, MSGL_V, "[gl2] Using image_bpp=%d, image_bytes=%d, isBGR=%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",
image_bpp, image_bytes, image_mode==MODE_BGR,
gl_bitmap_format_s, gl_bitmap_type_s,
rgb_sz, r_sz, g_sz, b_sz, a_sz, gl_internal_format_s);
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",
image_bpp, image_bytes,
glValName(gl_bitmap_format), glValName(gl_bitmap_type),
rgb_sz, r_sz, g_sz, b_sz, a_sz, glValName(gl_internal_format));
resize(&d_width, &d_height);
@ -871,54 +865,33 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
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";
}
#ifdef TEXTUREFORMAT_ALWAYS
gl_internal_format=TEXTUREFORMAT_ALWAYS;
gl_internal_format_s=TEXTUREFORMAT_ALWAYS_S;
#endif
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);
}
glFindFormat(format, &image_bpp, NULL, &gl_bitmap_format, &gl_bitmap_type);
image_bytes=(image_bpp+7)/8;
@ -927,58 +900,15 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
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
break;
case 16:
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;
}
if (initGl(d_width, d_height) == -1)