VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h@ 78375

Last change on this file since 78375 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 12.5 KB
Line 
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 */
11struct CRContext;
12typedef 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#include "cr_threads.h"
49
50#include <iprt/cdefs.h>
51
52# include <VBox/vmm/ssm.h>
53# include <iprt/asm.h>
54
55# define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) (crMemset((_pObj)->ctxUsage, 0, sizeof ((_pObj)->ctxUsage)))
56# define CR_STATE_SHAREDOBJ_USAGE_SET(_pObj, _pCtx) (ASMBitSet((_pObj)->ctxUsage, (_pCtx)->id))
57# define CR_STATE_SHAREDOBJ_USAGE_IS_SET(_pObj, _pCtx) (ASMBitTest((_pObj)->ctxUsage, (_pCtx)->id))
58# define CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX(_pObj, _i) (ASMBitClear((_pObj)->ctxUsage, (_i)))
59# define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) (CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX((_pObj), (_pCtx)->id))
60# define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3) >= 0)
61# define CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3))
62# define CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX(_pObj, _i) (ASMBitNextSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3, (_i)))
63
64# define CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(_pObj, _i) for ((_i) = CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj); ((int)(_i)) >= 0; (_i) = CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX((_pObj), ((int)(_i))))
65
66#define CR_MAX_EXTENTS 256
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72/**
73 * Bit vectors describing GL state
74 */
75typedef struct {
76 CRAttribBits attrib;
77 CRBufferBits buffer;
78#ifdef CR_ARB_vertex_buffer_object
79 CRBufferObjectBits bufferobject;
80#endif
81 CRClientBits client;
82 CRCurrentBits current;
83 CREvaluatorBits eval;
84 CRFeedbackBits feedback;
85 CRFogBits fog;
86 CRHintBits hint;
87 CRLightingBits lighting;
88 CRLineBits line;
89 CRListsBits lists;
90 CRMultisampleBits multisample;
91#if CR_ARB_occlusion_query
92 CROcclusionBits occlusion;
93#endif
94 CRPixelBits pixel;
95 CRPointBits point;
96 CRPolygonBits polygon;
97 CRProgramBits program;
98 CRRegCombinerBits regcombiner;
99 CRSelectionBits selection;
100 CRStencilBits stencil;
101 CRTextureBits texture;
102 CRTransformBits transform;
103 CRViewportBits viewport;
104} CRStateBits;
105
106typedef void (*CRStateFlushFunc)( void *arg );
107
108
109typedef struct _CRSharedState {
110 CRHashTable *textureTable; /* all texture objects */
111 CRHashTable *dlistTable; /* all display lists */
112 CRHashTable *buffersTable; /* vbo/pbo */
113 CRHashTable *fbTable; /* frame buffers */
114 CRHashTable *rbTable; /* render buffers */
115
116 volatile int32_t refCount;
117 GLint id; /*unique shared state id, it's not always matching some existing context id!*/
118 GLint saveCount;
119
120 /* Indicates that we have to resend data to GPU on first glMakeCurrent call with owning context */
121 GLboolean bTexResyncNeeded;
122 GLboolean bVBOResyncNeeded;
123 GLboolean bFBOResyncNeeded;
124} CRSharedState;
125
126/**
127 * Chromium version of the state variables in OpenGL
128 */
129struct CRContext {
130 int id;
131
132 /* we keep reference counting of context's makeCurrent for different threads
133 * this is primarily needed to avoid having an invalid memory reference in the TLS
134 * when the context is assigned to more than one threads and then destroyed from
135 * one of those, i.e.
136 * 1. Thread1 -> MakeCurrent(ctx1);
137 * 2. Thread2 -> MakeCurrent(ctx1);
138 * 3. Thread1 -> Destroy(ctx1);
139 * => Thread2 still refers to destroyed ctx1
140 * */
141 VBOXTLSREFDATA
142
143 CRbitvalue bitid[CR_MAX_BITARRAY];
144 CRbitvalue neg_bitid[CR_MAX_BITARRAY];
145
146 CRSharedState *shared;
147
148 GLenum renderMode;
149
150 GLenum error;
151
152 CRStateFlushFunc flush_func;
153 void *flush_arg;
154
155 CRAttribState attrib;
156 CRBufferState buffer;
157#ifdef CR_ARB_vertex_buffer_object
158 CRBufferObjectState bufferobject;
159#endif
160 CRClientState client;
161 CRCurrentState current;
162 CREvaluatorState eval;
163 CRExtensionState extensions;
164 CRFeedbackState feedback;
165 CRFogState fog;
166 CRHintState hint;
167 CRLightingState lighting;
168 CRLimitsState limits;
169 CRLineState line;
170 CRListsState lists;
171 CRMultisampleState multisample;
172#if CR_ARB_occlusion_query
173 CROcclusionState occlusion;
174#endif
175 CRPixelState pixel;
176 CRPointState point;
177 CRPolygonState polygon;
178 CRProgramState program;
179 CRRegCombinerState regcombiner;
180 CRSelectionState selection;
181 CRStencilState stencil;
182 CRTextureState texture;
183 CRTransformState transform;
184 CRViewportState viewport;
185
186#ifdef CR_EXT_framebuffer_object
187 CRFramebufferObjectState framebufferobject;
188#endif
189
190#ifdef CR_OPENGL_VERSION_2_0
191 CRGLSLState glsl;
192#endif
193
194 /** The state tracker the context is attached to. */
195 PCRStateTracker pStateTracker;
196
197 /** For buffering vertices for selection/feedback */
198 /*@{*/
199 GLuint vCount;
200 CRVertex vBuffer[4];
201 GLboolean lineReset;
202 GLboolean lineLoop;
203 /*@}*/
204};
205
206
207/**
208 * CR state tracker.
209 */
210typedef struct CRStateTracker
211{
212 bool fContextTLSInit;
213 CRtsd contextTSD;
214 CRStateBits *pCurrentBits;
215 CRContext *apAvailableContexts[CR_MAX_CONTEXTS];
216 uint32_t cContexts;
217 CRSharedState *pSharedState;
218 CRContext *pDefaultContext;
219 GLboolean fVBoxEnableDiffOnMakeCurrent;
220 SPUDispatchTable diff_api;
221} CRStateTracker;
222/** Pointer to a state tracker state. */
223typedef CRStateTracker *PCRStateTracker;
224
225DECLEXPORT(void) crStateInit(PCRStateTracker pState);
226DECLEXPORT(void) crStateDestroy(PCRStateTracker pState);
227DECLEXPORT(void) crStateVBoxDetachThread(PCRStateTracker pState);
228DECLEXPORT(void) crStateVBoxAttachThread(PCRStateTracker pState);
229DECLEXPORT(CRContext *) crStateCreateContext(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share);
230DECLEXPORT(CRContext *) crStateCreateContextEx(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
231DECLEXPORT(void) crStateMakeCurrent(PCRStateTracker pState, CRContext *ctx);
232DECLEXPORT(void) crStateSetCurrent(PCRStateTracker pState, CRContext *ctx);
233DECLEXPORT(void) crStateCleanupCurrent(PCRStateTracker pState);
234DECLEXPORT(CRContext *) crStateGetCurrent(PCRStateTracker pState);
235DECLEXPORT(void) crStateDestroyContext(PCRStateTracker pState, CRContext *ctx);
236DECLEXPORT(GLboolean) crStateEnableDiffOnMakeCurrent(PCRStateTracker pState, GLboolean fEnable);
237
238void crStateSwitchPrepare(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
239void crStateSwitchPostprocess(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
240
241void crStateSyncHWErrorState(CRContext *ctx);
242GLenum crStateCleanHWErrorState(PCRStateTracker pState);
243
244#define CR_STATE_CLEAN_HW_ERR_WARN(a_pState, _s) do {\
245 GLenum _err = crStateCleanHWErrorState((a_pState)); \
246 if (_err != GL_NO_ERROR) { \
247 static int _cErrPrints = 0; \
248 if (_cErrPrints < 5) { \
249 ++_cErrPrints; \
250 WARN(("%s %#x, ignoring.. (%d out of 5)", _s, _err, _cErrPrints)); \
251 } \
252 } \
253 } while (0)
254
255DECLEXPORT(void) crStateFlushFunc(PCRStateTracker pState, CRStateFlushFunc ff);
256DECLEXPORT(void) crStateFlushArg(PCRStateTracker pState, void *arg );
257DECLEXPORT(void) crStateDiffAPI(PCRStateTracker pState, SPUDispatchTable *api);
258DECLEXPORT(void) crStateUpdateColorBits(PCRStateTracker pState);
259
260DECLEXPORT(void) crStateSetCurrentPointers(CRContext *ctx, CRCurrentStatePointers *current);
261DECLEXPORT(void) crStateResetCurrentPointers(CRCurrentStatePointers *current);
262
263DECLEXPORT(void) crStateSetExtensionString(CRContext *ctx, const GLubyte *extensions);
264
265DECLEXPORT(void) crStateDiffContext(CRContext *from, CRContext *to);
266DECLEXPORT(void) crStateSwitchContext(CRContext *from, CRContext *to);
267
268DECLEXPORT(unsigned int) crStateHlpComponentsCount(GLenum pname);
269
270typedef struct CRFBDataElement
271{
272 /* FBO, can be NULL */
273 GLint idFBO;
274 /* to be used for glDraw/ReadBuffer, i.e. GL_FRONT, GL_BACK, GL_COLOR_ATTACHMENTX */
275 GLenum enmBuffer;
276 GLint posX;
277 GLint posY;
278 GLint width;
279 GLint height;
280 GLenum enmFormat;
281 GLenum enmType;
282 GLuint cbData;
283 GLvoid *pvData;
284} CRFBDataElement;
285
286typedef struct CRFBData
287{
288 /* override default draw and read buffers to be used for offscreen rendering */
289 GLint idOverrrideFBO;
290 uint32_t u32Version;
291 uint32_t cElements;
292 CRFBDataElement aElements[1];
293} CRFBData;
294
295DECLEXPORT(void) crStateApplyFBImage(CRContext *to, CRFBData *data);
296DECLEXPORT(int) crStateAcquireFBImage(CRContext *to, CRFBData *data);
297DECLEXPORT(void) crStateFreeFBImageLegacy(CRContext *to);
298
299DECLEXPORT(void) crStateGetTextureObjectAndImage(CRContext *g, GLenum texTarget, GLint level,
300 CRTextureObj **obj, CRTextureLevel **img);
301
302
303DECLEXPORT(void) crStateReleaseTexture(CRContext *pCtx, CRTextureObj *pObj);
304
305#ifndef IN_GUEST
306DECLEXPORT(int32_t) crStateSaveContext(CRContext *pContext, PSSMHANDLE pSSM);
307typedef DECLCALLBACK(CRContext*) FNCRSTATE_CONTEXT_GET(void*);
308typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
309DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version);
310DECLEXPORT(void) crStateFreeShared(PCRStateTracker pState, CRContext *pContext, CRSharedState *s);
311
312DECLEXPORT(int32_t) crStateLoadGlobals(PCRStateTracker pState, PSSMHANDLE pSSM, uint32_t u32Version);
313DECLEXPORT(int32_t) crStateSaveGlobals(PCRStateTracker pState, PSSMHANDLE pSSM);
314
315DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(PCRStateTracker pState);
316DECLEXPORT(void) crStateGlobalSharedRelease(PCRStateTracker pState);
317#endif
318
319DECLEXPORT(void) crStateSetTextureUsed(PCRStateTracker pState, GLuint texture, GLboolean used);
320DECLEXPORT(void) crStatePinTexture(PCRStateTracker pState, GLuint texture, GLboolean pin);
321DECLEXPORT(void) crStateDeleteTextureCallback(void *texObj, void *pvUser);
322
323 /* XXX move these! */
324
325DECLEXPORT(void) STATE_APIENTRY crStateChromiumParameteriCR(PCRStateTracker pState, GLenum target, GLint value );
326DECLEXPORT(void) STATE_APIENTRY crStateChromiumParameterfCR(PCRStateTracker pState, GLenum target, GLfloat value );
327DECLEXPORT(void) STATE_APIENTRY crStateChromiumParametervCR(PCRStateTracker pState, GLenum target, GLenum type, GLsizei count, const GLvoid *values );
328DECLEXPORT(void) STATE_APIENTRY crStateGetChromiumParametervCR(PCRStateTracker pState, GLenum target, GLuint index, GLenum type,
329 GLsizei count, GLvoid *values );
330DECLEXPORT(void) STATE_APIENTRY crStateReadPixels(PCRStateTracker pState, GLint x, GLint y, GLsizei width, GLsizei height,
331 GLenum format, GLenum type, GLvoid *pixels );
332DECLEXPORT(void) STATE_APIENTRY crStateShareContext(PCRStateTracker pState, GLboolean value);
333DECLEXPORT(void) STATE_APIENTRY crStateShareLists(CRContext *pContext1, CRContext *pContext2);
334DECLEXPORT(void) STATE_APIENTRY crStateSetSharedContext(CRContext *pCtx);
335DECLEXPORT(GLboolean) STATE_APIENTRY crStateContextIsShared(CRContext *pCtx);
336DECLEXPORT(void) STATE_APIENTRY crStateQueryHWState(PCRStateTracker pState, GLuint fbFbo, GLuint bbFbo);
337#ifdef __cplusplus
338}
339#endif
340
341#endif /* CR_GLSTATE_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette