summaryrefslogtreecommitdiffstats
path: root/libvo/gl_common.c
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-12-01 17:05:58 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-12-01 17:05:58 +0000
commitc977dab4562f5ee1324a971d396a997baf341383 (patch)
treeb13a36cea80220e5c68a83822fe7d410ed48bb9f /libvo/gl_common.c
parente6524e5b0958e8b798e160c6ae555f5495c5f5eb (diff)
downloadmpv-c977dab4562f5ee1324a971d396a997baf341383.tar.bz2
mpv-c977dab4562f5ee1324a971d396a997baf341383.tar.xz
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
Diffstat (limited to 'libvo/gl_common.c')
-rw-r--r--libvo/gl_common.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/libvo/gl_common.c b/libvo/gl_common.c
index 7c82c74076..3526195618 100644
--- a/libvo/gl_common.c
+++ b/libvo/gl_common.c
@@ -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.