nv50: checkpoint: shader code now exceeds caps of "old" code
[mesa.git] / progs / egl / demo2.c
index e8ace3da8e2460a34ed86f3dcc71d66bc8afc0ac..d7283e13bd3f6d47572f0a38fb7be6c03e309d82 100644 (file)
@@ -2,35 +2,54 @@
  * Exercise EGL API functions
  */
 
+#define EGL_EGLEXT_PROTOTYPES
+
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <GLES/egl.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <GLES/gl.h>
 
-#define FRONTBUFFER
+/*#define FRONTBUFFER*/
 
-static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
+                          GLfloat r, GLfloat g, GLfloat b)
 {
-   glBegin( GL_QUADS );
-   glVertex2f( x1, y1 );
-   glVertex2f( x2, y1 );
-   glVertex2f( x2, y2 );
-   glVertex2f( x1, y2 );
-   glEnd();
+   GLfloat v[4][2], c[4][4];
+   int i;
+
+   v[0][0] = x1;   v[0][1] = y1;
+   v[1][0] = x2;   v[1][1] = y1;
+   v[2][0] = x2;   v[2][1] = y2;
+   v[3][0] = x1;   v[3][1] = y2;
+
+   for (i = 0; i < 4; i++) {
+      c[i][0] = r;
+      c[i][1] = g;
+      c[i][2] = b;
+      c[i][3] = 1.0;
+   }
+
+   glVertexPointer(2, GL_FLOAT, 0, v);
+   glColorPointer(4, GL_FLOAT, 0, v);
+   glEnableClientState(GL_VERTEX_ARRAY);
+   glEnableClientState(GL_COLOR_ARRAY);
+
+   glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+   glDisableClientState(GL_VERTEX_ARRAY);
+   glDisableClientState(GL_COLOR_ARRAY);
 }
 
 
-static void redraw(EGLDisplay dpy, int rot)
+static void redraw(EGLDisplay dpy, EGLSurface surf, int rot)
 {
-   printf("Redraw event\n");
+   GLfloat r, g, b;
 
-#ifdef FRONTBUFFER
-    glDrawBuffer( GL_FRONT ); 
-#else
-    glDrawBuffer( GL_BACK );
-#endif
+   printf("Redraw event\n");
 
    glClearColor( rand()/(float)RAND_MAX, 
                 rand()/(float)RAND_MAX, 
@@ -39,19 +58,20 @@ static void redraw(EGLDisplay dpy, int rot)
 
    glClear( GL_COLOR_BUFFER_BIT ); 
 
-   glColor3f( rand()/(float)RAND_MAX, 
-             rand()/(float)RAND_MAX, 
-             rand()/(float)RAND_MAX );
+   r = rand()/(float)RAND_MAX;
+   g = rand()/(float)RAND_MAX;
+   b = rand()/(float)RAND_MAX;
+
    glPushMatrix();
    glRotatef(rot, 0, 0, 1);
    glScalef(.5, .5, .5);
-   _subset_Rectf( -1, -1, 1, 1 );
+   _subset_Rectf( -1, -1, 1, 1, r, g, b );
    glPopMatrix();
 
 #ifdef FRONTBUFFER
    glFlush();
 #else
-   EGLSwapBuffers( dpy, w ); 
+   eglSwapBuffers( dpy, surf ); 
 #endif
    glFinish();
 }
@@ -102,7 +122,7 @@ main(int argc, char *argv[])
    /*
    EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    */
-   EGLDisplay d = eglGetDisplay("!fb_dri");
+   EGLDisplay d = eglGetDisplay((EGLNativeDisplayType) "!EGL_i915");
    assert(d);
 
    if (!eglInitialize(d, &maj, &min)) {
@@ -152,7 +172,7 @@ main(int argc, char *argv[])
       return 0;
    }
    
-   eglShowSurfaceMESA(d, screen, screen_surf, mode);
+   eglShowScreenSurfaceMESA(d, screen, screen_surf, mode);
 
    b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
    if (!b) {
@@ -161,13 +181,21 @@ main(int argc, char *argv[])
    }
 
    glViewport(0, 0, 1024, 768);
+
+   glClearColor( 0, 
+                1.0, 
+                0,
+                1);
+
+   glClear( GL_COLOR_BUFFER_BIT ); 
    
+      
    TestScreens(d);
 
    glShadeModel( GL_FLAT );
    
    for (i = 0; i < 6; i++) {
-      redraw(d, i*10 );
+      redraw(d, screen_surf, i*10 );
 
       printf("sleep(1)\n");   
       sleep(1);