VirtualBox

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

Last change on this file since 76541 was 69474, checked in by vboxsync, 7 years ago

*: scm updates - header files should have 'svn:keywords=Id Revision' too (doesn't mean they have to use them).

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