VirtualBox

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

Last change on this file since 45410 was 44802, checked in by vboxsync, 12 years ago

crOpenGL: saved state: save depth and stencil buffer data (still needs more testing)

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

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