30f0ad28 |
1 | // Created on: 2013-09-19 |
2 | // Created by: Denis BOGOLEPOV |
d5f74e42 |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
30f0ad28 |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
30f0ad28 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
30f0ad28 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
30f0ad28 |
15 | |
16 | #ifndef _OpenGl_ShaderProgram_Header |
17 | #define _OpenGl_ShaderProgram_Header |
18 | |
19 | #include <NCollection_DataMap.hxx> |
20 | #include <NCollection_Sequence.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
22 | |
23 | #include <Graphic3d_ShaderObject.hxx> |
24 | #include <Graphic3d_ShaderProgram.hxx> |
25 | |
30f0ad28 |
26 | #include <OpenGl_Vec.hxx> |
27 | #include <OpenGl_Matrix.hxx> |
28 | #include <OpenGl_ShaderObject.hxx> |
30f0ad28 |
29 | |
c04c30b3 |
30 | class OpenGl_ShaderProgram; |
31 | DEFINE_STANDARD_HANDLE(OpenGl_ShaderProgram, OpenGl_Resource) |
32 | |
30f0ad28 |
33 | //! The enumeration of OCCT-specific OpenGL/GLSL variables. |
34 | enum OpenGl_StateVariable |
35 | { |
36 | // OpenGL matrix state |
37 | OpenGl_OCC_MODEL_WORLD_MATRIX, |
38 | OpenGl_OCC_WORLD_VIEW_MATRIX, |
39 | OpenGl_OCC_PROJECTION_MATRIX, |
40 | OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE, |
41 | OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE, |
42 | OpenGl_OCC_PROJECTION_MATRIX_INVERSE, |
43 | OpenGl_OCC_MODEL_WORLD_MATRIX_TRANSPOSE, |
44 | OpenGl_OCC_WORLD_VIEW_MATRIX_TRANSPOSE, |
45 | OpenGl_OCC_PROJECTION_MATRIX_TRANSPOSE, |
46 | OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE_TRANSPOSE, |
47 | OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE_TRANSPOSE, |
48 | OpenGl_OCC_PROJECTION_MATRIX_INVERSE_TRANSPOSE, |
49 | |
50 | // OpenGL clip planes state |
12381341 |
51 | OpenGl_OCC_CLIP_PLANE_EQUATIONS, |
5495fa7e |
52 | OpenGl_OCC_CLIP_PLANE_COUNT, |
30f0ad28 |
53 | |
54 | // OpenGL light state |
12381341 |
55 | OpenGl_OCC_LIGHT_SOURCE_COUNT, |
56 | OpenGl_OCC_LIGHT_SOURCE_TYPES, |
57 | OpenGl_OCC_LIGHT_SOURCE_PARAMS, |
58 | OpenGl_OCC_LIGHT_AMBIENT, |
30f0ad28 |
59 | |
60 | // Material state |
61 | OpenGl_OCCT_ACTIVE_SAMPLER, |
62 | OpenGl_OCCT_TEXTURE_ENABLE, |
63 | OpenGl_OCCT_DISTINGUISH_MODE, |
12381341 |
64 | OpenGl_OCCT_FRONT_MATERIAL, |
65 | OpenGl_OCCT_BACK_MATERIAL, |
8625ef7e |
66 | OpenGl_OCCT_COLOR, |
67 | |
79f4f036 |
68 | OpenGl_OCCT_TEXTURE_TRSF2D, |
8625ef7e |
69 | OpenGl_OCCT_POINT_SIZE, |
30f0ad28 |
70 | |
71 | // DON'T MODIFY THIS ITEM (insert new items before it) |
72 | OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES |
73 | }; |
74 | |
75 | class OpenGl_ShaderProgram; |
76 | |
77 | //! Interface for generic setter of user-defined uniform variables. |
78 | struct OpenGl_SetterInterface |
79 | { |
80 | //! Sets user-defined uniform variable to specified program. |
81 | virtual void Set (const Handle(OpenGl_Context)& theCtx, |
82 | const Handle(Graphic3d_ShaderVariable)& theVariable, |
83 | OpenGl_ShaderProgram* theProgram) = 0; |
84 | |
85 | //! Destructor |
86 | virtual ~OpenGl_SetterInterface() {} |
87 | }; |
88 | |
89 | //! List of OpenGL shader objects. |
90 | typedef NCollection_Sequence<Handle(OpenGl_ShaderObject)> OpenGl_ShaderList; |
91 | |
92 | //! List of shader variable setters. |
93 | typedef NCollection_DataMap<size_t, OpenGl_SetterInterface*> OpenGl_SetterList; |
94 | |
95 | //! Support tool for setting user-defined uniform variables. |
96 | class OpenGl_VariableSetterSelector |
97 | { |
98 | public: |
99 | |
100 | //! Creates new setter selector. |
101 | OpenGl_VariableSetterSelector(); |
102 | |
103 | //! Releases memory resources of setter selector. |
104 | ~OpenGl_VariableSetterSelector(); |
105 | |
106 | //! Sets user-defined uniform variable to specified program. |
107 | void Set (const Handle(OpenGl_Context)& theCtx, |
108 | const Handle(Graphic3d_ShaderVariable)& theVariable, |
109 | OpenGl_ShaderProgram* theProgram) const; |
110 | |
111 | private: |
112 | |
113 | //! List of variable setters. |
114 | OpenGl_SetterList mySetterList; |
115 | }; |
116 | |
117 | //! Defines types of uniform state variables. |
118 | enum OpenGl_UniformStateType |
119 | { |
120 | OpenGl_LIGHT_SOURCES_STATE, |
121 | OpenGl_CLIP_PLANES_STATE, |
122 | OpenGl_MODEL_WORLD_STATE, |
123 | OpenGl_WORLD_VIEW_STATE, |
124 | OpenGl_PROJECTION_STATE, |
e135a155 |
125 | OpenGl_MATERIALS_STATE, |
126 | OpenGl_SURF_DETAIL_STATE |
30f0ad28 |
127 | }; |
128 | |
129 | //! Total number of state types. |
130 | const int MaxStateTypes = 6; |
131 | |
132 | //! Wrapper for OpenGL program object. |
133 | class OpenGl_ShaderProgram : public OpenGl_Resource |
134 | { |
91c60b57 |
135 | friend class OpenGl_View; |
30f0ad28 |
136 | |
137 | public: |
138 | |
139 | //! Non-valid shader name. |
140 | static const GLuint NO_PROGRAM = 0; |
141 | |
142 | //! Invalid location of uniform/attribute variable. |
143 | static const GLint INVALID_LOCATION = -1; |
144 | |
145 | //! List of pre-defined OCCT state uniform variables. |
146 | static Standard_CString PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES]; |
147 | |
30f0ad28 |
148 | //! Creates uninitialized shader program. |
5440a790 |
149 | //! |
150 | //! WARNING! This constructor is not intended to be called anywhere but from OpenGl_ShaderManager::Create(). |
151 | //! Manager has been designed to synchronize camera position, lights definition and other aspects of the program implicitly, |
152 | //! as well as sharing same program across rendering groups. |
153 | //! |
154 | //! Program created outside the manager will be left detached from these routines, |
155 | //! and them should be performed manually by caller. |
156 | //! |
157 | //! This constructor has been made public to provide more flexibility to re-use OCCT OpenGL classes without OCCT Viewer itself. |
158 | //! If this is not the case - create the program using shared OpenGl_ShaderManager instance instead. |
30f0ad28 |
159 | Standard_EXPORT OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProxy = NULL); |
160 | |
5440a790 |
161 | protected: |
162 | |
30f0ad28 |
163 | static OpenGl_VariableSetterSelector mySetterSelector; |
164 | |
165 | public: |
166 | |
167 | //! Releases resources of shader program. |
168 | Standard_EXPORT virtual ~OpenGl_ShaderProgram(); |
169 | |
170 | //! Creates new empty shader program of specified type. |
171 | Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx); |
172 | |
173 | //! Destroys shader program. |
79104795 |
174 | Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE; |
30f0ad28 |
175 | |
176 | //! Attaches shader object to the program object. |
177 | Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)& theCtx, |
178 | const Handle(OpenGl_ShaderObject)& theShader); |
179 | |
180 | //! Detaches shader object to the program object. |
181 | Standard_EXPORT Standard_Boolean DetachShader (const Handle(OpenGl_Context)& theCtx, |
182 | const Handle(OpenGl_ShaderObject)& theShader); |
183 | |
184 | //! Initializes program object with the list of shader objects. |
185 | Standard_EXPORT Standard_Boolean Initialize (const Handle(OpenGl_Context)& theCtx, |
186 | const Graphic3d_ShaderObjectList& theShaders); |
187 | |
188 | //! Links the program object. |
189 | Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx); |
190 | |
191 | //! Fetches information log of the last link operation. |
192 | Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx, |
193 | TCollection_AsciiString& theLog); |
194 | |
195 | //! Fetches uniform variables from proxy shader program. |
196 | Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx); |
197 | |
12381341 |
198 | //! @return true if current object was initialized |
199 | inline bool IsValid() const |
200 | { |
201 | return myProgramID != NO_PROGRAM; |
202 | } |
203 | |
7d3e64ef |
204 | //! @return program ID |
205 | inline GLuint ProgramId() const |
206 | { |
207 | return myProgramID; |
208 | } |
209 | |
30f0ad28 |
210 | private: |
211 | |
212 | //! Returns index of last modification of variables of specified state type. |
213 | Standard_EXPORT Standard_Size ActiveState (const OpenGl_UniformStateType theType) const; |
214 | |
215 | //! Updates index of last modification of variables of specified state type. |
216 | Standard_EXPORT void UpdateState (const OpenGl_UniformStateType theType, |
217 | const Standard_Size theIndex); |
218 | |
219 | public: |
220 | |
221 | //! Returns location of the specific uniform variable. |
222 | Standard_EXPORT GLint GetUniformLocation (const Handle(OpenGl_Context)& theCtx, |
223 | const GLchar* theName) const; |
224 | |
225 | //! Returns index of the generic vertex attribute by variable name. |
226 | Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx, |
227 | const GLchar* theName) const; |
228 | |
229 | //! Returns location of the OCCT state uniform variable. |
230 | Standard_EXPORT GLint GetStateLocation (const GLuint theVariable) const; |
231 | |
232 | public: |
233 | |
234 | //! Returns the value of the integer uniform variable. |
235 | Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx, |
236 | const GLchar* theName, |
237 | OpenGl_Vec4i& theValue) const; |
238 | |
239 | Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx, |
240 | GLint theLocation, |
241 | OpenGl_Vec4i& theValue) const; |
242 | |
243 | //! Returns the value of the float uniform variable. |
244 | Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx, |
245 | const GLchar* theName, |
246 | OpenGl_Vec4& theValue) const; |
247 | |
248 | //! Returns the value of the float uniform variable. |
249 | Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx, |
250 | GLint theLocation, |
251 | OpenGl_Vec4& theValue) const; |
252 | |
253 | public: |
254 | |
255 | //! Returns the integer vertex attribute. |
256 | Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx, |
257 | const GLchar* theName, |
258 | OpenGl_Vec4i& theValue) const; |
259 | |
260 | //! Returns the integer vertex attribute. |
261 | Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx, |
262 | GLint theIndex, |
263 | OpenGl_Vec4i& theValue) const; |
264 | |
265 | //! Returns the float vertex attribute. |
266 | Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx, |
267 | const GLchar* theName, |
268 | OpenGl_Vec4& theValue) const; |
269 | |
270 | //! Returns the float vertex attribute. |
271 | Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx, |
272 | GLint theIndex, |
273 | OpenGl_Vec4& theValue) const; |
274 | |
fc73a202 |
275 | public: |
276 | |
277 | //! Wrapper for glBindAttribLocation() |
278 | Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx, |
279 | GLint theIndex, |
280 | const GLchar* theName); |
281 | |
282 | //! Wrapper for glVertexAttrib1f() |
283 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
284 | const GLchar* theName, |
285 | GLfloat theValue); |
286 | |
287 | //! Wrapper for glVertexAttrib1f() |
288 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
289 | GLint theIndex, |
290 | GLfloat theValue); |
291 | |
292 | //! Wrapper for glVertexAttrib2fv() |
293 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
294 | const GLchar* theName, |
295 | const OpenGl_Vec2& theValue); |
296 | |
297 | //! Wrapper for glVertexAttrib2fv() |
298 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
299 | GLint theIndex, |
300 | const OpenGl_Vec2& theValue); |
301 | |
302 | //! Wrapper for glVertexAttrib3fv() |
303 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
304 | const GLchar* theName, |
305 | const OpenGl_Vec3& theValue); |
306 | |
307 | //! Wrapper for glVertexAttrib3fv() |
308 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
309 | GLint theIndex, |
310 | const OpenGl_Vec3& theValue); |
311 | |
312 | //! Wrapper for glVertexAttrib4fv() |
313 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
314 | const GLchar* theName, |
315 | const OpenGl_Vec4& theValue); |
316 | |
317 | //! Wrapper for glVertexAttrib4fv() |
318 | Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx, |
319 | GLint theIndex, |
320 | const OpenGl_Vec4& theValue); |
321 | |
30f0ad28 |
322 | public: |
323 | |
324 | //! Specifies the value of the integer uniform variable. |
325 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
326 | const GLchar* theName, |
327 | GLint theValue); |
328 | |
329 | //! Specifies the value of the integer uniform variable. |
330 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
331 | GLint theLocation, |
332 | GLint theValue); |
333 | |
334 | //! Specifies the value of the integer uniform 2D vector. |
335 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
336 | const GLchar* theName, |
337 | const OpenGl_Vec2i& theValue); |
338 | |
339 | //! Specifies the value of the integer uniform 2D vector. |
340 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
341 | GLint theLocation, |
342 | const OpenGl_Vec2i& theValue); |
343 | |
344 | //! Specifies the value of the integer uniform 3D vector. |
345 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
346 | const GLchar* theName, |
347 | const OpenGl_Vec3i& theValue); |
348 | |
349 | //! Specifies the value of the integer uniform 3D vector. |
350 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
351 | GLint theLocation, |
352 | const OpenGl_Vec3i& theValue); |
353 | |
354 | //! Specifies the value of the integer uniform 4D vector. |
355 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
356 | const GLchar* theName, |
357 | const OpenGl_Vec4i& theValue); |
358 | |
359 | //! Specifies the value of the integer uniform 4D vector. |
360 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
361 | GLint theLocation, |
362 | const OpenGl_Vec4i& theValue); |
363 | |
25ef750e |
364 | public: |
365 | |
47e9c178 |
366 | //! Specifies the value of the unsigned integer uniform 2D vector (uvec2). |
25ef750e |
367 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
368 | const GLchar* theName, |
47e9c178 |
369 | const OpenGl_Vec2u& theValue); |
25ef750e |
370 | |
47e9c178 |
371 | //! Specifies the value of the unsigned integer uniform 2D vector (uvec2). |
25ef750e |
372 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
373 | GLint theLocation, |
47e9c178 |
374 | const OpenGl_Vec2u& theValue); |
25ef750e |
375 | |
47e9c178 |
376 | //! Specifies the value of the uvec2 uniform array |
25ef750e |
377 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
378 | const GLchar* theName, |
379 | const GLsizei theCount, |
47e9c178 |
380 | const OpenGl_Vec2u* theValue); |
25ef750e |
381 | |
47e9c178 |
382 | //! Specifies the value of the uvec2 uniform array |
25ef750e |
383 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
384 | GLint theLocation, |
385 | const GLsizei theCount, |
47e9c178 |
386 | const OpenGl_Vec2u* theValue); |
25ef750e |
387 | |
30f0ad28 |
388 | public: |
389 | |
390 | //! Specifies the value of the float uniform variable. |
391 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
392 | const GLchar* theName, |
393 | GLfloat theValue); |
394 | |
395 | //! Specifies the value of the float uniform variable. |
396 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
397 | GLint theLocation, |
398 | GLfloat theValue); |
399 | |
400 | //! Specifies the value of the float uniform 2D vector. |
401 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
402 | const GLchar* theName, |
403 | const OpenGl_Vec2& theValue); |
404 | |
405 | //! Specifies the value of the float uniform 2D vector. |
406 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
407 | GLint theLocation, |
408 | const OpenGl_Vec2& theValue); |
409 | |
410 | //! Specifies the value of the float uniform 3D vector. |
411 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
412 | const GLchar* theName, |
413 | const OpenGl_Vec3& theValue); |
414 | |
415 | //! Specifies the value of the float uniform 3D vector. |
416 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
417 | GLint theLocation, |
418 | const OpenGl_Vec3& theValue); |
419 | |
420 | //! Specifies the value of the float uniform 4D vector. |
421 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
422 | const GLchar* theName, |
423 | const OpenGl_Vec4& theValue); |
424 | |
425 | //! Specifies the value of the float uniform 4D vector. |
426 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
427 | GLint theLocation, |
428 | const OpenGl_Vec4& theValue); |
429 | |
430 | public: |
431 | |
25ef750e |
432 | //! Specifies the value of the float uniform 4x4 matrix. |
433 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
434 | const GLchar* theName, |
435 | const OpenGl_Mat4& theValue, |
436 | GLboolean theTranspose = GL_FALSE); |
437 | |
438 | //! Specifies the value of the float uniform 4x4 matrix. |
439 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
440 | GLint theLocation, |
441 | const OpenGl_Mat4& theValue, |
442 | GLboolean theTranspose = GL_FALSE); |
443 | |
30f0ad28 |
444 | //! Specifies the value of the float uniform 4x4 matrix. |
445 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
446 | const GLchar* theName, |
447 | const OpenGl_Matrix& theValue, |
448 | GLboolean theTranspose = GL_FALSE); |
449 | |
450 | //! Specifies the value of the float uniform 4x4 matrix. |
451 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
452 | GLint theLocation, |
453 | const OpenGl_Matrix& theValue, |
454 | GLboolean theTranspose = GL_FALSE); |
455 | |
4fe9ad57 |
456 | //! Specifies the value of the float uniform array |
457 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
458 | GLint theLocation, |
459 | GLuint theCount, |
460 | const Standard_ShortReal* theData); |
461 | |
462 | //! Specifies the value of the float2 uniform array |
463 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
464 | GLint theLocation, |
465 | GLuint theCount, |
466 | const OpenGl_Vec2* theData); |
467 | |
468 | //! Specifies the value of the float3 uniform array |
469 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
470 | GLint theLocation, |
471 | GLuint theCount, |
472 | const OpenGl_Vec3* theData); |
473 | |
474 | //! Specifies the value of the float4 uniform array |
475 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
476 | GLint theLocation, |
477 | GLuint theCount, |
478 | const OpenGl_Vec4* theData); |
479 | |
480 | //! Specifies the value of the integer uniform array |
481 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
482 | GLint theLocation, |
483 | GLuint theCount, |
484 | const Standard_Integer* theData); |
485 | |
486 | //! Specifies the value of the int2 uniform array |
487 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
488 | GLint theLocation, |
489 | GLuint theCount, |
490 | const OpenGl_Vec2i* theData); |
491 | |
492 | //! Specifies the value of the int3 uniform array |
493 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
494 | GLint theLocation, |
495 | GLuint theCount, |
496 | const OpenGl_Vec3i* theData); |
497 | |
498 | //! Specifies the value of the int4 uniform array |
499 | Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx, |
500 | GLint theLocation, |
501 | GLuint theCount, |
502 | const OpenGl_Vec4i* theData); |
503 | |
30f0ad28 |
504 | public: |
505 | |
506 | //! Specifies the value of the sampler uniform variable. |
507 | Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx, |
508 | const GLchar* theName, |
509 | const GLenum theTextureUnit); |
510 | |
511 | //! Specifies the value of the sampler uniform variable. |
512 | Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx, |
513 | GLint theLocation, |
514 | const GLenum theTextureUnit); |
515 | |
516 | protected: |
517 | |
392ac980 |
518 | //! Increments counter of users. |
519 | //! Used by OpenGl_ShaderManager. |
05dd08ce |
520 | //! @return true when resource has been restored from delayed release queue |
521 | bool Share() |
392ac980 |
522 | { |
05dd08ce |
523 | return ++myShareCount == 1; |
392ac980 |
524 | } |
525 | |
526 | //! Decrements counter of users. |
527 | //! Used by OpenGl_ShaderManager. |
528 | //! @return true when there are no more users of this program has been left |
529 | bool UnShare() |
530 | { |
531 | return --myShareCount == 0; |
532 | } |
533 | |
534 | protected: |
535 | |
536 | GLuint myProgramID; //!< Handle of OpenGL shader program |
537 | OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects |
538 | Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer) |
539 | Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user) |
30f0ad28 |
540 | |
541 | protected: |
542 | |
8625ef7e |
543 | Standard_Size myCurrentState[MaxStateTypes]; //!< defines last modification for variables of each state type |
30f0ad28 |
544 | |
545 | //! Stores locations of OCCT state uniform variables. |
546 | GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES]; |
547 | |
548 | public: |
549 | |
92efcf78 |
550 | DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderProgram,OpenGl_Resource) |
30f0ad28 |
551 | friend class OpenGl_ShaderManager; |
552 | |
553 | }; |
554 | |
555 | template<class T> |
556 | struct OpenGl_VariableSetter : public OpenGl_SetterInterface |
557 | { |
558 | virtual void Set (const Handle(OpenGl_Context)& theCtx, |
559 | const Handle(Graphic3d_ShaderVariable)& theVariable, |
560 | OpenGl_ShaderProgram* theProgram) |
561 | { |
562 | theProgram->SetUniform (theCtx, |
563 | theVariable->Name().ToCString(), |
564 | theVariable->Value()->As<T>()); |
565 | } |
566 | }; |
567 | |
568 | namespace OpenGl_HashMapInitializer |
569 | { |
570 | template<class K, class V> |
571 | struct MapListOfType |
572 | { |
573 | NCollection_DataMap<K, V> myDictionary; |
574 | |
575 | MapListOfType (K theKey, V theValue) |
576 | { |
577 | myDictionary.Bind (theKey, theValue); |
578 | } |
579 | |
580 | MapListOfType& operator() (K theKey, V theValue) |
581 | { |
582 | myDictionary.Bind (theKey, theValue); |
583 | return *this; |
584 | } |
585 | |
586 | operator const NCollection_DataMap<K, V>& () const |
587 | { |
588 | return myDictionary; |
589 | } |
590 | }; |
591 | |
592 | template<class K, class V> |
593 | MapListOfType<K, V> CreateListOf (K theKey, V theValue) |
594 | { |
595 | return MapListOfType<K, V> (theKey, theValue); |
596 | } |
597 | } |
598 | |
599 | #endif // _OpenGl_ShaderProgram_Header |