gpu-gles: add fps display
authornotaz <notasas@gmail.com>
Fri, 20 Jan 2012 01:09:21 +0000 (03:09 +0200)
committernotaz <notasas@gmail.com>
Fri, 20 Jan 2012 22:05:13 +0000 (00:05 +0200)
plugins/gpu-gles/gpulib_if.c
plugins/gpu-gles/hud.c [new file with mode: 0644]

index a8daa5e..569fff4 100644 (file)
@@ -19,6 +19,7 @@
 #include "gpuDraw.c"
 #include "gpuTexture.c"
 #include "gpuPrim.c"
+#include "hud.c"
 
 static const short dispWidths[8] = {256,320,512,640,368,384,512,640};
 short g_m1,g_m2,g_m3;
@@ -84,6 +85,8 @@ static void PaintBlackBorders(void)
  glEnable(GL_SCISSOR_TEST); glError();
 }
 
+static void fps_update(void);
+
 void updateDisplay(void)
 {
  bFakeFrontBuffer=FALSE;
@@ -120,8 +123,11 @@ void updateDisplay(void)
  }
 
  if(iDrawnSomething)
+ {
+  fps_update();
   eglSwapBuffers(display, surface);
- iDrawnSomething=0;
+  iDrawnSomething=0;
+ }
 
  if(lClearOnSwap)                                     // clear buffer after swap?
  {
@@ -622,6 +628,8 @@ void vout_update(void)
 
 long GPUopen(void **dpy)
 {
+ int ret;
+
  iResX = 800; iResY = 480;
  rRatioRect.left   = rRatioRect.top=0;
  rRatioRect.right  = iResX;
@@ -632,27 +640,29 @@ long GPUopen(void **dpy)
  CSTEXTURE = CSVERTEX = CSCOLOR = 0;
 
  InitializeTextureStore();                             // init texture mem
- is_opened = 1;
 
- return GLinitialize();
+ ret = GLinitialize();
+ MakeDisplayLists();
+
+ is_opened = 1;
+ return ret;
 }
 
 long GPUclose(void)
 {
  is_opened = 0;
 
+ KillDisplayLists();
  GLcleanup();                                          // close OGL
  return 0;
 }
 
-//#include "../../frontend/plugin_lib.h"
-
-static const struct rearmed_cbs *cbs;
+static struct rearmed_cbs *cbs;
 
 /* acting as both renderer and vout handler here .. */
 void renderer_set_config(const struct rearmed_cbs *cbs_)
 {
- cbs = cbs_;
+ cbs = (void *)cbs_; // ugh..
 
  iOffscreenDrawing = 0;
  iZBufferDepth = 0;
@@ -687,3 +697,20 @@ void SetAspectRatio(void)
            rRatioRect.right,rRatioRect.bottom);
  glError();
 }
+
+static void fps_update(void)
+{
+ char buf[16];
+
+ cbs->flip_cnt++;
+ if(cbs->flips_per_sec != 0)
+ {
+  snprintf(buf,sizeof(buf),"%2d %4.1f",cbs->flips_per_sec,cbs->vsps_cur);
+  DisplayText(buf, 0);
+ }
+ if(cbs->cpu_usage != 0)
+ {
+  snprintf(buf,sizeof(buf),"%3d",cbs->cpu_usage);
+  DisplayText(buf, 1);
+ }
+}
diff --git a/plugins/gpu-gles/hud.c b/plugins/gpu-gles/hud.c
new file mode 100644 (file)
index 0000000..251423b
--- /dev/null
@@ -0,0 +1,318 @@
+/***************************************************************************\r
+                           menu.c  -  description\r
+                             -------------------\r
+    begin                : Sun Mar 08 2009\r
+    copyright            : (C) 1999-2009 by Pete Bernert\r
+    web                  : www.pbernert.com   \r
+\r
+    PCSX rearmed adjustments (c) notaz, 2012\r
+ ***************************************************************************/\r
+\r
+/***************************************************************************\r
+ *                                                                         *\r
+ *   This program is free software; you can redistribute it and/or modify  *\r
+ *   it under the terms of the GNU General Public License as published by  *\r
+ *   the Free Software Foundation; either version 2 of the License, or     *\r
+ *   (at your option) any later version. See also the license.txt file for *\r
+ *   additional informations.                                              *\r
+ *                                                                         *\r
+ ***************************************************************************/\r
+\r
+#include "gpuStdafx.h"\r
+\r
+#define _IN_MENU\r
+\r
+#include "gpuExternals.h"\r
+\r
+////////////////////////////////////////////////////////////////////////\r
+// field with menu chars... like good old C64 time :)\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+static const GLubyte texrasters[40][12]= {\r
+\r
+// 0,0 FPS\r
+{0x00,0x60,0x60,0x60,0x60,0x60,0x7e,0x60,0x60,0x60,0x60,0x7f},\r
+{0x00,0x18,0x18,0x18,0x18,0x18,0x1f,0x18,0x18,0x18,0x18,0x1f},\r
+{0x00,0x03,0x06,0x00,0x00,0x00,0xc3,0x66,0x66,0x66,0x66,0xc3},\r
+{0x00,0xf0,0x18,0x18,0x18,0x18,0xf0,0x00,0x00,0x00,0x18,0xf0},\r
+// 4,0 0\r
+{0x00,0x3c,0x66,0xc3,0xe3,0xf3,0xdb,0xcf,0xc7,0xc3,0x66,0x3c},\r
+// 5,0 1\r
+{0x00,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x78,0x38,0x18},\r
+// 6,0 2\r
+{0x00,0xff,0xc0,0xc0,0x60,0x30,0x18,0x0c,0x06,0x03,0xe7,0x7e},\r
+// 7,0 3\r
+\r
+{0x00,0x7e,0xe7,0x03,0x03,0x07,0x7e,0x07,0x03,0x03,0xe7,0x7e},\r
+// 0,1 4\r
+{0x00,0x0c,0x0c,0x0c,0x0c,0x0c,0xff,0xcc,0x6c,0x3c,0x1c,0x0c},\r
+// 1,1 5\r
+{0x00,0x7e,0xe7,0x03,0x03,0x07,0xfe,0xc0,0xc0,0xc0,0xc0,0xff},\r
+// 2,1 6\r
+{0x00,0x7e,0xe7,0xc3,0xc3,0xc7,0xfe,0xc0,0xc0,0xc0,0xe7,0x7e},\r
+// 3,1 7\r
+{0x00,0x30,0x30,0x30,0x30,0x18,0x0c,0x06,0x03,0x03,0x03,0xff},\r
+// 4,1 8\r
+{0x00,0x7e,0xe7,0xc3,0xc3,0xe7,0x7e,0xe7,0xc3,0xc3,0xe7,0x7e},\r
+// 5,1 9\r
+{0x00,0x7e,0xe7,0x03,0x03,0x03,0x7f,0xe7,0xc3,0xc3,0xe7,0x7e},\r
+// 6,1 smiley\r
+{0x00,0x3c,0x42,0x99,0xa5,0x81,0xa5,0x81,0x42,0x3c,0x00,0x00},\r
+// 7,1 sun\r
+{0x00,0x08,0x49,0x2a,0x1c,0x7f,0x1c,0x2a,0x49,0x08,0x00,0x00},\r
+\r
+// 0,2 fl + empty  box\r
+{0xff,0x81,0x81,0x81,0xff,0x00,0x87,0x84,0x84,0xf4,0x84,0xf8},\r
+// 1,2 fs + grey box\r
+{0xff,0xab,0xd5,0xab,0xff,0x00,0x87,0x81,0x87,0xf4,0x87,0xf8},\r
+// 2,2 od + filled box\r
+{0xff,0xff,0xff,0xff,0xff,0x00,0x66,0x95,0x95,0x95,0x96,0x60},\r
+// 3,2 fi + half grey box\r
+{0xff,0xa1,0xd1,0xa1,0xff,0x00,0x82,0x82,0x82,0xe2,0x82,0xf8},\r
+// 4,2 di + half filled box\r
+{0xff,0xf1,0xf1,0xf1,0xff,0x00,0xe2,0x92,0x92,0x92,0x92,0xe0},\r
+// 5,2 am  + grey box\r
+{0xff,0xab,0xd5,0xab,0xff,0x00,0x95,0x95,0x95,0xf7,0x95,0x60},\r
+// 6,2 ab  + filled box\r
+{0xff,0xff,0xff,0xff,0xff,0x00,0x97,0x95,0x96,0xf5,0x96,0x60},\r
+// 7,2 fa\r
+{0x00,0x00,0x00,0x00,0x00,0x00,0x85,0x85,0x87,0xf5,0x82,0xf8},\r
+\r
+// 0,3 fb\r
+{0xff,0x8b,0x85,0x8b,0xff,0x00,0x82,0x82,0x82,0xe2,0x87,0xf8},\r
+// 1,3 gf\r
+{0xff,0x8f,0x8f,0x8f,0xff,0x00,0x74,0x94,0x96,0xb4,0x87,0x70},\r
+// 2,3 D\r
+{0xff,0x00,0xfc,0xc6,0xc3,0xc3,0xc3,0xc3,0xc6,0xfc,0x00,0xff}, \r
+// 3,3 G\r
+{0xff,0x00,0x3e,0x63,0xc3,0xc7,0xc0,0xc0,0x63,0x3e,0x00,0xff},\r
+// 4,3\r
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},\r
+// 5,3\r
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},\r
+// 6,3 tex pal smiley\r
+{0x00,0x3c,0x7e,0xe7,0xdb,0xff,0xdb,0xff,0x7e,0x3c,0x00,0x00},\r
+// 7,3\r
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},\r
+\r
+// 0,4 subtract blending (moon)\r
+{0x00,0x06,0x1c,0x38,0x78,0x78,0x78,0x38,0x1c,0x06,0x00,0x00},\r
+// 1,4 blurring\r
+{0x00,0x7e,0x93,0xa5,0x93,0xc9,0x93,0xa5,0x93,0x7e,0x00,0x00},\r
+// 2,4 (M)\r
+{0xff,0x00,0xc3,0xc3,0xc3,0xdb,0xff,0xe7,0xc3,0x81,0x00,0xff},\r
+// 3,4 (A)\r
+{0xff,0x00,0xc3,0xc3,0xff,0xc3,0xc3,0x66,0x3c,0x18,0x00,0xff},\r
+// 4,4 blank\r
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},\r
+// 5,4\r
+{0x00,0xfe,0xc5,0x62,0x35,0x18,0x0c,0xc6,0xc6,0x7c,0x00,0x00},\r
+// 6,4  <-\r
+{0x00,0x00,0x00,0x00,0x00,0x10,0x30,0x7f,0xff,0x7f,0x30,0x10},\r
+// 7,4 .\r
+{0x00,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}\r
+};\r
+\r
+////////////////////////////////////////////////////////////////////////\r
+// create lists/stuff for fonts \r
+// (as a matter of fact: no more display list used, just a texture)\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+GLuint gTexFontName=0;\r
+\r
+void MakeDisplayLists(void)                            // MAKE FONT \r
+{\r
+ GLubyte TexBytes[64][64][3];                          // we use a 64x64 texture\r
+ int x,y,i,j,n=0; GLubyte col,IB;\r
+\r
+ glPixelStorei(GL_UNPACK_ALIGNMENT,1);\r
\r
+ memset(TexBytes,0,64*64*3);\r
+\r
+ for(y=0;y<5;y++)                                      // create texture out of raster infos\r
+  {\r
+   for(x=0;x<8;x++,n++)\r
+    {\r
+     for(i=0;i<12;i++)\r
+      {\r
+       IB=texrasters[n][i];\r
+       for(j=0;j<8;j++)\r
+        {\r
+         if(IB&(1<<(7-j))) col=255; else col=0;\r
+         TexBytes[y*12+i][x*8+j][0]=col;\r
+         TexBytes[y*12+i][x*8+j][1]=col;\r
+         TexBytes[y*12+i][x*8+j][2]=col;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+ glGenTextures(1, &gTexFontName);                      // set tex params for font texture\r
+ glBindTexture(GL_TEXTURE_2D, gTexFontName);\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\r
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB,\r
+              GL_UNSIGNED_BYTE,TexBytes);\r
+ glError();\r
+}\r
+\r
+////////////////////////////////////////////////////////////////////////\r
+// kill existing font stuff\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+void KillDisplayLists(void)\r
+{\r
+#ifdef _WINDOWS\r
+ if(hGFont) DeleteObject(hGFont);                      // windows: kill info font\r
+ hGFont=NULL;\r
+#endif\r
+\r
+ if(gTexFontName)                                      // del font/info textures\r
+  {glDeleteTextures(1,&gTexFontName);gTexFontName=0;}\r
+}\r
+\r
+////////////////////////////////////////////////////////////////////////\r
+// display text/infos in gpu menu\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+#define TEXCHAR_VERTEX(t0,t1,v0,v1,v2) \\r
+ *pta++ = t0; *pta++ = t1; *pva++ = v0; *pva++ = v1; *pva++ = v2\r
+\r
+#ifdef OWNSCALE\r
+#define DRAWTEXCHAR \\r
+ pta = text_tex_array, pva = text_vertex_array; \\r
+ TEXCHAR_VERTEX(fX1/256.0f,fY2/256.0f,fXS1,fYS2,1.0f); \\r
+ TEXCHAR_VERTEX(fX1/256.0f,fY1/256.0f,fXS1,fYS1,1.0f); \\r
+ TEXCHAR_VERTEX(fX2/256.0f,fY1/256.0f,fXS2,fYS1,1.0f); \\r
+ TEXCHAR_VERTEX(fX2/256.0f,fY2/256.0f,fXS2,fYS2,1.0f); \\r
+ glDrawArrays(GL_TRIANGLE_FAN,0,4)\r
+\r
+#else\r
+#define DRAWTEXCHAR glTexCoord2f(fX1,fY2);glVertex3f(fXS1,fYS2,1.0f);glTexCoord2f(fX1,fY1);glVertex3f(fXS1,fYS1,1.0f);glTexCoord2f(fX2,fY1);glVertex3f(fXS2,fYS1,1.0f);glTexCoord2f(fX2,fY2);glVertex3f(fXS2,fYS2,1.0f);\r
+#endif\r
+\r
+static GLfloat text_tex_array[2*4];\r
+static GLfloat text_vertex_array[3*4];\r
+\r
+void DisplayText(const char *ltext, int right_aligned)\r
+{\r
+ int iX,iY,i;\r
+ GLfloat fX1,fY1,fX2,fY2,fYS1,fYS2,fXS1,fXS2,fXS,fXSC,fYSC,fYD;\r
+ GLfloat *pta, *pva;\r
+\r
+ glDisable(GL_SCISSOR_TEST);                           // disable unwanted ogl states\r
+ glDisable(GL_ALPHA_TEST);\r
+ if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}\r
+ if(bBlendEnable)     {glDisable(GL_BLEND);bBlendEnable=FALSE;}\r
+ if(!bTexEnabled)     {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}\r
+\r
+ gTexName=gTexFontName;\r
+ glBindTexture(GL_TEXTURE_2D,gTexFontName);            // now set font texture\r
+\r
+ fYD=fYSC=(GLfloat)PSXDisplay.DisplayMode.y/(GLfloat)iResY; // some pre-calculations\r
+ fYS1=(GLfloat)PSXDisplay.DisplayMode.y-1.0f*fYSC;\r
+ fYS2=(GLfloat)PSXDisplay.DisplayMode.y-13.0f*fYSC;\r
+ fYSC*=13.0f;\r
+ fXS= (GLfloat)PSXDisplay.DisplayMode.x/(GLfloat)iResX;\r
+ fXSC= 8.0f*fXS;fXS*=10.0f;\r
+ fXS1=0.0f;\r
+ fXS2=50.0f*fXS;                                       // 3 is one option\r
+\r
+ vertex[0].c.lcol=0xffffffff;                          // set menu text color\r
+ SETCOL(vertex[0]); \r
+\r
+ //glBegin(GL_QUADS);\r
+ glEnableClientState(GL_VERTEX_ARRAY);\r
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);\r
+ glDisableClientState(GL_COLOR_ARRAY);\r
+ glVertexPointer(3,GL_FLOAT,0,text_vertex_array);\r
+ glTexCoordPointer(2,GL_FLOAT,0,text_tex_array);\r
+ glError();\r
+\r
+ if(right_aligned)\r
+  fYSC=fXS1=(GLfloat)PSXDisplay.DisplayMode.x-strlen(ltext)*8.0f;\r
+ else\r
+  fYSC=fXS1=1.0f*fXS;                                  // start pos of numbers\r
+\r
+ i=0;do                                                // paint fps numbers\r
+  {\r
+   iX=4;iY=4;\r
+   if(ltext[i]>='0' && ltext[i]<='3')\r
+    {iX=4+ltext[i]-'0';iY=0;}\r
+   else\r
+   if(ltext[i]>='4' && ltext[i]<='9')\r
+    {iX=ltext[i]-'4';iY=1;}\r
+   else\r
+   if(ltext[i]=='.')\r
+    {iX=7;iY=4;}\r
+   else\r
+   if(ltext[i]==0) break;\r
+\r
+   fX1=(GLfloat)iX*32.0f; fX2=fX1+32.0f;\r
+   fY1=(GLfloat)iY*48.0f; fY2=fY1+48.0f;\r
+   fXS1+=fXS;\r
+   fXS2=fXS1+fXSC;\r
+\r
+   DRAWTEXCHAR;\r
+\r
+   i++;\r
+  }\r
+ while(i);\r
+\r
+ //glEnd();\r
+ glDisableClientState(GL_VERTEX_ARRAY);\r
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);\r
+ CSTEXTURE = CSVERTEX = CSCOLOR = 0;\r
+\r
+ glEnable(GL_ALPHA_TEST);                              // repair needed states\r
+ glEnable(GL_SCISSOR_TEST);                       \r
+ glError();\r
+}\r
\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+void HideText(void)\r
+{\r
+ GLfloat fYS1,fYS2,fXS1,fXS2,fXS,fXSC,fYSC;\r
+\r
+ glDisable(GL_SCISSOR_TEST);                           // turn off unneeded ogl states\r
+ glDisable(GL_ALPHA_TEST);\r
+ if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}\r
+ if(bBlendEnable)     {glDisable(GL_BLEND);bBlendEnable=FALSE;}\r
+ if(bTexEnabled)      {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;}\r
+\r
+ fYSC=(GLfloat)PSXDisplay.DisplayMode.y/(GLfloat)iResY;\r
+ fYS1=12.0f*fYSC;fYSC*=13.0f;\r
+ fYS2=0.0f;\r
+ fXS= (GLfloat)PSXDisplay.DisplayMode.x/(GLfloat)iResX;\r
+ fXSC= 8.0f*fXS;fXS*=10.0f;\r
+ fXS1=0.0f;\r
+ fXS2=50.0f*fXS;                                       \r
+\r
+ vertex[0].c.lcol=0xff000000;                          // black color\r
+ SETCOL(vertex[0]); \r
+\r
+ //glBegin(GL_QUADS);                                  // make one quad\r
+\r
+ {\r
+  GLfloat vertex_array[3*4] = {\r
+   fXS1,fYS2,0.99996f,\r
+   fXS1,fYSC,0.99996f,\r
+   fXS2,fYSC,0.99996f,\r
+   fXS2,fYS2,0.99996f,\r
+  };\r
+  glDisableClientState(GL_TEXTURE_COORD_ARRAY);\r
+  glEnableClientState(GL_VERTEX_ARRAY);\r
+  glVertexPointer(3,GL_FLOAT,0,vertex_array);\r
+\r
+  glDrawArrays(GL_TRIANGLE_STRIP,0,4);\r
+  glDisableClientState(GL_VERTEX_ARRAY);\r
+ }\r
+\r
+ //glEnd();\r
+ glEnable(GL_ALPHA_TEST);                              // enable needed ogl states\r
+ glEnable(GL_SCISSOR_TEST);                       \r
+}\r
+\r