changeset 34337:f8c523d09e5e

Use glLoadMatrixf. This makes it easier to support OpenGL ES.
author reimar
date Sat, 10 Dec 2011 20:21:50 +0000
parents dd3d2c5dd021
children 4a507d3a039a
files libvo/gl_common.c libvo/gl_common.h libvo/matrixview.c libvo/vo_gl.c libvo/vo_gl2.c
diffstat 5 files changed, 42 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/gl_common.c	Sat Dec 10 14:31:28 2011 +0000
+++ b/libvo/gl_common.c	Sat Dec 10 20:21:50 2011 +0000
@@ -49,10 +49,7 @@
 void (GLAPIENTRY *mpglViewport)(GLint, GLint, GLsizei, GLsizei);
 void (GLAPIENTRY *mpglMatrixMode)(GLenum);
 void (GLAPIENTRY *mpglLoadIdentity)(void);
-void (GLAPIENTRY *mpglTranslated)(double, double, double);
-void (GLAPIENTRY *mpglScaled)(double, double, double);
-void (GLAPIENTRY *mpglOrtho)(double, double, double, double, double, double);
-void (GLAPIENTRY *mpglFrustum)(double, double, double, double, double, double);
+void (GLAPIENTRY *mpglLoadMatrixf)(float *);
 void (GLAPIENTRY *mpglPushMatrix)(void);
 void (GLAPIENTRY *mpglPopMatrix)(void);
 void (GLAPIENTRY *mpglClear)(GLbitfield);
@@ -396,10 +393,7 @@
   DEF_FUNC_DESC(Viewport),
   DEF_FUNC_DESC(MatrixMode),
   DEF_FUNC_DESC(LoadIdentity),
-  DEF_FUNC_DESC(Translated),
-  DEF_FUNC_DESC(Scaled),
-  DEF_FUNC_DESC(Ortho),
-  DEF_FUNC_DESC(Frustum),
+  DEF_FUNC_DESC(LoadMatrixf),
   DEF_FUNC_DESC(PushMatrix),
   DEF_FUNC_DESC(PopMatrix),
   DEF_FUNC_DESC(Clear),
--- a/libvo/gl_common.h	Sat Dec 10 14:31:28 2011 +0000
+++ b/libvo/gl_common.h	Sat Dec 10 20:21:50 2011 +0000
@@ -441,10 +441,7 @@
 extern void (GLAPIENTRY *mpglViewport)(GLint, GLint, GLsizei, GLsizei);
 extern void (GLAPIENTRY *mpglMatrixMode)(GLenum);
 extern void (GLAPIENTRY *mpglLoadIdentity)(void);
-extern void (GLAPIENTRY *mpglTranslated)(double, double, double);
-extern void (GLAPIENTRY *mpglScaled)(double, double, double);
-extern void (GLAPIENTRY *mpglOrtho)(double, double, double, double, double, double);
-extern void (GLAPIENTRY *mpglFrustum)(double, double, double, double, double, double);
+extern void (GLAPIENTRY *mpglLoadMatrixf)(float *);
 extern void (GLAPIENTRY *mpglPushMatrix)(void);
 extern void (GLAPIENTRY *mpglPopMatrix)(void);
 extern void (GLAPIENTRY *mpglClear)(GLbitfield);
--- a/libvo/matrixview.c	Sat Dec 10 14:31:28 2011 +0000
+++ b/libvo/matrixview.c	Sat Dec 10 20:21:50 2011 +0000
@@ -310,15 +310,23 @@
 
 void matrixview_reshape(int w, int h)
 {
+    double nearplane = -Z_Off - Z_Depth;
+    // perspective projection, also adjusting vertex position
+    // by Z_Off and with simplified Z equation since the absolute
+    // Z value does not matter, only relative to other pixels
+    float matrix[16] = {
+      nearplane / _text_x, 0, 0, 0,
+      0, nearplane / _text_y, 0, 0,
+      0, 0,  1, -1,
+      0, 0,  0, -Z_Off
+    };
     mpglViewport(0, 0, w, h);
 
     mpglMatrixMode(GL_PROJECTION);
-    mpglLoadIdentity();
-    mpglFrustum(-_text_x, _text_x, -_text_y, _text_y, -Z_Off - Z_Depth, -Z_Off);
+    mpglLoadMatrixf(matrix);
 
     mpglMatrixMode(GL_MODELVIEW);
     mpglLoadIdentity();
-    mpglTranslated(0.0f, 0.0f, Z_Off);
 }
 
 
--- a/libvo/vo_gl.c	Sat Dec 10 14:31:28 2011 +0000
+++ b/libvo/vo_gl.c	Sat Dec 10 20:21:50 2011 +0000
@@ -172,6 +172,13 @@
 static void redraw(void);
 
 static void resize(int x,int y){
+  // simple orthogonal projection for 0-image_width;0-image_height
+  float matrix[16] = {
+    2.0/image_width,   0, 0, 0,
+    0, -2.0/image_height, 0, 0,
+    0, 0, 0, 0,
+    -1, 1, 0, 1
+  };
   mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n",x,y);
   if (WinID >= 0) {
     int left = 0, top = 0, w = x, h = y;
@@ -182,7 +189,6 @@
     mpglViewport( 0, 0, x, y );
 
   mpglMatrixMode(GL_PROJECTION);
-  mpglLoadIdentity();
   ass_border_x = ass_border_y = 0;
   if (aspect_scaling() && use_aspect) {
     int new_w, new_h;
@@ -193,11 +199,14 @@
     new_h += vo_panscan_y;
     scale_x = (GLdouble)new_w / (GLdouble)x;
     scale_y = (GLdouble)new_h / (GLdouble)y;
-    mpglScaled(scale_x, scale_y, 1);
+    matrix[0]  *= scale_x;
+    matrix[12] *= scale_x;
+    matrix[5]  *= scale_y;
+    matrix[13] *= scale_y;
     ass_border_x = (vo_dwidth - new_w) / 2;
     ass_border_y = (vo_dheight - new_h) / 2;
   }
-  mpglOrtho(0, image_width, image_height, 0, -1,1);
+  mpglLoadMatrixf(matrix);
 
   mpglMatrixMode(GL_MODELVIEW);
   mpglLoadIdentity();
@@ -775,10 +784,16 @@
     return;
   // set special rendering parameters
   if (!scaled_osd) {
+    // simple orthogonal projection for 0-vo_dwidth;0-vo_dheight
+    float matrix[16] = {
+      2.0/vo_dwidth,   0, 0, 0,
+      0, -2.0/vo_dheight, 0, 0,
+      0,  0, 0, 0,
+      -1, 1, 0, 1
+    };
     mpglMatrixMode(GL_PROJECTION);
     mpglPushMatrix();
-    mpglLoadIdentity();
-    mpglOrtho(0, vo_dwidth, vo_dheight, 0, -1, 1);
+    mpglLoadMatrixf(matrix);
   }
   mpglEnable(GL_BLEND);
   if (draw_eosd) {
--- a/libvo/vo_gl2.c	Sat Dec 10 14:31:28 2011 +0000
+++ b/libvo/vo_gl2.c	Sat Dec 10 20:21:50 2011 +0000
@@ -423,6 +423,13 @@
 
 
 static void resize(int x,int y){
+  // simple orthogonal projection for 0-1;0-1
+  static const float matrix[16] = {
+     2,  0, 0, 0,
+     0, -2, 0, 0,
+     0,  0, 0, 0,
+    -1,  1, 0, 1,
+  };
   mp_msg(MSGT_VO,MSGL_V,"[gl2] Resize: %dx%d\n",x,y);
   if(aspect_scaling()) {
     glClear(GL_COLOR_BUFFER_BIT);
@@ -443,8 +450,7 @@
   }
 
   glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  glOrtho (0, 1, 1, 0, -1.0, 1.0);
+  glLoadMatrixf(matrix);
 
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();