VirtualBox

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

Last change on this file since 41057 was 41057, checked in by vboxsync, 13 years ago

crOpenGL: fix gl resource leaking (server part)

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