Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-z64/src/rgl.h
2 views
1
/*
2
* z64
3
*
4
* Copyright (C) 2007 ziggy
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
**/
21
22
#ifndef _RGL_H_
23
#define _RGL_H_
24
25
#include "queue.h"
26
#include "rgl_assert.h"
27
#include "rdp.h"
28
29
#include <glew.h>
30
#if defined(__MACOSX__)
31
#include <OpenGL/gl.h>
32
#elif defined(__MACOS__)
33
#include <gl.h>
34
#else
35
#include <GL/gl.h>
36
#endif
37
38
#ifdef RDP_DEBUG
39
//#include <IL/il.h>
40
#endif
41
42
#include "glshader.h"
43
44
#include <limits.h> //for PATH_MAX
45
46
#define DWORD unsigned int
47
extern GFX_INFO gfx;
48
#define rdram ((uint32_t*)gfx.RDRAM)
49
#define rsp_imem ((uint32_t*)gfx.IMEM)
50
#define rsp_dmem ((uint32_t*)gfx.DMEM)
51
#define vi_origin (*(uint32_t*)gfx.VI_ORIGIN_REG)
52
#define vi_width (*(uint32_t*)gfx.VI_WIDTH_REG)
53
#define vi_control (*(uint32_t*)gfx.VI_STATUS_REG)
54
55
#define dp_start (*(uint32_t*)gfx.DPC_START_REG)
56
#define dp_end (*(uint32_t*)gfx.DPC_END_REG)
57
#define dp_current (*(uint32_t*)gfx.DPC_CURRENT_REG)
58
#define dp_status (*(uint32_t*)gfx.DPC_STATUS_REG)
59
60
// highly experimental AND slow
61
//#define RGL_EXACT_BLEND
62
63
struct rglSettings_t {
64
int hiresFb;
65
int resX, resY;
66
int fsResX, fsResY;
67
int fbInfo;
68
int forceSwap;
69
int threaded;
70
int async;
71
int noNpotFbos;
72
int lowres;
73
int fullscreen;
74
};
75
76
extern rglSettings_t rglSettings;
77
extern void (*render_callback)(int);
78
79
struct rglDepthBuffer_t {
80
uint32_t address;
81
int width, height;
82
GLuint zbid;
83
};
84
#define MAX_DEPTH_BUFFERS 16
85
extern rglDepthBuffer_t zBuffers[MAX_DEPTH_BUFFERS];
86
extern int nbZBuffers;
87
88
struct rglRenderBuffer_t;
89
struct rglDepthSection_t {
90
rglRenderBuffer_t * buffer;
91
int chunkId;
92
};
93
#define RGL_MAX_DEPTH_SECTIONS 16
94
95
struct rglRenderBuffer_t {
96
CIRCLEQ_ENTRY(rglRenderBuffer_t) link;
97
uint32_t addressStart, addressStop;
98
int format, size, fbWidth, line;
99
int width, height;
100
int flags;
101
GLuint texid, fbid;
102
#ifdef RGL_EXACT_BLEND
103
GLuint texid2, fbid2;
104
#endif
105
int realWidth, realHeight;
106
int fboWidth, fboHeight;
107
int redimensionStamp;
108
rdpRect_t area;
109
rdpRect_t mod;
110
rglDepthBuffer_t * depthBuffer;
111
int chunkId;
112
rglDepthSection_t depthSections[16];
113
int nbDepthSections;
114
};
115
#define RGL_RB_DEPTH 1
116
#define RGL_RB_FULL 2
117
#define RGL_RB_ERASED 4
118
#define RGL_RB_FBMOD 8 // the GL framebuffer was modified
119
#define RGL_RB_RAMMOD 16 // the framebuffer was modified in rdram
120
#define RGL_RB_HASTRIANGLES 32 // we assume it's not a depth buffer in this case
121
122
CIRCLEQ_HEAD(rglRenderBufferHead_t, rglRenderBuffer_t);
123
124
#define MAX_RENDER_BUFFERS 64
125
extern rglRenderBuffer_t rBuffers[MAX_RENDER_BUFFERS];
126
extern int nbRBuffers;
127
extern rglRenderBuffer_t * curRBuffer;
128
extern rglRenderBuffer_t * curZBuffer;
129
extern rglRenderBufferHead_t rBufferHead;
130
131
extern int rglTexCacheCounter;
132
struct rglTexture_t {
133
CIRCLEQ_ENTRY(rglTexture_t) byCrc, byUsage;
134
GLuint id, zid;
135
uint32_t crc;
136
int w, h, fmt;
137
int clipw, cliph;
138
GLuint ws, wt, filter; // current settings
139
};
140
CIRCLEQ_HEAD(rglTextureHead_t, rglTexture_t);
141
#define RGL_TEX_CACHE_SIZE 1024
142
extern rglTexture_t rglTextures[RGL_TEX_CACHE_SIZE];
143
struct rglTexCache_t {
144
int counter;
145
rglTexture_t * tex;
146
};
147
extern rglTexCache_t rglTexCache[0x1000];
148
extern uint8_t rglTmpTex[];
149
extern uint8_t rglTmpTex2[];
150
151
struct rglTile_t : public rdpTile_t {
152
rglTexture_t * tex;
153
rglRenderBuffer_t * hiresBuffer;
154
uint32_t hiresAddress;
155
GLuint ws, wt; // GL clamping modes
156
GLuint filter; // GL filter mode
157
};
158
159
struct rglVertex_t {
160
float x, y, z, w;
161
float s, t;
162
uint8_t r, g, b, a;
163
};
164
165
struct rglStrip_t {
166
int tilenum;
167
int nbVtxs;
168
int flags;
169
rglVertex_t * vtxs;
170
};
171
172
#define RGL_STRIP_TEX1 1
173
#define RGL_STRIP_TEX2 2
174
#define RGL_STRIP_SHADE 4
175
#define RGL_STRIP_ZBUFFER 8
176
177
struct rglRenderChunk_t {
178
rdpState_t rdpState;
179
rglTile_t tiles[8];
180
rglRenderBuffer_t * renderBuffer;
181
uint32_t depthAddress;
182
int flags;
183
int nbStrips;
184
rglStrip_t * strips;
185
#ifdef RDP_DEBUG
186
rglShader_t * shader;
187
int tracePos;
188
#endif
189
};
190
191
// first 8 bits used for tile usage
192
#define RGL_CHUNK_CLEAR (1<<8)
193
194
#define MAX_RENDER_CHUNKS 40000
195
extern rglRenderChunk_t chunks[MAX_RENDER_CHUNKS];
196
extern rglRenderChunk_t * curChunk;
197
extern int nbChunks;
198
199
#define MAX_STRIPS 80000
200
extern rglStrip_t strips[MAX_STRIPS];
201
extern rglVertex_t vtxs[6*MAX_STRIPS];
202
extern int nbStrips, nbVtxs;
203
204
struct rglRenderMode_t {
205
rdpOtherModes_t otherModes;
206
rdpCombineModes_t combineModes;
207
uint32_t flags;
208
};
209
210
#define RGL_RM_DEPTH 1
211
212
// TODO use a hash table
213
#define MAX_RENDER_MODES 1024
214
extern rglRenderMode_t renderModesDb[MAX_RENDER_MODES];
215
extern int nbRenderModes;
216
217
extern rglShader_t * rglCopyShader;
218
extern rglShader_t * rglCopyDepthShader;
219
220
221
#define RGL_COMB_FMT_RGBA 0
222
#define RGL_COMB_FMT_I 1
223
#define RGL_COMB_FMT_DEPTH 2
224
#define RGL_COMB_FMT 3
225
#define RGL_COMB_IN0_DEPTH 4
226
#define RGL_COMB_IN0 4
227
#define RGL_COMB_IN1_DEPTH 8
228
#define RGL_COMB_IN1 8
229
#define RGL_COMB_TILE7 16
230
231
extern volatile int rglStatus, rglNextStatus;
232
#define RGL_STATUS_CLOSED 0
233
#define RGL_STATUS_WINDOWED 1
234
#define RGL_STATUS_FULLSCREEN 2
235
236
237
void rglUpdateStatus();
238
void rglTouchTMEM();
239
void rglResetTextureCache();
240
void rglTile(rdpTile_t & tile, rglTile_t & rtile, int recth);
241
void rglRenderMode(rglRenderChunk_t & chunk);
242
void rglBlender(rglRenderChunk_t & chunk);
243
void rglClearCombiners();
244
void rglSetCombiner(rglRenderChunk_t & chunk, int format);
245
void rglPrepareRendering(int texturing, int tilenum, int recth, int depth);
246
rglRenderBuffer_t * rglSelectRenderBuffer(uint32_t addr, int width, int size, int format);
247
char * rglCombiner2String(rdpState_t & state);
248
249
250
int rglInit();
251
void rglClose();
252
int rglOpenScreen();
253
void rglCloseScreen();
254
int rglReadSettings();
255
void rglUpdate();
256
void rglFullSync();
257
void rglTextureRectangle(rdpTexRect_t * rect, int flip);
258
void rglFillRectangle(rdpRect_t * rect);
259
void rglTriangle(uint32_t w1, uint32_t w2, int shade, int texture, int zbuffer,
260
uint32_t * rdp_cmd);
261
void rglRenderChunks();
262
void rglDisplayFramebuffers();
263
int rglT1Usage(rdpState_t & state);
264
int rglT2Usage(rdpState_t & state);
265
void rglDebugger();
266
void rglCloseDebugger();
267
void rglFramebuffer2Rdram(rglRenderBuffer_t & buffer, uint32_t start, uint32_t stop);
268
void rglRdram2Framebuffer(rglRenderBuffer_t & buffer, uint32_t start, uint32_t stop);
269
void rglRenderChunks(rglRenderBuffer_t * upto);
270
void rglRenderChunks(int upto);
271
float rglZscale(uint16_t z);
272
273
void rglSwapBuffers();
274
275
extern int screen_width, screen_height;
276
277
extern void check();
278
279
#endif
280
281