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