Mercurial > mplayer.hg
comparison libvo/vo_gl.c @ 12445:d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
author | reimar |
---|---|
date | Sat, 08 May 2004 21:38:41 +0000 |
parents | 2e8b305586a0 |
children | 86774b3d5ede |
comparison
equal
deleted
inserted
replaced
12444:0971849c04b6 | 12445:d97398ed403e |
---|---|
29 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | 29 "Arpad Gereoffy <arpi@esp-team.scene.hu>", |
30 "" | 30 "" |
31 }; | 31 }; |
32 | 32 |
33 LIBVO_EXTERN(gl) | 33 LIBVO_EXTERN(gl) |
34 | |
35 /* local data */ | |
36 static unsigned char *ImageData=NULL; | |
37 | 34 |
38 static GLXContext wsGLXContext; | 35 static GLXContext wsGLXContext; |
39 static int wsGLXAttrib[] = { GLX_RGBA, | 36 static int wsGLXAttrib[] = { GLX_RGBA, |
40 GLX_RED_SIZE,1, | 37 GLX_RED_SIZE,1, |
41 GLX_GREEN_SIZE,1, | 38 GLX_GREEN_SIZE,1, |
46 | 43 |
47 static uint32_t image_width; | 44 static uint32_t image_width; |
48 static uint32_t image_height; | 45 static uint32_t image_height; |
49 static uint32_t image_bytes; | 46 static uint32_t image_bytes; |
50 static int many_fmts; | 47 static int many_fmts; |
48 static GLenum gl_texfmt; | |
51 static GLenum gl_format; | 49 static GLenum gl_format; |
52 static GLenum gl_type; | 50 static GLenum gl_type; |
53 | 51 |
54 static int int_pause; | 52 static int int_pause; |
55 | 53 |
70 glLoadIdentity(); | 68 glLoadIdentity(); |
71 } | 69 } |
72 | 70 |
73 static int find_gl_format (uint32_t format) | 71 static int find_gl_format (uint32_t format) |
74 { | 72 { |
73 image_bytes = (IMGFMT_RGB_DEPTH(format)+7)/8; | |
74 gl_texfmt = 3; | |
75 switch (format) { | 75 switch (format) { |
76 case IMGFMT_RGB24: | 76 case IMGFMT_RGB24: |
77 gl_format = GL_RGB; | 77 gl_format = GL_RGB; |
78 gl_type = GL_UNSIGNED_BYTE; | 78 gl_type = GL_UNSIGNED_BYTE; |
79 break; | 79 break; |
80 case IMGFMT_RGB32: | 80 case IMGFMT_RGB32: |
81 gl_texfmt = 4; | |
81 gl_format = GL_RGBA; | 82 gl_format = GL_RGBA; |
82 gl_type = GL_UNSIGNED_BYTE; | 83 gl_type = GL_UNSIGNED_BYTE; |
83 break; | 84 break; |
84 case IMGFMT_Y800: | 85 case IMGFMT_Y800: |
85 case IMGFMT_Y8: | 86 case IMGFMT_Y8: |
87 gl_texfmt = 1; | |
88 image_bytes = 1; | |
86 gl_format = GL_LUMINANCE; | 89 gl_format = GL_LUMINANCE; |
87 gl_type = GL_UNSIGNED_BYTE; | 90 gl_type = GL_UNSIGNED_BYTE; |
88 break; | 91 break; |
89 #ifdef GL_VERSION_1_2 | 92 #ifdef GL_VERSION_1_2 |
90 case IMGFMT_RGB8: | 93 case IMGFMT_RGB8: |
118 case IMGFMT_BGR24: | 121 case IMGFMT_BGR24: |
119 gl_format = GL_BGR; | 122 gl_format = GL_BGR; |
120 gl_type = GL_UNSIGNED_BYTE; | 123 gl_type = GL_UNSIGNED_BYTE; |
121 break; | 124 break; |
122 case IMGFMT_BGR32: | 125 case IMGFMT_BGR32: |
126 gl_texfmt = 4; | |
123 gl_format = GL_BGRA; | 127 gl_format = GL_BGRA; |
124 gl_type = GL_UNSIGNED_BYTE; | 128 gl_type = GL_UNSIGNED_BYTE; |
125 break; | 129 break; |
126 #endif | 130 #endif |
127 default: | 131 default: |
132 gl_texfmt = 4; | |
128 gl_format = GL_RGBA; | 133 gl_format = GL_RGBA; |
129 gl_type = GL_UNSIGNED_BYTE; | 134 gl_type = GL_UNSIGNED_BYTE; |
130 return 0; | 135 return 0; |
131 } | 136 } |
137 #ifdef TEXTUREFORMAT_32BPP | |
138 gl_texfmt = GL_RGB8; | |
139 #endif | |
132 return 1; | 140 return 1; |
133 } | 141 } |
134 | 142 |
135 /* connect to server, create and map window, | 143 /* connect to server, create and map window, |
136 * allocate colors and (shared) memory | 144 * allocate colors and (shared) memory |
137 */ | 145 */ |
138 static uint32_t | 146 static uint32_t |
139 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) | 147 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
140 { | 148 { |
149 unsigned char *ImageData=NULL; | |
141 // int screen; | 150 // int screen; |
142 unsigned int fg, bg; | 151 unsigned int fg, bg; |
143 XSizeHints hint; | 152 XSizeHints hint; |
144 XVisualInfo *vinfo; | 153 XVisualInfo *vinfo; |
145 XEvent xev; | 154 XEvent xev; |
228 | 237 |
229 texture_width=32; | 238 texture_width=32; |
230 while(texture_width<image_width || texture_width<image_height) texture_width*=2; | 239 while(texture_width<image_width || texture_width<image_height) texture_width*=2; |
231 texture_height=texture_width; | 240 texture_height=texture_width; |
232 | 241 |
233 image_bytes=(IMGFMT_RGB_DEPTH(format)+7)/8; | |
234 | |
235 if ( ImageData ) free( ImageData ); | |
236 ImageData=malloc(texture_width*texture_height*image_bytes); | 242 ImageData=malloc(texture_width*texture_height*image_bytes); |
237 memset(ImageData,128,texture_width*texture_height*image_bytes); | 243 memset(ImageData,128,texture_width*texture_height*image_bytes); |
238 | 244 |
239 glDisable(GL_BLEND); | 245 glDisable(GL_BLEND); |
240 glDisable(GL_DEPTH_TEST); | 246 glDisable(GL_DEPTH_TEST); |
247 | 253 |
248 #if 1 | 254 #if 1 |
249 // glBindTexture(GL_TEXTURE_2D, texture_id); | 255 // glBindTexture(GL_TEXTURE_2D, texture_id); |
250 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 256 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
251 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 257 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
252 /* Old OpenGL 1.0 used the third parameter (known as internalFormat) as an | 258 glTexImage2D(GL_TEXTURE_2D, 0, gl_texfmt, texture_width, texture_height, 0, |
253 integer, which indicated the bytes per pixel (bpp). Later in OpenGL 1.1 | 259 gl_format, gl_type, ImageData); |
254 they switched to constants, like GL_RGB8. GL_RGB8 means 8 bits for each | |
255 channel (R,G,B), so it's equal to RGB24. It should be safe to pass the | |
256 image_bytes to internalFormat with newer OpenGL versions. | |
257 Anyway, I'm leaving this so as it was, it doesn't hurt, as OpenGL 1.1 is | |
258 about 10 years old too. -- alex | |
259 */ | |
260 #ifdef TEXTUREFORMAT_32BPP | |
261 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, | |
262 #else | |
263 glTexImage2D(GL_TEXTURE_2D, 0, image_bytes, texture_width, texture_height, 0, | |
264 #endif | 260 #endif |
265 (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); | 261 |
266 #endif | 262 free (ImageData); |
267 | 263 |
268 resize(d_width,d_height); | 264 resize(d_width,d_height); |
269 | 265 |
270 glClearColor( 1.0f,0.0f,1.0f,0.0f ); | 266 glClearColor( 1.0f,0.0f,1.0f,0.0f ); |
271 glClear( GL_COLOR_BUFFER_BIT ); | 267 glClear( GL_COLOR_BUFFER_BIT ); |