VirtualBox

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

Last change on this file since 44124 was 44108, checked in by vboxsync, 12 years ago

crOpenGL: more state fixes & corrections

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