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