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_STATE_PROGRAM_H
|
---|
8 | #define CR_STATE_PROGRAM_H
|
---|
9 |
|
---|
10 | #include "cr_hash.h"
|
---|
11 | #include "state/cr_statetypes.h"
|
---|
12 | #include "state/cr_limits.h"
|
---|
13 |
|
---|
14 | #include <iprt/cdefs.h>
|
---|
15 |
|
---|
16 | /*
|
---|
17 | * Dirty bits for per-context program state. Per-program dirty bits
|
---|
18 | * are in the CRProgram structure.
|
---|
19 | */
|
---|
20 | typedef struct {
|
---|
21 | CRbitvalue dirty[CR_MAX_BITARRAY];
|
---|
22 | CRbitvalue vpEnable[CR_MAX_BITARRAY];
|
---|
23 | CRbitvalue fpEnable[CR_MAX_BITARRAY];
|
---|
24 | CRbitvalue vpBinding[CR_MAX_BITARRAY];
|
---|
25 | CRbitvalue fpBinding[CR_MAX_BITARRAY];
|
---|
26 | CRbitvalue vertexAttribArrayEnable[CR_MAX_VERTEX_ATTRIBS][CR_MAX_BITARRAY];
|
---|
27 | CRbitvalue map1AttribArrayEnable[CR_MAX_VERTEX_ATTRIBS][CR_MAX_BITARRAY];
|
---|
28 | CRbitvalue map2AttribArrayEnable[CR_MAX_VERTEX_ATTRIBS][CR_MAX_BITARRAY];
|
---|
29 | /* per-param flags: */
|
---|
30 | CRbitvalue vertexEnvParameter[CR_MAX_VERTEX_PROGRAM_ENV_PARAMS][CR_MAX_BITARRAY];
|
---|
31 | CRbitvalue fragmentEnvParameter[CR_MAX_FRAGMENT_PROGRAM_ENV_PARAMS][CR_MAX_BITARRAY];
|
---|
32 | /* any param flags: */
|
---|
33 | CRbitvalue vertexEnvParameters[CR_MAX_BITARRAY];
|
---|
34 | CRbitvalue fragmentEnvParameters[CR_MAX_BITARRAY];
|
---|
35 | CRbitvalue trackMatrix[CR_MAX_VERTEX_PROGRAM_ENV_PARAMS / 4][CR_MAX_BITARRAY];
|
---|
36 | } CRProgramBits;
|
---|
37 |
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * Fragment programs have named symbols which are defined/declared
|
---|
41 | * within the fragment program that can also be set with the
|
---|
42 | * glProgramNamedParameter4*NV() functions.
|
---|
43 | * We keep a linked list of these CRProgramSymbol structures to implement
|
---|
44 | * a symbol table. A simple linked list is sufficient since a fragment
|
---|
45 | * program typically has just a few symbols.
|
---|
46 | */
|
---|
47 | typedef struct CRProgramSymbol {
|
---|
48 | const char *name;
|
---|
49 | GLuint cbName;
|
---|
50 | GLfloat value[4];
|
---|
51 | CRbitvalue dirty[CR_MAX_BITARRAY];
|
---|
52 | struct CRProgramSymbol *next;
|
---|
53 | } CRProgramSymbol;
|
---|
54 |
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * A vertex or fragment program.
|
---|
58 | */
|
---|
59 | typedef struct {
|
---|
60 | GLenum target;
|
---|
61 | GLuint id;
|
---|
62 | GLboolean isARBprogram; /* to distinguish between NV and ARB programs */
|
---|
63 | const GLubyte *string;
|
---|
64 | GLsizei length;
|
---|
65 | GLboolean resident;
|
---|
66 | GLenum format;
|
---|
67 |
|
---|
68 | /* Set with ProgramNamedParameterNV */
|
---|
69 | struct CRProgramSymbol *symbolTable;
|
---|
70 |
|
---|
71 | /* Set with ProgramLocalParameterARB: */
|
---|
72 | GLfloat parameters[CR_MAX_PROGRAM_LOCAL_PARAMS][4];
|
---|
73 |
|
---|
74 | /* ARB info (this could be impossible to implement without parsing */
|
---|
75 | GLint numInstructions;
|
---|
76 | GLint numTemporaries;
|
---|
77 | GLint numParameters;
|
---|
78 | GLint numAttributes;
|
---|
79 | GLint numAddressRegs;
|
---|
80 | GLint numAluInstructions;
|
---|
81 | GLint numTexInstructions;
|
---|
82 | GLint numTexIndirections;
|
---|
83 |
|
---|
84 | CRbitvalue dirtyNamedParams[CR_MAX_BITARRAY];
|
---|
85 | CRbitvalue dirtyParam[CR_MAX_PROGRAM_LOCAL_PARAMS][CR_MAX_BITARRAY];
|
---|
86 | CRbitvalue dirtyParams[CR_MAX_BITARRAY];
|
---|
87 | CRbitvalue dirtyProgram[CR_MAX_BITARRAY];
|
---|
88 | } CRProgram;
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | typedef struct {
|
---|
93 | CRProgram *currentVertexProgram;
|
---|
94 | CRProgram *currentFragmentProgram;
|
---|
95 | GLint errorPos;
|
---|
96 | const GLubyte *errorString;
|
---|
97 | GLboolean loadedProgram; /* XXX temporary */
|
---|
98 |
|
---|
99 | CRProgram *defaultVertexProgram;
|
---|
100 | CRProgram *defaultFragmentProgram;
|
---|
101 |
|
---|
102 | /* tracking matrices for vertex programs */
|
---|
103 | GLenum TrackMatrix[CR_MAX_VERTEX_PROGRAM_LOCAL_PARAMS / 4];
|
---|
104 | GLenum TrackMatrixTransform[CR_MAX_VERTEX_PROGRAM_LOCAL_PARAMS / 4];
|
---|
105 |
|
---|
106 | /* global/env params shared by all programs */
|
---|
107 | GLfloat fragmentParameters[CR_MAX_FRAGMENT_PROGRAM_ENV_PARAMS][4];
|
---|
108 | GLfloat vertexParameters[CR_MAX_VERTEX_PROGRAM_ENV_PARAMS][4];
|
---|
109 |
|
---|
110 | CRHashTable *programHash; /* XXX belongs in shared state, actually */
|
---|
111 |
|
---|
112 | GLuint vpProgramBinding;
|
---|
113 | GLuint fpProgramBinding;
|
---|
114 | GLboolean vpEnabled; /* GL_VERTEX_PROGRAM_NV / ARB*/
|
---|
115 | GLboolean fpEnabled; /* GL_FRAGMENT_PROGRAM_NV */
|
---|
116 | GLboolean fpEnabledARB; /* GL_FRAGMENT_PROGRAM_ARB */
|
---|
117 | GLboolean vpPointSize; /* GL_VERTEX_PROGRAM_NV */
|
---|
118 | GLboolean vpTwoSide; /* GL_VERTEX_PROGRAM_NV */
|
---|
119 |
|
---|
120 | /* Indicates that we have to resend program data to GPU on first glMakeCurrent call with owning context */
|
---|
121 | GLboolean bResyncNeeded;
|
---|
122 |
|
---|
123 | } CRProgramState;
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | extern DECLEXPORT(void) crStateProgramInit(CRContext *ctx);
|
---|
128 | extern DECLEXPORT(void) crStateProgramDestroy(CRContext *ctx);
|
---|
129 |
|
---|
130 | extern DECLEXPORT(void) crStateProgramDiff(CRProgramBits *b, CRbitvalue *bitID,
|
---|
131 | CRContext *fromCtx, CRContext *toCtx);
|
---|
132 | extern DECLEXPORT(void) crStateProgramSwitch(CRProgramBits *b, CRbitvalue *bitID,
|
---|
133 | CRContext *fromCtx, CRContext *toCtx);
|
---|
134 |
|
---|
135 | DECLEXPORT(void) crStateDiffAllPrograms(CRContext *g, CRbitvalue *bitID, GLboolean bForceUpdate);
|
---|
136 |
|
---|
137 | #endif /* CR_STATE_PROGRAM_H */
|
---|