GLES2N64 (from mupen64plus-ae) plugin. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / gles2n64 / src / OpenGL.h
1 #ifndef OPENGL_H
2 #define OPENGL_H
3
4 #include <GLES2/gl2.h>
5 #include <GLES2/gl2ext.h>
6 #include "gSP.h"
7
8 #ifdef USE_SDL
9 //    #include <EGL/egl.h>  // Android 2.3 only
10 //    #include <GLES2/gl2extimg.h>
11     #include <SDL.h>
12 #endif
13
14 #ifndef min
15 #define min(a,b) ((a) < (b) ? (a) : (b))
16 #endif
17 #ifndef max
18 #define max(a,b) ((a) > (b) ? (a) : (b))
19 #endif
20
21 #define RS_NONE         0
22 #define RS_TRIANGLE     1
23 #define RS_RECT         2
24 #define RS_TEXTUREDRECT 3
25 #define RS_LINE         4
26
27
28 #define SCREEN_UPDATE_AT_VI_UPDATE              1
29 #define SCREEN_UPDATE_AT_VI_CHANGE              2
30 #define SCREEN_UPDATE_AT_CI_CHANGE              3
31 #define SCREEN_UPDATE_AT_1ST_CI_CHANGE          4
32 #define SCREEN_UPDATE_AT_1ST_PRIMITIVE          5
33 #define SCREEN_UPDATE_BEFORE_SCREEN_CLEAR       6
34 #define SCREEN_UPDATE_AT_VI_UPDATE_AND_DRAWN    7
35
36
37 #define BLEND_NOOP              0x0000
38 #define BLEND_NOOP5             0xcc48  // Fog * 0 + Mem * 1
39 #define BLEND_NOOP4             0xcc08  // Fog * 0 + In * 1
40 #define BLEND_FOG_ASHADE        0xc800
41 #define BLEND_FOG_3             0xc000  // Fog * AIn + In * 1-A
42 #define BLEND_FOG_MEM           0xc440  // Fog * AFog + Mem * 1-A
43 #define BLEND_FOG_APRIM         0xc400  // Fog * AFog + In * 1-A
44 #define BLEND_BLENDCOLOR        0x8c88
45 #define BLEND_BI_AFOG           0x8400  // Bl * AFog + In * 1-A
46 #define BLEND_BI_AIN            0x8040  // Bl * AIn + Mem * 1-A
47 #define BLEND_MEM               0x4c40  // Mem*0 + Mem*(1-0)?!
48 #define BLEND_FOG_MEM_3         0x44c0  // Mem * AFog + Fog * 1-A
49 #define BLEND_NOOP3             0x0c48  // In * 0 + Mem * 1
50 #define BLEND_PASS              0x0c08  // In * 0 + In * 1
51 #define BLEND_FOG_MEM_IN_MEM    0x0440  // In * AFog + Mem * 1-A
52 #define BLEND_FOG_MEM_FOG_MEM   0x04c0  // In * AFog + Fog * 1-A
53 #define BLEND_OPA               0x0044  //  In * AIn + Mem * AMem
54 #define BLEND_XLU               0x0040
55 #define BLEND_MEM_ALPHA_IN      0x4044  //  Mem * AIn + Mem * AMem
56
57
58 #define OGL_FRAMETIME_NUM       8
59
60 struct GLVertex
61 {
62     float x, y, z, w;
63     struct
64     {
65         float r, g, b, a;
66     } color, secondaryColor;
67     float s0, t0, s1, t1;
68 };
69
70 struct GLcolor
71 {
72     float r, g, b, a;
73 };
74
75 struct GLInfo
76 {
77 #ifdef USE_SDL
78 // TODO: More EGL stuff, need to do this in Java
79     SDL_Surface *hScreen;  // TODO: Do we really need this?  Only using it in one place AFAICT..
80 /*
81     struct
82     {
83         EGLint                      version_major, version_minor;
84         EGLDisplay              display;
85         EGLContext              context;
86         EGLConfig               config;
87         EGLSurface              surface;
88         EGLNativeDisplayType    device;
89         EGLNativeWindowType     handle;
90     } EGL;
91 */
92 #endif
93
94     bool    screenUpdate;
95
96     struct
97     {
98         GLuint fb,depth_buffer, color_buffer;
99     } framebuffer;
100
101
102     int     frameSkipped;
103     unsigned consecutiveSkips;
104     unsigned frameTime[OGL_FRAMETIME_NUM];
105
106     int     frame_vsync, frame_actual, frame_dl;
107     int     frame_prevdl;
108     int     mustRenderDlist;
109     int     renderingToTexture;
110
111
112     GLint   defaultProgram;
113     GLint   defaultVertShader;
114     GLint   defaultFragShader;
115
116     float   scaleX, scaleY;
117
118 #define INDEXMAP_SIZE 64
119 #define VERTBUFF_SIZE 256
120 #define ELEMBUFF_SIZE 1024
121
122     struct {
123         SPVertex    vertices[VERTBUFF_SIZE];
124         GLubyte     elements[ELEMBUFF_SIZE];
125         int         num;
126
127 //#ifdef __TRIBUFFER_OPT
128
129         u32     indexmap[INDEXMAP_SIZE];
130         u32     indexmapinv[VERTBUFF_SIZE];
131         u32     indexmap_prev;
132         u32     indexmap_nomap;
133 //#endif
134
135     } triangles;
136
137
138     unsigned int    renderState;
139
140     GLVertex rect[4];
141 };
142
143 extern GLInfo OGL;
144
145 bool OGL_Start();
146 void OGL_Stop();
147
148 void OGL_AddTriangle(int v0, int v1, int v2);
149 void OGL_DrawTriangles();
150 void OGL_DrawTriangle(SPVertex *vertices, int v0, int v1, int v2);
151 void OGL_DrawLine(int v0, int v1, float width);
152 void OGL_DrawRect(int ulx, int uly, int lrx, int lry, float *color);
153 void OGL_DrawTexturedRect(float ulx, float uly, float lrx, float lry, float uls, float ult, float lrs, float lrt, bool flip );
154
155 void OGL_UpdateFrameTime();
156 void OGL_UpdateScale();
157 void OGL_UpdateStates();
158 void OGL_UpdateViewport();
159 void OGL_UpdateScissor();
160 void OGL_UpdateCullFace();
161
162 void OGL_ClearDepthBuffer();
163 void OGL_ClearColorBuffer(float *color);
164 void OGL_ResizeWindow(int x, int y, int width, int height);
165 void OGL_SwapBuffers();
166 void OGL_ReadScreen( void *dest, int *width, int *height );
167
168 int  OGL_CheckError();
169 int  OGL_IsExtSupported( const char *extension );
170 #endif
171