1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved.
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #ifndef CR_GLSTATE_H
|
---|
8 | #define CR_GLSTATE_H
|
---|
9 |
|
---|
10 | /* Forward declaration since some of the state/cr_*.h files need the CRContext type */
|
---|
11 | struct CRContext;
|
---|
12 | typedef struct CRContext CRContext;
|
---|
13 |
|
---|
14 | #include "cr_version.h"
|
---|
15 |
|
---|
16 | #include "state/cr_buffer.h"
|
---|
17 | #include "state/cr_bufferobject.h"
|
---|
18 | #include "state/cr_client.h"
|
---|
19 | #include "state/cr_current.h"
|
---|
20 | #include "state/cr_evaluators.h"
|
---|
21 | #include "state/cr_feedback.h"
|
---|
22 | #include "state/cr_fog.h"
|
---|
23 | #include "state/cr_hint.h"
|
---|
24 | #include "state/cr_lighting.h"
|
---|
25 | #include "state/cr_limits.h"
|
---|
26 | #include "state/cr_line.h"
|
---|
27 | #include "state/cr_lists.h"
|
---|
28 | #include "state/cr_multisample.h"
|
---|
29 | #include "state/cr_occlude.h"
|
---|
30 | #include "state/cr_pixel.h"
|
---|
31 | #include "state/cr_point.h"
|
---|
32 | #include "state/cr_polygon.h"
|
---|
33 | #include "state/cr_program.h"
|
---|
34 | #include "state/cr_regcombiner.h"
|
---|
35 | #include "state/cr_stencil.h"
|
---|
36 | #include "state/cr_texture.h"
|
---|
37 | #include "state/cr_transform.h"
|
---|
38 | #include "state/cr_viewport.h"
|
---|
39 | #include "state/cr_attrib.h"
|
---|
40 | #include "state/cr_framebuffer.h"
|
---|
41 | #include "state/cr_glsl.h"
|
---|
42 |
|
---|
43 | #include "state/cr_statefuncs.h"
|
---|
44 | #include "state/cr_stateerror.h"
|
---|
45 |
|
---|
46 | #include "spu_dispatch_table.h"
|
---|
47 |
|
---|
48 | #ifdef CHROMIUM_THREADSAFE
|
---|
49 | # include <cr_threads.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #include <iprt/cdefs.h>
|
---|
53 |
|
---|
54 | #ifndef IN_GUEST
|
---|
55 | # include <VBox/vmm/ssm.h>
|
---|
56 | # include <iprt/asm.h>
|
---|
57 |
|
---|
58 | # define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) (crMemset((_pObj)->ctxUsage, 0, sizeof ((_pObj)->ctxUsage)))
|
---|
59 | # define CR_STATE_SHAREDOBJ_USAGE_SET(_pObj, _pCtx) (ASMBitSet((_pObj)->ctxUsage, (_pCtx)->id))
|
---|
60 | # define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) (ASMBitClear((_pObj)->ctxUsage, (_pCtx)->id))
|
---|
61 | # define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3) >= 0)
|
---|
62 | #else
|
---|
63 | # define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) do {} while (0)
|
---|
64 | # define CR_STATE_SHAREDOBJ_USAGE_SET(_pObj, _pCtx) do {} while (0)
|
---|
65 | # define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) do {} while (0)
|
---|
66 | # define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (GL_FALSE)
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #define CR_MAX_EXTENTS 256
|
---|
70 |
|
---|
71 | #ifdef __cplusplus
|
---|
72 | extern "C" {
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Bit vectors describing GL state
|
---|
77 | */
|
---|
78 | typedef struct {
|
---|
79 | CRAttribBits attrib;
|
---|
80 | CRBufferBits buffer;
|
---|
81 | #ifdef CR_ARB_vertex_buffer_object
|
---|
82 | CRBufferObjectBits bufferobject;
|
---|
83 | #endif
|
---|
84 | CRClientBits client;
|
---|
85 | CRCurrentBits current;
|
---|
86 | CREvaluatorBits eval;
|
---|
87 | CRFeedbackBits feedback;
|
---|
88 | CRFogBits fog;
|
---|
89 | CRHintBits hint;
|
---|
90 | CRLightingBits lighting;
|
---|
91 | CRLineBits line;
|
---|
92 | CRListsBits lists;
|
---|
93 | CRMultisampleBits multisample;
|
---|
94 | #if CR_ARB_occlusion_query
|
---|
95 | CROcclusionBits occlusion;
|
---|
96 | #endif
|
---|
97 | CRPixelBits pixel;
|
---|
98 | CRPointBits point;
|
---|
99 | CRPolygonBits polygon;
|
---|
100 | CRProgramBits program;
|
---|
101 | CRRegCombinerBits regcombiner;
|
---|
102 | CRSelectionBits selection;
|
---|
103 | CRStencilBits stencil;
|
---|
104 | CRTextureBits texture;
|
---|
105 | CRTransformBits transform;
|
---|
106 | CRViewportBits viewport;
|
---|
107 | } CRStateBits;
|
---|
108 |
|
---|
109 | typedef void (*CRStateFlushFunc)( void *arg );
|
---|
110 |
|
---|
111 |
|
---|
112 | typedef struct _CRSharedState {
|
---|
113 | CRHashTable *textureTable; /* all texture objects */
|
---|
114 | CRHashTable *dlistTable; /* all display lists */
|
---|
115 | CRHashTable *buffersTable; /* vbo/pbo */
|
---|
116 | CRHashTable *fbTable; /* frame buffers */
|
---|
117 | CRHashTable *rbTable; /* render buffers */
|
---|
118 |
|
---|
119 | GLint refCount;
|
---|
120 | GLint id; /*unique shared state id, it's not always matching some existing context id!*/
|
---|
121 | GLint saveCount;
|
---|
122 |
|
---|
123 | /* Indicates that we have to resend data to GPU on first glMakeCurrent call with owning context */
|
---|
124 | GLboolean bTexResyncNeeded;
|
---|
125 | GLboolean bVBOResyncNeeded;
|
---|
126 | GLboolean bFBOResyncNeeded;
|
---|
127 | } CRSharedState;
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Chromium version of the state variables in OpenGL
|
---|
131 | */
|
---|
132 | struct CRContext {
|
---|
133 | int id;
|
---|
134 |
|
---|
135 | #ifdef CHROMIUM_THREADSAFE
|
---|
136 | /* we keep reference counting of context's makeCurrent for different threads
|
---|
137 | * this is primarily needed to avoid having an invalid memory reference in the TLS
|
---|
138 | * when the context is assigned to more than one threads and then destroyed from
|
---|
139 | * one of those, i.e.
|
---|
140 | * 1. Thread1 -> MakeCurrent(ctx1);
|
---|
141 | * 2. Thread2 -> MakeCurrent(ctx1);
|
---|
142 | * 3. Thread1 -> Destroy(ctx1);
|
---|
143 | * => Thread2 still refers to destroyed ctx1
|
---|
144 | * */
|
---|
145 | VBOXTLSREFDATA
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | CRbitvalue bitid[CR_MAX_BITARRAY];
|
---|
149 | CRbitvalue neg_bitid[CR_MAX_BITARRAY];
|
---|
150 |
|
---|
151 | CRSharedState *shared;
|
---|
152 |
|
---|
153 | GLenum renderMode;
|
---|
154 |
|
---|
155 | GLenum error;
|
---|
156 |
|
---|
157 | CRStateFlushFunc flush_func;
|
---|
158 | void *flush_arg;
|
---|
159 |
|
---|
160 | CRAttribState attrib;
|
---|
161 | CRBufferState buffer;
|
---|
162 | #ifdef CR_ARB_vertex_buffer_object
|
---|
163 | CRBufferObjectState bufferobject;
|
---|
164 | #endif
|
---|
165 | CRClientState client;
|
---|
166 | CRCurrentState current;
|
---|
167 | CREvaluatorState eval;
|
---|
168 | CRExtensionState extensions;
|
---|
169 | CRFeedbackState feedback;
|
---|
170 | CRFogState fog;
|
---|
171 | CRHintState hint;
|
---|
172 | CRLightingState lighting;
|
---|
173 | CRLimitsState limits;
|
---|
174 | CRLineState line;
|
---|
175 | CRListsState lists;
|
---|
176 | CRMultisampleState multisample;
|
---|
177 | #if CR_ARB_occlusion_query
|
---|
178 | CROcclusionState occlusion;
|
---|
179 | #endif
|
---|
180 | CRPixelState pixel;
|
---|
181 | CRPointState point;
|
---|
182 | CRPolygonState polygon;
|
---|
183 | CRProgramState program;
|
---|
184 | CRRegCombinerState regcombiner;
|
---|
185 | CRSelectionState selection;
|
---|
186 | CRStencilState stencil;
|
---|
187 | CRTextureState texture;
|
---|
188 | CRTransformState transform;
|
---|
189 | CRViewportState viewport;
|
---|
190 |
|
---|
191 | #ifdef CR_EXT_framebuffer_object
|
---|
192 | CRFramebufferObjectState framebufferobject;
|
---|
193 | #endif
|
---|
194 |
|
---|
195 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
196 | CRGLSLState glsl;
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | /** For buffering vertices for selection/feedback */
|
---|
200 | /*@{*/
|
---|
201 | GLuint vCount;
|
---|
202 | CRVertex vBuffer[4];
|
---|
203 | GLboolean lineReset;
|
---|
204 | GLboolean lineLoop;
|
---|
205 | /*@}*/
|
---|
206 | };
|
---|
207 |
|
---|
208 |
|
---|
209 | DECLEXPORT(void) crStateInit(void);
|
---|
210 | DECLEXPORT(void) crStateDestroy(void);
|
---|
211 | DECLEXPORT(void) crStateVBoxDetachThread();
|
---|
212 | DECLEXPORT(void) crStateVBoxAttachThread();
|
---|
213 | DECLEXPORT(CRContext *) crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share);
|
---|
214 | DECLEXPORT(CRContext *) crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
|
---|
215 | DECLEXPORT(void) crStateMakeCurrent(CRContext *ctx);
|
---|
216 | DECLEXPORT(void) crStateSetCurrent(CRContext *ctx);
|
---|
217 | DECLEXPORT(CRContext *) crStateGetCurrent(void);
|
---|
218 | DECLEXPORT(void) crStateDestroyContext(CRContext *ctx);
|
---|
219 | DECLEXPORT(GLboolean) crStateEnableDiffOnMakeCurrent(GLboolean fEnable);
|
---|
220 |
|
---|
221 | CRContext * crStateSwichPrepare(CRContext *toCtx, GLboolean fMultipleContexts, GLuint idFBO);
|
---|
222 | void crStateSwichPostprocess(CRContext *fromCtx, GLboolean fMultipleContexts, GLuint idFBO);
|
---|
223 |
|
---|
224 | DECLEXPORT(void) crStateFlushFunc( CRStateFlushFunc ff );
|
---|
225 | DECLEXPORT(void) crStateFlushArg( void *arg );
|
---|
226 | DECLEXPORT(void) crStateDiffAPI( SPUDispatchTable *api );
|
---|
227 | DECLEXPORT(void) crStateUpdateColorBits( void );
|
---|
228 |
|
---|
229 | DECLEXPORT(void) crStateSetCurrentPointers( CRContext *ctx, CRCurrentStatePointers *current );
|
---|
230 | DECLEXPORT(void) crStateResetCurrentPointers( CRCurrentStatePointers *current );
|
---|
231 |
|
---|
232 | DECLEXPORT(void) crStateSetExtensionString( CRContext *ctx, const GLubyte *extensions );
|
---|
233 |
|
---|
234 | DECLEXPORT(void) crStateDiffContext( CRContext *from, CRContext *to );
|
---|
235 | DECLEXPORT(void) crStateSwitchContext( CRContext *from, CRContext *to );
|
---|
236 | DECLEXPORT(void) crStateApplyFBImage(CRContext *to);
|
---|
237 |
|
---|
238 | #ifndef IN_GUEST
|
---|
239 | DECLEXPORT(int32_t) crStateSaveContext(CRContext *pContext, PSSMHANDLE pSSM);
|
---|
240 | typedef DECLCALLBACK(CRContext*) FNCRSTATE_CONTEXT_GET(void*);
|
---|
241 | typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
|
---|
242 | DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version);
|
---|
243 | DECLEXPORT(void) crStateFreeShared(CRContext *pContext, CRSharedState *s);
|
---|
244 | DECLEXPORT(void) crStateFreeShared(CRContext *pContext, CRSharedState *s);
|
---|
245 | #endif
|
---|
246 |
|
---|
247 | DECLEXPORT(void) crStateSetTextureUsed(GLuint texture, GLboolean used);
|
---|
248 | DECLEXPORT(void) crStateDeleteTextureCallback(void *texObj);
|
---|
249 |
|
---|
250 | /* XXX move these! */
|
---|
251 |
|
---|
252 | DECLEXPORT(void) STATE_APIENTRY
|
---|
253 | crStateChromiumParameteriCR( GLenum target, GLint value );
|
---|
254 |
|
---|
255 | DECLEXPORT(void) STATE_APIENTRY
|
---|
256 | crStateChromiumParameterfCR( GLenum target, GLfloat value );
|
---|
257 |
|
---|
258 | DECLEXPORT(void) STATE_APIENTRY
|
---|
259 | crStateChromiumParametervCR( GLenum target, GLenum type, GLsizei count, const GLvoid *values );
|
---|
260 |
|
---|
261 | DECLEXPORT(void) STATE_APIENTRY
|
---|
262 | crStateGetChromiumParametervCR( GLenum target, GLuint index, GLenum type,
|
---|
263 | GLsizei count, GLvoid *values );
|
---|
264 |
|
---|
265 | DECLEXPORT(void) STATE_APIENTRY
|
---|
266 | crStateReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
|
---|
267 | GLenum format, GLenum type, GLvoid *pixels );
|
---|
268 |
|
---|
269 | DECLEXPORT(void) STATE_APIENTRY crStateShareContext(GLboolean value);
|
---|
270 | DECLEXPORT(void) STATE_APIENTRY crStateSetSharedContext(CRContext *pCtx);
|
---|
271 | DECLEXPORT(GLboolean) STATE_APIENTRY crStateContextIsShared(CRContext *pCtx);
|
---|
272 |
|
---|
273 | DECLEXPORT(void) STATE_APIENTRY crStateQueryHWState();
|
---|
274 | #ifdef __cplusplus
|
---|
275 | }
|
---|
276 | #endif
|
---|
277 |
|
---|
278 | #endif /* CR_GLSTATE_H */
|
---|