[MPlayer-cvslog] CVS: main/libvo gl_common.c, 1.10, 1.11 gl_common.h, 1.8, 1.9 vo_gl.c, 1.79, 1.80 vo_gl2.c, 1.67, 1.68

Reimar Döffinger CVS syncmail at mplayerhq.hu
Sun Aug 14 15:44:17 CEST 2005


CVS change done by Reimar Döffinger CVS

Update of /cvsroot/mplayer/main/libvo
In directory mail:/var2/tmp/cvs-serv5310/libvo

Modified Files:
	gl_common.c gl_common.h vo_gl.c vo_gl2.c 
Log Message:
Helper function for drawing texture and general cleanup of vo_gl2.c


Index: gl_common.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/gl_common.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- gl_common.c	27 Jul 2005 17:22:24 -0000	1.10
+++ gl_common.c	14 Aug 2005 13:44:14 -0000	1.11
@@ -345,6 +345,38 @@
     glTexSubImage2D(target, 0, x, y, w, y_max - y, format, type, data);
 }
 
+/**
+ * \brief draw a texture part at given 2D coordinates
+ * \param x screen top coordinate
+ * \param y screen left coordinate
+ * \param w screen width coordinate
+ * \param h screen height coordinate
+ * \param tx texture top coordinate in pixels
+ * \param ty texture left coordinate in pixels
+ * \param tw texture part width in pixels
+ * \param th texture part height in pixels
+ * \param sx width of texture in pixels
+ * \param sy height of texture in pixels
+ * \param rect_tex whether this texture uses texture_rectangle extension
+ */
+void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
+               GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
+               int sx, int sy, int rect_tex) {
+  if (!rect_tex) {
+    tx /= sx; ty /= sy; tw /= sx; th /= sy;
+  }
+  glBegin(GL_QUADS);
+  glTexCoord2f(tx, ty);
+  glVertex2f(x, y);
+  glTexCoord2f(tx, ty + th);
+  glVertex2f(x, y + h);
+  glTexCoord2f(tx + tw, ty + th);
+  glVertex2f(x + w, y + h);
+  glTexCoord2f(tx + tw, ty);
+  glVertex2f(x + w, y);
+  glEnd();
+}
+
 #ifdef GL_WIN32
 static void *w32gpa(const GLubyte *procName) {
   return wglGetProcAddress(procName);

Index: gl_common.h
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/gl_common.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- gl_common.h	27 Jul 2005 17:22:24 -0000	1.8
+++ gl_common.h	14 Aug 2005 13:44:14 -0000	1.9
@@ -66,6 +66,9 @@
 void glUploadTex(GLenum target, GLenum format, GLenum type,
                  const char *data, int stride,
                  int x, int y, int w, int h, int slice);
+void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
+               GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
+               int sx, int sy, int rect_tex);
 
 //! could not set new window, will continue drawing into the old one.
 #define SET_WINDOW_FAILED -1

Index: vo_gl.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_gl.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- vo_gl.c	5 Aug 2005 01:24:36 -0000	1.79
+++ vo_gl.c	14 Aug 2005 13:44:14 -0000	1.80
@@ -307,15 +307,8 @@
   int i;
   // initialize to 8 to avoid special-casing on alignment
   int sx = 8, sy = 8;
-  GLfloat xcov, ycov;
   GLint scale_type = (scaled_osd) ? GL_LINEAR : GL_NEAREST;
   texSize(w, h, &sx, &sy);
-  xcov = (GLfloat) w / (GLfloat) sx;
-  ycov = (GLfloat) h / (GLfloat) sy;
-  if (use_rectangle == 1) {
-    xcov = w;
-    ycov = h;
-  }
 
   if (osdtexCnt >= MAX_OSD_PARTS) {
     mp_msg(MSGT_VO, MSGL_ERR, "Too many OSD parts, contact the developers!\n");
@@ -352,30 +345,12 @@
   // render alpha
   glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
   BindTexture(gl_target, osdatex[osdtexCnt]);
-  glBegin(GL_QUADS);
-  glTexCoord2f (0, 0);
-  glVertex2f (x0, y0);
-  glTexCoord2f (0, ycov);
-  glVertex2f (x0, y0 + h);
-  glTexCoord2f (xcov, ycov);
-  glVertex2f (x0 + w, y0 + h);
-  glTexCoord2f (xcov, 0);
-  glVertex2f (x0 + w, y0);
-  glEnd();
+  glDrawTex(x0, y0, w, h, 0, 0, w, h, sx, sy, use_rectangle == 1);
 #endif
   // render OSD
   glBlendFunc (GL_ONE, GL_ONE);
   BindTexture(gl_target, osdtex[osdtexCnt]);
-  glBegin(GL_QUADS);
-  glTexCoord2f (0, 0);
-  glVertex2f (x0, y0);
-  glTexCoord2f (0, ycov);
-  glVertex2f (x0, y0 + h);
-  glTexCoord2f (xcov, ycov);
-  glVertex2f (x0 + w, y0 + h);
-  glTexCoord2f (xcov, 0);
-  glVertex2f (x0 + w, y0);
-  glEnd();
+  glDrawTex(x0, y0, w, h, 0, 0, w, h, sx, sy, use_rectangle == 1);
   glEndList();
 
   osdtexCnt++;
@@ -405,22 +380,13 @@
 static void
 flip_page(void)
 {
-  int tc_x = 1, tc_y = 1;
-  if (use_rectangle == 1) {
-    tc_x = texture_width;
-    tc_y = texture_height;
-  }
-
 //  glEnable(GL_TEXTURE_2D);
 //  glBindTexture(GL_TEXTURE_2D, texture_id);
 
   glColor3f(1,1,1);
-  glBegin(GL_QUADS);
-    glTexCoord2f(0,0);glVertex2i(0,0);
-    glTexCoord2f(0,tc_y);glVertex2i(0,texture_height);
-    glTexCoord2f(tc_x,tc_y);glVertex2i(texture_width,texture_height);
-    glTexCoord2f(tc_x,0);glVertex2i(texture_width,0);
-  glEnd();
+  glDrawTex(0, 0, texture_width, texture_height,
+            0, 0, texture_width, texture_height,
+            texture_width, texture_height, use_rectangle == 1);
 
   if (osdtexCnt > 0) {
     // set special rendering parameters

Index: vo_gl2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_gl2.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- vo_gl2.c	5 Aug 2005 01:24:36 -0000	1.67
+++ vo_gl2.c	14 Aug 2005 13:44:14 -0000	1.68
@@ -70,7 +70,6 @@
 static uint32_t texture_width;
 static uint32_t texture_height;
 static int texnumx, texnumy, raw_line_len;
-static GLfloat texpercx, texpercy;
 static struct TexSquare * texgrid = NULL;
 static GLint    gl_internal_format;
 static int      rgb_sz, r_sz, g_sz, b_sz, a_sz;
@@ -92,22 +91,11 @@
   GLubyte *texture;
   GLuint texobj;
   int isTexture;
-  GLfloat fx1, fy1, fx2, fy2, fx3, fy3, fx4, fy4;
-  GLfloat xcov, ycov;
+  GLfloat fx, fy, fw, fh;
   int isDirty;
   int dirtyXoff, dirtyYoff, dirtyWidth, dirtyHeight;
 };
 
-static void resetTexturePointers(unsigned char *imageSource);
-
-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;
-}
-
 static GLint getInternalFormat()
 {
 #ifdef GL_WIN32
@@ -161,20 +149,21 @@
 static int initTextures()
 {
   struct TexSquare *tsq=0;
-  int e_x, e_y, s, i=0;
+  GLfloat texpercx, texpercy;
+  int 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;
+  s=1;
   while (s<texture_width)
-  { s*=2; e_x++; }
+    s*=2;
   texture_width=s;
 
-  e_y=0; s=1;
+  s=1;
   while (s<texture_height)
-  { s*=2; e_y++; }
+    s*=2;
   texture_height=s;
 
   gl_internal_format = getInternalFormat();
@@ -196,19 +185,9 @@
 		texture_height, texture_width);
 
       if (texture_width > texture_height)
-      {
-	e_x--;
-	texture_width = 1;
-	for (i = e_x; i > 0; i--)
-	  texture_width *= 2;
-      }
+        texture_width /= 2;
       else
-      {
-	e_y--;
-	texture_height = 1;
-	for (i = e_y; i > 0; i--)
-	  texture_height *= 2;
-      }
+        texture_height /= 2;
 
       mp_msg (MSGT_VO, MSGL_V, "[%dx%d] !\n", texture_height, texture_width);
 
@@ -235,12 +214,7 @@
   /* 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;
 
   if (texgrid)
     free(texgrid);
@@ -253,28 +227,16 @@
 		 (int) texnumx, (int) texture_width, (int) texnumy,
 		 (int) texture_height);
 
+  tsq = texgrid;
   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));
+      tsq->fx = x * texpercx;
+      tsq->fy = y * texpercy;
+      tsq->fw = texpercx;
+      tsq->fh = texpercy;
 
       tsq->isDirty=GL_TRUE;
       tsq->isTexture=GL_FALSE;
@@ -298,24 +260,14 @@
         tsq->isTexture=GL_TRUE;
       }
 
-      glTexImage2D (GL_TEXTURE_2D, 0,
-		    gl_internal_format,
-		    texture_width, texture_height,
-		    0, gl_bitmap_format, gl_bitmap_type, NULL); 
-
-      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);
+      glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, GL_LINEAR,
+                       texture_width, texture_height, 0);
 
       glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
+      tsq++;
     }	/* for all texnumx */
   }  /* for all texnumy */
-  resetTexturePointers (ImageData);
   
   return 0;
 }
@@ -488,7 +440,7 @@
 
 static void drawTextureDisplay ()
 {
-  struct TexSquare *square;
+  struct TexSquare *square = texgrid;
   int x, y/*, xoff=0, yoff=0, wd, ht*/;
   GLenum err;
 
@@ -498,8 +450,6 @@
   {
     for (x = 0; x < texnumx; x++)
     {
-      square = texgrid + y * texnumx + x;
-
       if(square->isTexture==GL_FALSE)
       {
         mp_msg (MSGT_VO, MSGL_V, "[gl2] ain't a texture(update): texnum x=%d, y=%d, texture=%d\n",
@@ -538,27 +488,10 @@
         mp_msg (MSGT_VO, MSGL_DBG2, "[gl2] glTexSubImage2D texnum x=%d, y=%d, %d/%d - %d/%d\n", 
 		x, y, square->dirtyXoff, square->dirtyYoff, square->dirtyWidth, square->dirtyHeight);
 
-	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);
-
-	glEnd();
-/*
-#ifndef NDEBUG
-        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,
-	square->fx3, square->fy3, square->fx2, square->fy2);
-#endif
-*/
+      glDrawTex(square->fx, square->fy, square->fw, square->fh,
+                0, 0, texture_width, texture_height,
+                texture_width, texture_height, 0);
+      square++;
     } /* for all texnumx */
   } /* for all texnumy */
 
@@ -776,12 +709,6 @@
 
 static int initGl(uint32_t d_width, uint32_t d_height)
 {
-  ImageData=malloc(image_width*image_height*image_bytes);
-  memset(ImageData,128,image_width*image_height*image_bytes);
-
-  texture_width=image_width;
-  texture_height=image_height;
-    
   if (initTextures() < 0)
     return -1;
 
@@ -815,9 +742,6 @@
 
   drawTextureDisplay ();
 
-  free (ImageData);
-  ImageData = NULL;
-
   return 0;
 }
 
@@ -998,40 +922,13 @@
     return 0;
 }
 
-static inline uint32_t 
-draw_frame_x11_bgr(uint8_t *src[])
-{
-      resetTexturePointers((unsigned char *)src[0]);
-      ImageData=(unsigned char *)src[0];
-
-      // for(i=0;i<image_height;i++) ImageData[image_width*image_bytes*i+20]=128;
-
-     setupTextureDirtyArea(0, 0, image_width, image_height);
-	return 0; 
-}
-
-static inline uint32_t 
-draw_frame_x11_rgb(uint8_t *src[])
-{
-      resetTexturePointers((unsigned char *)src[0]);
-      ImageData=(unsigned char *)src[0];
-
-     setupTextureDirtyArea(0, 0, image_width, image_height);
-      return 0; 
-}
-
-
 static int
 draw_frame(uint8_t *src[])
 {
-    uint32_t res = 0;
-
-    if (IMGFMT_IS_RGB(image_format))
-	res = draw_frame_x11_rgb(src);
-    else
-	res = draw_frame_x11_bgr(src);
-
-    return res;
+  ImageData=(unsigned char *)src[0];
+  resetTexturePointers(ImageData);
+  setupTextureDirtyArea(0, 0, image_width, image_height);
+  return 0;
 }
 
 static int




More information about the MPlayer-cvslog mailing list