1 | /* $Id: cr_glsl.h 78375 2019-05-03 21:51:02Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox crOpenGL: GLSL related state info
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009-2019 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef CR_STATE_GLSL_H
|
---|
20 | #define CR_STATE_GLSL_H
|
---|
21 |
|
---|
22 | #include "cr_hash.h"
|
---|
23 | #include "state/cr_statetypes.h"
|
---|
24 | #include "state/cr_statefuncs.h"
|
---|
25 |
|
---|
26 | #ifdef __cplusplus
|
---|
27 | extern "C" {
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | /* We can't go the "easy" way of just extracting all the required data when taking snapshots.
|
---|
31 | Shader objects might be modified *after* program linkage and wouldn't affect program until it's relinked.
|
---|
32 | So we have to keep track of shaders statuses right before each program was linked as well as their "current" status.
|
---|
33 | */
|
---|
34 |
|
---|
35 | /*@todo: check rare case when successfully linked and active program is relinked with failure*/
|
---|
36 |
|
---|
37 | typedef struct {
|
---|
38 | GLuint id, hwid;
|
---|
39 | GLenum type; /*GL_VERTEX_SHADER or GL_FRAGMENT_SHADER*/
|
---|
40 | GLchar* source; /*NULL after context loading unless in program's "active" hash*/
|
---|
41 | GLboolean compiled, deleted;
|
---|
42 | GLuint refCount; /*valid only for shaders in CRGLSLState's hash*/
|
---|
43 | } CRGLSLShader;
|
---|
44 |
|
---|
45 | typedef struct {
|
---|
46 | GLchar* name;
|
---|
47 | GLuint index;
|
---|
48 | } CRGLSLAttrib;
|
---|
49 |
|
---|
50 | /*Note: active state will hold copies of shaders while current state references shaders in the CRGLSLState hashtable*/
|
---|
51 | /*@todo: probably don't need a hashtable here*/
|
---|
52 | typedef struct {
|
---|
53 | CRHashTable *attachedShaders;
|
---|
54 | CRGLSLAttrib *pAttribs; /*several names could be bound to the same index*/
|
---|
55 | GLuint cAttribs;
|
---|
56 | } CRGLSLProgramState;
|
---|
57 |
|
---|
58 | typedef struct{
|
---|
59 | GLchar *name;
|
---|
60 | GLenum type;
|
---|
61 | GLvoid *data;
|
---|
62 | #ifdef IN_GUEST
|
---|
63 | GLint location;
|
---|
64 | #endif
|
---|
65 | } CRGLSLUniform;
|
---|
66 |
|
---|
67 | typedef struct {
|
---|
68 | GLuint id, hwid;
|
---|
69 | GLboolean validated, linked, deleted;
|
---|
70 | CRGLSLProgramState activeState, currentState;
|
---|
71 | CRGLSLUniform *pUniforms;
|
---|
72 | GLuint cUniforms;
|
---|
73 | #ifdef IN_GUEST
|
---|
74 | CRGLSLAttrib *pAttribs;
|
---|
75 | GLuint cAttribs;
|
---|
76 | GLboolean bUniformsSynced; /*uniforms info is updated since last link program call.*/
|
---|
77 | GLboolean bAttribsSynced; /*attribs info is updated since last link program call.*/
|
---|
78 | #endif
|
---|
79 | } CRGLSLProgram;
|
---|
80 |
|
---|
81 | typedef struct {
|
---|
82 | CRHashTable *shaders;
|
---|
83 | CRHashTable *programs;
|
---|
84 |
|
---|
85 | CRGLSLProgram *activeProgram;
|
---|
86 |
|
---|
87 | /* Indicates that we have to resend GLSL data to GPU on first glMakeCurrent call with owning context */
|
---|
88 | GLboolean bResyncNeeded;
|
---|
89 | } CRGLSLState;
|
---|
90 |
|
---|
91 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLInit(CRContext *ctx);
|
---|
92 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLDestroy(CRContext *ctx);
|
---|
93 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLSwitch(CRContext *from, CRContext *to);
|
---|
94 |
|
---|
95 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGetShaderHWID(PCRStateTracker pState, GLuint id);
|
---|
96 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGetProgramHWID(PCRStateTracker pState, GLuint id);
|
---|
97 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLProgramHWIDtoID(PCRStateTracker pState, GLuint hwid);
|
---|
98 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGLSLShaderHWIDtoID(PCRStateTracker pState, GLuint hwid);
|
---|
99 |
|
---|
100 | DECLEXPORT(GLint) STATE_APIENTRY crStateGetUniformSize(PCRStateTracker pState, GLenum type);
|
---|
101 | DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsIntUniform(PCRStateTracker pState, GLenum type);
|
---|
102 |
|
---|
103 | DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(PCRStateTracker pState, GLuint id, GLenum type);
|
---|
104 | DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateProgram(PCRStateTracker pState, GLuint id);
|
---|
105 | DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB(PCRStateTracker pState, VBoxGLhandleARB obj );
|
---|
106 |
|
---|
107 | DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramUniformsCached(PCRStateTracker pState, GLuint program);
|
---|
108 | DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramAttribsCached(PCRStateTracker pState, GLuint program);
|
---|
109 |
|
---|
110 | #ifdef IN_GUEST
|
---|
111 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheUniforms(PCRStateTracker pState, GLuint program, GLsizei cbData, GLvoid *pData);
|
---|
112 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheAttribs(PCRStateTracker pState, GLuint program, GLsizei cbData, GLvoid *pData);
|
---|
113 | #else
|
---|
114 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheUniforms(PCRStateTracker pState, GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData);
|
---|
115 | DECLEXPORT(void) STATE_APIENTRY crStateGLSLProgramCacheAttribs(PCRStateTracker pState, GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData);
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | #ifdef __cplusplus
|
---|
119 | }
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | #endif /* CR_STATE_GLSL_H */
|
---|