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