0027208: Show method in Message_ProgressIndicator::NewScope should not be commented out
[occt.git] / src / OpenGl / OpenGl_ShaderProgram.cxx
CommitLineData
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#include <OSD_File.hxx>
17#include <OSD_Protection.hxx>
18
7d3e64ef 19#include <Graphic3d_Buffer.hxx>
30f0ad28 20#include <Standard_Assert.hxx>
21#include <Standard_Atomic.hxx>
22#include <TCollection_ExtendedString.hxx>
23
24#include <OpenGl_Context.hxx>
25#include <OpenGl_ShaderProgram.hxx>
26#include <OpenGl_ShaderManager.hxx>
25ef750e 27#include <OpenGl_ArbTexBindless.hxx>
30f0ad28 28
47e9c178 29#include <OpenGl_GlCore32.hxx>
30f0ad28 30
92efcf78 31IMPLEMENT_STANDARD_RTTIEXT(OpenGl_ShaderProgram,OpenGl_Resource)
32
30f0ad28 33OpenGl_VariableSetterSelector OpenGl_ShaderProgram::mySetterSelector = OpenGl_VariableSetterSelector();
34
35// Declare OCCT-specific OpenGL/GLSL shader variables
36Standard_CString OpenGl_ShaderProgram::PredefinedKeywords[] =
37{
12381341 38 "occModelWorldMatrix", // OpenGl_OCC_MODEL_WORLD_MATRIX
39 "occWorldViewMatrix", // OpenGl_OCC_WORLD_VIEW_MATRIX
40 "occProjectionMatrix", // OpenGl_OCC_PROJECTION_MATRIX
41 "occModelWorldMatrixInverse", // OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE
42 "occWorldViewMatrixInverse", // OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE
43 "occProjectionMatrixInverse", // OpenGl_OCC_PROJECTION_MATRIX_INVERSE
44 "occModelWorldMatrixTranspose", // OpenGl_OCC_MODEL_WORLD_MATRIX_TRANSPOSE
45 "occWorldViewMatrixTranspose", // OpenGl_OCC_WORLD_VIEW_MATRIX_TRANSPOSE
46 "occProjectionMatrixTranspose", // OpenGl_OCC_PROJECTION_MATRIX_TRANSPOSE
47 "occModelWorldMatrixInverseTranspose", // OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE_TRANSPOSE
48 "occWorldViewMatrixInverseTranspose", // OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE_TRANSPOSE
49 "occProjectionMatrixInverseTranspose", // OpenGl_OCC_PROJECTION_MATRIX_INVERSE_TRANSPOSE
50
51 "occClipPlaneEquations", // OpenGl_OCC_CLIP_PLANE_EQUATIONS
52 "occClipPlaneSpaces", // OpenGl_OCC_CLIP_PLANE_SPACES
5495fa7e 53 "occClipPlaneCount", // OpenGl_OCC_CLIP_PLANE_COUNT
12381341 54
55 "occLightSourcesCount", // OpenGl_OCC_LIGHT_SOURCE_COUNT
56 "occLightSourcesTypes", // OpenGl_OCC_LIGHT_SOURCE_TYPES
57 "occLightSources", // OpenGl_OCC_LIGHT_SOURCE_PARAMS
58 "occLightAmbient", // OpenGl_OCC_LIGHT_AMBIENT
59
60 "occActiveSampler", // OpenGl_OCCT_ACTIVE_SAMPLER
61 "occTextureEnable", // OpenGl_OCCT_TEXTURE_ENABLE
62 "occDistinguishingMode", // OpenGl_OCCT_DISTINGUISH_MODE
63 "occFrontMaterial", // OpenGl_OCCT_FRONT_MATERIAL
8625ef7e 64 "occBackMaterial", // OpenGl_OCCT_BACK_MATERIAL
65 "occColor", // OpenGl_OCCT_COLOR
66
79f4f036 67 "occTexTrsf2d", // OpenGl_OCCT_TEXTURE_TRSF2D
8625ef7e 68 "occPointSize" // OpenGl_OCCT_POINT_SIZE
30f0ad28 69
70};
71
72// =======================================================================
73// function : OpenGl_VariableSetterSelector
74// purpose : Creates new variable setter selector
75// =======================================================================
76OpenGl_VariableSetterSelector::OpenGl_VariableSetterSelector()
77{
78 // Note: Add new variable setters here
79 mySetterList = OpenGl_HashMapInitializer::CreateListOf<size_t, OpenGl_SetterInterface*>
80 (Graphic3d_UniformValueTypeID<int>::ID, new OpenGl_VariableSetter<int>())
81 (Graphic3d_UniformValueTypeID<float>::ID, new OpenGl_VariableSetter<float>())
82 (Graphic3d_UniformValueTypeID<OpenGl_Vec2>::ID, new OpenGl_VariableSetter<OpenGl_Vec2>())
83 (Graphic3d_UniformValueTypeID<OpenGl_Vec3>::ID, new OpenGl_VariableSetter<OpenGl_Vec3>())
84 (Graphic3d_UniformValueTypeID<OpenGl_Vec4>::ID, new OpenGl_VariableSetter<OpenGl_Vec4>())
85 (Graphic3d_UniformValueTypeID<OpenGl_Vec2i>::ID, new OpenGl_VariableSetter<OpenGl_Vec2i>())
86 (Graphic3d_UniformValueTypeID<OpenGl_Vec3i>::ID, new OpenGl_VariableSetter<OpenGl_Vec3i>())
87 (Graphic3d_UniformValueTypeID<OpenGl_Vec4i>::ID, new OpenGl_VariableSetter<OpenGl_Vec4i>());
88}
89
90// =======================================================================
91// function : ~OpenGl_VariableSetterSelector
92// purpose : Releases memory resources of variable setter selector
93// =======================================================================
94OpenGl_VariableSetterSelector::~OpenGl_VariableSetterSelector()
95{
96 for (OpenGl_SetterList::Iterator anIt (mySetterList); anIt.More(); anIt.Next())
97 {
98 delete anIt.Value();
99 }
100
101 mySetterList.Clear();
102}
103
104// =======================================================================
105// function : Set
106// purpose : Sets generic variable to specified shader program
107// =======================================================================
108void OpenGl_VariableSetterSelector::Set (const Handle(OpenGl_Context)& theCtx,
109 const Handle(Graphic3d_ShaderVariable)& theVariable,
110 OpenGl_ShaderProgram* theProgram) const
111{
112 Standard_ASSERT_RETURN (mySetterList.IsBound (theVariable->Value()->TypeID()),
113 "The type of user-defined uniform variable is not supported...", );
114
115 mySetterList.Find (theVariable->Value()->TypeID())->Set (theCtx, theVariable, theProgram);
116}
117
118// =======================================================================
119// function : OpenGl_ShaderProgram
120// purpose : Creates uninitialized shader program
121// =======================================================================
122OpenGl_ShaderProgram::OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProxy)
123: myProgramID (NO_PROGRAM),
392ac980 124 myProxy (theProxy),
125 myShareCount(1)
30f0ad28 126{
127 memset (myCurrentState, 0, sizeof (myCurrentState));
128 for (GLint aVar = 0; aVar < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES; ++aVar)
129 {
130 myStateLocations[aVar] = INVALID_LOCATION;
131 }
132}
133
134// =======================================================================
135// function : Initialize
136// purpose : Initializes program object with the list of shader objects
137// =======================================================================
138Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)& theCtx,
139 const Graphic3d_ShaderObjectList& theShaders)
140{
141 if (theCtx.IsNull() || !Create (theCtx))
142 {
143 return Standard_False;
144 }
145
12381341 146 OSD_File aDeclFile (Graphic3d_ShaderProgram::ShadersFolder() + "/Declarations.glsl");
147 OSD_File aDeclImplFile (Graphic3d_ShaderProgram::ShadersFolder() + "/DeclarationsImpl.glsl");
148 if (!aDeclFile.Exists()
149 || !aDeclImplFile.Exists())
30f0ad28 150 {
392ac980 151 const TCollection_ExtendedString aMsg = "Error! Failed to load OCCT shader declarations file";
3b523c4c 152 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
153 GL_DEBUG_TYPE_ERROR,
30f0ad28 154 0,
3b523c4c 155 GL_DEBUG_SEVERITY_HIGH,
30f0ad28 156 aMsg);
30f0ad28 157 return Standard_False;
158 }
159
b86bb3df 160 TCollection_AsciiString aHeader = !myProxy.IsNull() && !myProxy->Header().IsEmpty()
161 ? (myProxy->Header() + "\n")
162 : TCollection_AsciiString();
163
30f0ad28 164 TCollection_AsciiString aDeclarations;
30f0ad28 165 aDeclFile.Open (OSD_ReadOnly, OSD_Protection());
bd0b3e60 166 aDeclFile.Read (aDeclarations, (int)aDeclFile.Size());
30f0ad28 167 aDeclFile.Close();
168
12381341 169 TCollection_AsciiString aDeclImpl;
170 aDeclImplFile.Open (OSD_ReadOnly, OSD_Protection());
171 aDeclImplFile.Read (aDeclImpl, (int)aDeclImplFile.Size());
172 aDeclImplFile.Close();
173 aDeclarations += aDeclImpl;
174
30f0ad28 175 for (Graphic3d_ShaderObjectList::Iterator anIter (theShaders);
176 anIter.More(); anIter.Next())
177 {
178 if (!anIter.Value()->IsDone())
179 {
392ac980 180 const TCollection_ExtendedString aMsg = "Error! Failed to get shader source";
3b523c4c 181 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
182 GL_DEBUG_TYPE_ERROR,
30f0ad28 183 0,
3b523c4c 184 GL_DEBUG_SEVERITY_HIGH,
30f0ad28 185 aMsg);
30f0ad28 186 return Standard_False;
187 }
188
189 Handle(OpenGl_ShaderObject) aShader;
190
191 // Note: Add support of other shader types here
192 switch (anIter.Value()->Type())
193 {
194 case Graphic3d_TOS_VERTEX:
195 aShader = new OpenGl_ShaderObject (GL_VERTEX_SHADER);
196 break;
197 case Graphic3d_TOS_FRAGMENT:
198 aShader = new OpenGl_ShaderObject (GL_FRAGMENT_SHADER);
199 break;
200 }
201
202 // Is unsupported shader type?
203 if (aShader.IsNull())
204 {
205 TCollection_ExtendedString aMsg = "Error! Unsupported shader type";
3b523c4c 206 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
207 GL_DEBUG_TYPE_ERROR,
30f0ad28 208 0,
3b523c4c 209 GL_DEBUG_SEVERITY_HIGH,
30f0ad28 210 aMsg);
30f0ad28 211 return Standard_False;
212 }
213
214 if (!aShader->Create (theCtx))
215 {
392ac980 216 aShader->Release (theCtx.operator->());
30f0ad28 217 return Standard_False;
218 }
219
220 TCollection_AsciiString aSource = aDeclarations + anIter.Value()->Source();
8625ef7e 221 switch (anIter.Value()->Type())
30f0ad28 222 {
8625ef7e 223 case Graphic3d_TOS_VERTEX:
224 {
b86bb3df 225 aSource = aHeader + TCollection_AsciiString ("#define VERTEX_SHADER\n") + aSource;
8625ef7e 226 break;
227 }
228 case Graphic3d_TOS_FRAGMENT:
229 {
230 #if defined(GL_ES_VERSION_2_0)
231 TCollection_AsciiString aPrefix (theCtx->hasHighp
232 ? "precision highp float;\n"
8a53d1c4 233 "precision highp int;\n"
234 : "precision mediump float;\n"
235 "precision mediump int;\n");
b86bb3df 236 aSource = aHeader + aPrefix + aSource;
4e1523ef 237 #else
238 aSource = aHeader + aSource;
8625ef7e 239 #endif
240 break;
241 }
30f0ad28 242 }
243
244 if (!aShader->LoadSource (theCtx, aSource))
245 {
392ac980 246 const TCollection_ExtendedString aMsg = "Error! Failed to set shader source";
3b523c4c 247 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
248 GL_DEBUG_TYPE_ERROR,
30f0ad28 249 0,
3b523c4c 250 GL_DEBUG_SEVERITY_HIGH,
30f0ad28 251 aMsg);
392ac980 252 aShader->Release (theCtx.operator->());
30f0ad28 253 return Standard_False;
254 }
255
256 if (!aShader->Compile (theCtx))
257 {
392ac980 258 TCollection_AsciiString aLog;
259 aShader->FetchInfoLog (theCtx, aLog);
260 if (aLog.IsEmpty())
261 {
262 aLog = "Compilation log is empty.";
263 }
3b523c4c 264 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
265 GL_DEBUG_TYPE_ERROR,
30f0ad28 266 0,
3b523c4c 267 GL_DEBUG_SEVERITY_HIGH,
392ac980 268 TCollection_ExtendedString ("Failed to compile shader object. Compilation log:\n") + aLog);
269 aShader->Release (theCtx.operator->());
270 return Standard_False;
271 }
272 else if (theCtx->caps->glslWarnings)
273 {
274 TCollection_AsciiString aLog;
275 aShader->FetchInfoLog (theCtx, aLog);
276 if (!aLog.IsEmpty()
277 && !aLog.IsEqual ("No errors.\n"))
30f0ad28 278 {
3b523c4c 279 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
280 GL_DEBUG_TYPE_PORTABILITY,
392ac980 281 0,
3b523c4c 282 GL_DEBUG_SEVERITY_LOW,
392ac980 283 TCollection_ExtendedString ("Shader compilation log:\n") + aLog);
30f0ad28 284 }
30f0ad28 285 }
286
287 if (!AttachShader (theCtx, aShader))
288 {
392ac980 289 aShader->Release (theCtx.operator->());
30f0ad28 290 return Standard_False;
291 }
292 }
293
7d3e64ef 294 // bind locations for pre-defined Vertex Attributes
295 SetAttributeName (theCtx, Graphic3d_TOA_POS, "occVertex");
296 SetAttributeName (theCtx, Graphic3d_TOA_NORM, "occNormal");
297 SetAttributeName (theCtx, Graphic3d_TOA_UV, "occTexCoord");
8625ef7e 298 SetAttributeName (theCtx, Graphic3d_TOA_COLOR, "occVertColor");
7d3e64ef 299
30f0ad28 300 if (!Link (theCtx))
301 {
392ac980 302 TCollection_AsciiString aLog;
303 FetchInfoLog (theCtx, aLog);
304 if (aLog.IsEmpty())
305 {
306 aLog = "Linker log is empty.";
307 }
3b523c4c 308 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
309 GL_DEBUG_TYPE_ERROR,
30f0ad28 310 0,
3b523c4c 311 GL_DEBUG_SEVERITY_HIGH,
12381341 312 TCollection_ExtendedString ("Failed to link program object! Linker log:\n") + aLog);
392ac980 313 return Standard_False;
314 }
315 else if (theCtx->caps->glslWarnings)
316 {
317 TCollection_AsciiString aLog;
318 FetchInfoLog (theCtx, aLog);
319 if (!aLog.IsEmpty()
320 && !aLog.IsEqual ("No errors.\n"))
30f0ad28 321 {
3b523c4c 322 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
323 GL_DEBUG_TYPE_PORTABILITY,
392ac980 324 0,
3b523c4c 325 GL_DEBUG_SEVERITY_LOW,
392ac980 326 TCollection_ExtendedString ("GLSL linker log:\n") + aLog);
30f0ad28 327 }
30f0ad28 328 }
329
330 return Standard_True;
331}
332
333// =======================================================================
334// function : ~OpenGl_ShaderProgram
335// purpose : Releases resources of shader program
336// =======================================================================
337OpenGl_ShaderProgram::~OpenGl_ShaderProgram()
338{
339 Release (NULL);
340}
341
342// =======================================================================
343// function : AttachShader
344// purpose : Attaches shader object to the program object
345// =======================================================================
346Standard_Boolean OpenGl_ShaderProgram::AttachShader (const Handle(OpenGl_Context)& theCtx,
347 const Handle(OpenGl_ShaderObject)& theShader)
348{
349 if (myProgramID == NO_PROGRAM || theShader.IsNull())
350 {
351 return Standard_False;
352 }
353
354 for (OpenGl_ShaderList::Iterator anIter (myShaderObjects); anIter.More(); anIter.Next())
355 {
356 if (theShader == anIter.Value())
357 {
358 return Standard_False;
359 }
360 }
361
362 myShaderObjects.Append (theShader);
4e1523ef 363 theCtx->core20fwd->glAttachShader (myProgramID, theShader->myShaderID);
30f0ad28 364 return Standard_True;
365}
366
367// =======================================================================
368// function : DetachShader
369// purpose : Detaches shader object to the program object
370// =======================================================================
371Standard_Boolean OpenGl_ShaderProgram::DetachShader (const Handle(OpenGl_Context)& theCtx,
372 const Handle(OpenGl_ShaderObject)& theShader)
373{
374 if (myProgramID == NO_PROGRAM
375 || theShader.IsNull())
376 {
377 return Standard_False;
378 }
379
380 OpenGl_ShaderList::Iterator anIter (myShaderObjects);
381 while (anIter.More())
382 {
383 if (theShader == anIter.Value())
384 {
385 myShaderObjects.Remove (anIter);
386 break;
387 }
388
389 anIter.Next();
390 }
391
392 if (!anIter.More())
393 {
394 return Standard_False;
395 }
396
4e1523ef 397 theCtx->core20fwd->glDetachShader (myProgramID, theShader->myShaderID);
30f0ad28 398 return Standard_True;
399}
400
401// =======================================================================
402// function : Link
403// purpose : Links the program object
404// =======================================================================
405Standard_Boolean OpenGl_ShaderProgram::Link (const Handle(OpenGl_Context)& theCtx)
406{
407 if (myProgramID == NO_PROGRAM)
408 {
409 return Standard_False;
410 }
411
30f0ad28 412 GLint aStatus = GL_FALSE;
4e1523ef 413 theCtx->core20fwd->glLinkProgram (myProgramID);
414 theCtx->core20fwd->glGetProgramiv (myProgramID, GL_LINK_STATUS, &aStatus);
fc73a202 415 if (aStatus == GL_FALSE)
416 {
417 return Standard_False;
418 }
30f0ad28 419
420 for (GLint aVar = 0; aVar < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES; ++aVar)
421 {
422 myStateLocations[aVar] = GetUniformLocation (theCtx, PredefinedKeywords[aVar]);
423 }
fc73a202 424 return Standard_True;
30f0ad28 425}
426
427// =======================================================================
428// function : FetchInfoLog
429// purpose : Fetches information log of the last link operation
430// =======================================================================
431Standard_Boolean OpenGl_ShaderProgram::FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
432 TCollection_AsciiString& theOutput)
433{
434 if (myProgramID == NO_PROGRAM)
435 {
436 return Standard_False;
437 }
438
439 GLint aLength = 0;
4e1523ef 440 theCtx->core20fwd->glGetProgramiv (myProgramID, GL_INFO_LOG_LENGTH, &aLength);
30f0ad28 441 if (aLength > 0)
442 {
443 GLchar* aLog = (GLchar*) alloca (aLength);
444 memset (aLog, 0, aLength);
4e1523ef 445 theCtx->core20fwd->glGetProgramInfoLog (myProgramID, aLength, NULL, aLog);
30f0ad28 446 theOutput = aLog;
447 }
448 return Standard_True;
449}
450
30f0ad28 451// =======================================================================
452// function : ApplyVariables
453// purpose : Fetches uniform variables from proxy shader program
454// =======================================================================
455Standard_Boolean OpenGl_ShaderProgram::ApplyVariables(const Handle(OpenGl_Context)& theCtx)
456{
457 if (myProxy.IsNull() || myProxy->Variables().IsEmpty())
458 {
459 return Standard_False;
460 }
461
462 for (Graphic3d_ShaderVariableList::Iterator anIter (myProxy->Variables()); anIter.More(); anIter.Next())
463 {
464 mySetterSelector.Set (theCtx, anIter.Value(), this);
465 }
466
467 myProxy->ClearVariables();
468 return Standard_True;
469}
470
30f0ad28 471// =======================================================================
472// function : ActiveState
473// purpose : Returns index of last modification for specified state type
474// =======================================================================
475Standard_Size OpenGl_ShaderProgram::ActiveState (const OpenGl_UniformStateType theType) const
476{
477 if (theType < MaxStateTypes)
478 {
479 return myCurrentState[theType];
480 }
481 return 0;
482}
483
484// =======================================================================
485// function : UpdateState
486// purpose : Updates index of last modification for specified state type
487// =======================================================================
488void OpenGl_ShaderProgram::UpdateState (const OpenGl_UniformStateType theType,
489 const Standard_Size theIndex)
490{
491 if (theType < MaxStateTypes)
492 {
493 myCurrentState[theType] = theIndex;
494 }
495}
496
497// =======================================================================
498// function : GetUniformLocation
499// purpose : Returns location (index) of the specific uniform variable
500// =======================================================================
501GLint OpenGl_ShaderProgram::GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
502 const GLchar* theName) const
503{
504 return myProgramID != NO_PROGRAM
4e1523ef 505 ? theCtx->core20fwd->glGetUniformLocation (myProgramID, theName)
30f0ad28 506 : INVALID_LOCATION;
507}
508
509// =======================================================================
510// function : GetAttributeLocation
511// purpose : Returns location (index) of the generic vertex attribute
512// =======================================================================
513GLint OpenGl_ShaderProgram::GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
514 const GLchar* theName) const
515{
516 return myProgramID != NO_PROGRAM
4e1523ef 517 ? theCtx->core20fwd->glGetAttribLocation (myProgramID, theName)
30f0ad28 518 : INVALID_LOCATION;
519}
520
521// =======================================================================
522// function : GetStateLocation
523// purpose : Returns location of the OCCT state uniform variable
524// =======================================================================
525GLint OpenGl_ShaderProgram::GetStateLocation (const GLuint theVariable) const
526{
527 if (theVariable < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES)
528 {
529 return myStateLocations[theVariable];
530 }
531 return INVALID_LOCATION;
532}
533
534// =======================================================================
535// function : GetUniform
536// purpose : Returns the value of the integer uniform variable
537// =======================================================================
538Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)& theCtx,
539 const GLchar* theName,
540 OpenGl_Vec4i& theValue) const
541{
542 return GetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
543}
544
545// =======================================================================
546// function : GetUniform
547// purpose : Returns the value of the integer uniform variable
548// =======================================================================
549Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)& theCtx,
550 GLint theLocation,
551 OpenGl_Vec4i& theValue) const
552{
553 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
554 {
555 return Standard_False;
556 }
557
4e1523ef 558 theCtx->core20fwd->glGetUniformiv (myProgramID, theLocation, theValue);
30f0ad28 559 return Standard_True;
560}
561
562// =======================================================================
563// function : GetUniform
564// purpose : Returns the value of the floating-point uniform variable
565// =======================================================================
566Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)& theCtx,
567 const GLchar* theName,
568 OpenGl_Vec4& theValue) const
569{
570 return GetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
571}
572
573// =======================================================================
574// function : GetUniform
575// purpose : Returns the value of the floating-point uniform variable
576// =======================================================================
577Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)& theCtx,
578 GLint theLocation,
579 OpenGl_Vec4& theValue) const
580{
581 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
582 {
583 return Standard_False;
584 }
585
4e1523ef 586 theCtx->core20fwd->glGetUniformfv (myProgramID, theLocation, theValue);
30f0ad28 587 return Standard_True;
588}
589
590// =======================================================================
591// function : GetAttribute
592// purpose : Returns the integer vertex attribute
593// =======================================================================
594Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context)& theCtx,
595 const GLchar* theName,
596 OpenGl_Vec4i& theValue) const
597{
598 return GetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
599}
600
601// =======================================================================
602// function : GetAttribute
603// purpose : Returns the integer vertex attribute
604// =======================================================================
605Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context)& theCtx,
606 GLint theIndex,
607 OpenGl_Vec4i& theValue) const
608{
609 if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
610 {
611 return Standard_False;
612 }
613
4e1523ef 614 theCtx->core20fwd->glGetVertexAttribiv (theIndex, GL_CURRENT_VERTEX_ATTRIB, theValue);
30f0ad28 615 return Standard_True;
616}
617
618// =======================================================================
619// function : GetAttribute
620// purpose : Returns the floating-point vertex attribute
621// =======================================================================
622Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context)& theCtx,
623 const GLchar* theName,
624 OpenGl_Vec4& theValue) const
625{
626 return GetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
627}
628
629// =======================================================================
630// function : GetAttribute
631// purpose : Returns the floating-point vertex attribute
632// =======================================================================
633Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context)& theCtx,
634 GLint theIndex,
635 OpenGl_Vec4& theValue) const
636{
637 if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
638 {
639 return Standard_False;
640 }
641
4e1523ef 642 theCtx->core20fwd->glGetVertexAttribfv (theIndex, GL_CURRENT_VERTEX_ATTRIB, theValue);
30f0ad28 643 return Standard_True;
644}
645
fc73a202 646// =======================================================================
647// function : SetAttributeName
648// purpose :
649// =======================================================================
650Standard_Boolean OpenGl_ShaderProgram::SetAttributeName (const Handle(OpenGl_Context)& theCtx,
651 GLint theIndex,
652 const GLchar* theName)
653{
654 theCtx->core20fwd->glBindAttribLocation (myProgramID, theIndex, theName);
655 return Standard_True;
656}
b86bb3df 657
fc73a202 658// =======================================================================
659// function : SetAttribute
660// purpose :
661// =======================================================================
662Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
663 const GLchar* theName,
664 GLfloat theValue)
665{
666 return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
667}
668
669// =======================================================================
670// function : SetAttribute
671// purpose :
672// =======================================================================
673Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
674 GLint theIndex,
675 GLfloat theValue)
676{
677 if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
678 {
679 return Standard_False;
680 }
681
682 theCtx->core20fwd->glVertexAttrib1f (theIndex, theValue);
683 return Standard_True;
684}
685
686// =======================================================================
687// function : SetAttribute
688// purpose :
689// =======================================================================
690Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
691 const GLchar* theName,
692 const OpenGl_Vec2& theValue)
693{
694 return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
695}
696
697// =======================================================================
698// function : SetAttribute
699// purpose :
700// =======================================================================
701Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
702 GLint theIndex,
703 const OpenGl_Vec2& theValue)
704{
705 if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
706 {
707 return Standard_False;
708 }
709
710 theCtx->core20fwd->glVertexAttrib2fv (theIndex, theValue);
711 return Standard_True;
712}
713
714// =======================================================================
715// function : SetAttribute
716// purpose :
717// =======================================================================
718Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
719 const GLchar* theName,
720 const OpenGl_Vec3& theValue)
721{
722 return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
723}
724
725// =======================================================================
726// function : SetAttribute
727// purpose :
728// =======================================================================
729Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
730 GLint theIndex,
731 const OpenGl_Vec3& theValue)
732{
733 if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
734 {
735 return Standard_False;
736 }
737
738 theCtx->core20fwd->glVertexAttrib3fv (theIndex, theValue);
739 return Standard_True;
740}
741
742// =======================================================================
743// function : SetAttribute
744// purpose :
745// =======================================================================
746Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
747 const GLchar* theName,
748 const OpenGl_Vec4& theValue)
749{
750 return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
751}
752
753// =======================================================================
754// function : SetAttribute
755// purpose :
756// =======================================================================
757Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
758 GLint theIndex,
759 const OpenGl_Vec4& theValue)
760{
761 if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
762 {
763 return Standard_False;
764 }
765
766 theCtx->core20fwd->glVertexAttrib4fv (theIndex, theValue);
767 return Standard_True;
768}
769
30f0ad28 770// =======================================================================
771// function : SetUniform
772// purpose : Specifies the value of the integer uniform variable
773// =======================================================================
774Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
775 const GLchar* theName,
776 GLint theValue)
777{
778 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
779}
780
781// =======================================================================
782// function : SetUniform
783// purpose : Specifies the value of the integer uniform variable
784// =======================================================================
785Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
786 GLint theLocation,
787 GLint theValue)
788{
789 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
790 {
791 return Standard_False;
792 }
793
4e1523ef 794 theCtx->core20fwd->glUniform1i (theLocation, theValue);
30f0ad28 795 return Standard_True;
796}
797
25ef750e 798// =======================================================================
799// function : SetUniform
47e9c178 800// purpose :
25ef750e 801// =======================================================================
802Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
803 const GLchar* theName,
47e9c178 804 const OpenGl_Vec2u& theValue)
25ef750e 805{
806 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
807}
808
809// =======================================================================
810// function : SetUniform
47e9c178 811// purpose :
25ef750e 812// =======================================================================
813Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
814 GLint theLocation,
47e9c178 815 const OpenGl_Vec2u& theValue)
25ef750e 816{
47e9c178 817 if (theCtx->core32 == NULL || myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
25ef750e 818 {
819 return Standard_False;
820 }
821
822#if !defined(GL_ES_VERSION_2_0)
47e9c178 823 theCtx->core32->glUniform2uiv (theLocation, 1, theValue.GetData());
25ef750e 824 return Standard_True;
20aeeb7b 825#else
826 (void )theValue;
827 return Standard_False;
828#endif
25ef750e 829}
830
831// =======================================================================
832// function : SetUniform
47e9c178 833// purpose :
25ef750e 834// =======================================================================
835Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
836 const GLchar* theName,
837 const GLsizei theCount,
47e9c178 838 const OpenGl_Vec2u* theValue)
25ef750e 839{
840 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theCount, theValue);
841}
842
843// =======================================================================
844// function : SetUniform
47e9c178 845// purpose :
25ef750e 846// =======================================================================
847Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
848 GLint theLocation,
849 const GLsizei theCount,
47e9c178 850 const OpenGl_Vec2u* theValue)
25ef750e 851{
47e9c178 852 if (theCtx->core32 == NULL || myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
25ef750e 853 {
854 return Standard_False;
855 }
856
857#if !defined(GL_ES_VERSION_2_0)
47e9c178 858 theCtx->core32->glUniform2uiv (theLocation, theCount, theValue->GetData());
25ef750e 859 return Standard_True;
20aeeb7b 860#else
861 (void )theCount;
862 (void )theValue;
863 return Standard_False;
864#endif
25ef750e 865}
866
30f0ad28 867// =======================================================================
868// function : SetUniform
869// purpose : Specifies the value of the floating-point uniform variable
870// =======================================================================
871Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
872 const GLchar* theName,
873 GLfloat theValue)
874{
875 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
876}
877
878// =======================================================================
879// function : SetUniform
880// purpose : Specifies the value of the floating-point uniform variable
881// =======================================================================
882Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
883 GLint theLocation,
884 GLfloat theValue)
885{
886 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
887 {
888 return Standard_False;
889 }
890
4e1523ef 891 theCtx->core20fwd->glUniform1f (theLocation, theValue);
30f0ad28 892 return Standard_True;
893}
894
895// =======================================================================
896// function : SetUniform
897// purpose : Specifies the value of the integer uniform 2D vector
898// =======================================================================
899Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
900 const GLchar* theName,
901 const OpenGl_Vec2i& theValue)
902{
903 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
904}
905
906// =======================================================================
907// function : SetUniform
908// purpose : Specifies the value of the integer uniform 2D vector
909// =======================================================================
910Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
911 GLint theLocation,
912 const OpenGl_Vec2i& theValue)
913{
914 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
915 {
916 return Standard_False;
917 }
918
4e1523ef 919 theCtx->core20fwd->glUniform2iv (theLocation, 1, theValue);
30f0ad28 920 return Standard_True;
921}
922
923// =======================================================================
924// function : SetUniform
925// purpose : Specifies the value of the integer uniform 3D vector
926// =======================================================================
927Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
928 const GLchar* theName,
929 const OpenGl_Vec3i& theValue)
930{
931 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
932}
933
934// =======================================================================
935// function : SetUniform
936// purpose : Specifies the value of the integer uniform 3D vector
937// =======================================================================
938Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
939 GLint theLocation,
940 const OpenGl_Vec3i& theValue)
941{
942 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
943 {
944 return Standard_False;
945 }
946
4e1523ef 947 theCtx->core20fwd->glUniform3iv (theLocation, 1, theValue);
30f0ad28 948 return Standard_True;
949}
950
951// =======================================================================
952// function : SetUniform
953// purpose : Specifies the value of the integer uniform 4D vector
954// =======================================================================
955Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
956 const GLchar* theName,
957 const OpenGl_Vec4i& theValue)
958{
959 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
960}
961
962// =======================================================================
963// function : SetUniform
964// purpose : Specifies the value of the integer uniform 4D vector
965// =======================================================================
966Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
967 GLint theLocation,
968 const OpenGl_Vec4i& theValue)
969{
970 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
971 {
972 return Standard_False;
973 }
974
4e1523ef 975 theCtx->core20fwd->glUniform4iv (theLocation, 1, theValue);
30f0ad28 976 return Standard_True;
977}
978
979// =======================================================================
980// function : SetUniform
981// purpose : Specifies the value of the floating-point uniform 2D vector
982// =======================================================================
983Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
984 const GLchar* theName,
985 const OpenGl_Vec2& theValue)
986{
987 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
988}
989
990// =======================================================================
991// function : SetUniform
992// purpose : Specifies the value of the floating-point uniform 2D vector
993// =======================================================================
994Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
995 GLint theLocation,
996 const OpenGl_Vec2& theValue)
997{
998 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
999 {
1000 return Standard_False;
1001 }
1002
4e1523ef 1003 theCtx->core20fwd->glUniform2fv (theLocation, 1, theValue);
30f0ad28 1004 return Standard_True;
1005}
1006
1007// =======================================================================
1008// function : SetUniform
1009// purpose : Specifies the value of the floating-point uniform 3D vector
1010// =======================================================================
1011Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1012 const GLchar* theName,
1013 const OpenGl_Vec3& theValue)
1014{
1015 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
1016}
1017
1018// =======================================================================
1019// function : SetUniform
1020// purpose : Specifies the value of the floating-point uniform 3D vector
1021// =======================================================================
1022Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1023 GLint theLocation,
1024 const OpenGl_Vec3& theValue)
1025{
1026 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1027 {
1028 return Standard_False;
1029 }
1030
4e1523ef 1031 theCtx->core20fwd->glUniform3fv (theLocation, 1, theValue);
30f0ad28 1032 return Standard_True;
1033}
1034
1035// =======================================================================
1036// function : SetUniform
1037// purpose : Specifies the value of the floating-point uniform 4D vector
1038// =======================================================================
1039Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1040 const GLchar* theName,
1041 const OpenGl_Vec4& theValue)
1042{
1043 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
1044}
1045
1046// =======================================================================
1047// function : SetUniform
1048// purpose : Specifies the value of the floating-point uniform 4D vector
1049// =======================================================================
1050Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1051 GLint theLocation,
1052 const OpenGl_Vec4& theValue)
1053{
1054 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1055 {
1056 return Standard_False;
1057 }
1058
4e1523ef 1059 theCtx->core20fwd->glUniform4fv (theLocation, 1, theValue);
30f0ad28 1060 return Standard_True;
1061}
1062
25ef750e 1063// =======================================================================
1064// function : SetUniform
1065// purpose : Specifies the value of the floating-point uniform 4x4 matrix
1066// =======================================================================
1067Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1068 const GLchar* theName,
1069 const OpenGl_Mat4& theValue,
1070 GLboolean theTranspose)
1071{
1072 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
1073}
1074
1075// =======================================================================
1076// function : SetUniform
1077// purpose : Specifies the value of the floating-point uniform 4x4 matrix
1078// =======================================================================
1079Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1080 GLint theLocation,
1081 const OpenGl_Mat4& theValue,
1082 GLboolean theTranspose)
1083{
1084 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1085 {
1086 return Standard_False;
1087 }
1088
4e1523ef 1089 theCtx->core20fwd->glUniformMatrix4fv (theLocation, 1, GL_FALSE, theTranspose ? theValue.Transposed() : theValue);
25ef750e 1090 return Standard_True;
1091}
1092
30f0ad28 1093// =======================================================================
1094// function : SetUniform
1095// purpose : Specifies the value of the floating-point uniform 4x4 matrix
1096// =======================================================================
1097Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1098 const GLchar* theName,
1099 const OpenGl_Matrix& theValue,
1100 GLboolean theTranspose)
1101{
1102 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
1103}
1104
1105// =======================================================================
1106// function : SetUniform
1107// purpose : Specifies the value of the floating-point uniform 4x4 matrix
1108// =======================================================================
1109Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1110 GLint theLocation,
1111 const OpenGl_Matrix& theValue,
1112 GLboolean theTranspose)
1113{
c827ea3a 1114 return SetUniform (theCtx, theLocation, OpenGl_Mat4::Map (*theValue.mat), theTranspose);
30f0ad28 1115}
1116
4fe9ad57 1117// =======================================================================
1118// function : SetUniform
1119// purpose : Specifies the value of the float uniform array
1120// =======================================================================
1121Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1122 GLint theLocation,
1123 GLuint theCount,
1124 const Standard_ShortReal* theData)
1125{
1126 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1127 {
1128 return Standard_False;
1129 }
1130
4e1523ef 1131 theCtx->core20fwd->glUniform1fv (theLocation, theCount, theData);
4fe9ad57 1132 return Standard_True;
1133}
1134
1135// =======================================================================
1136// function : SetUniform
1137// purpose : Specifies the value of the float2 uniform array
1138// =======================================================================
1139Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1140 GLint theLocation,
1141 GLuint theCount,
1142 const OpenGl_Vec2* theData)
1143{
1144 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1145 {
1146 return Standard_False;
1147 }
1148
4e1523ef 1149 theCtx->core20fwd->glUniform2fv (theLocation, theCount, theData[0].GetData());
4fe9ad57 1150 return Standard_True;
1151}
1152
1153// =======================================================================
1154// function : SetUniform
1155// purpose : Specifies the value of the float3 uniform array
1156// =======================================================================
1157Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1158 GLint theLocation,
1159 GLuint theCount,
1160 const OpenGl_Vec3* theData)
1161{
1162 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1163 {
1164 return Standard_False;
1165 }
1166
4e1523ef 1167 theCtx->core20fwd->glUniform3fv (theLocation, theCount, theData[0].GetData());
4fe9ad57 1168 return Standard_True;
1169}
1170
1171// =======================================================================
1172// function : SetUniform
1173// purpose : Specifies the value of the float4 uniform array
1174// =======================================================================
1175Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1176 GLint theLocation,
1177 GLuint theCount,
1178 const OpenGl_Vec4* theData)
1179{
1180 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1181 {
1182 return Standard_False;
1183 }
1184
4e1523ef 1185 theCtx->core20fwd->glUniform4fv (theLocation, theCount, theData[0].GetData());
4fe9ad57 1186 return Standard_True;
1187}
1188
1189// =======================================================================
1190// function : SetUniform
1191// purpose : Specifies the value of the integer uniform array
1192// =======================================================================
1193Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1194 GLint theLocation,
1195 GLuint theCount,
1196 const Standard_Integer* theData)
1197{
1198 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1199 {
1200 return Standard_False;
1201 }
1202
4e1523ef 1203 theCtx->core20fwd->glUniform1iv (theLocation, theCount, theData);
4fe9ad57 1204 return Standard_True;
1205}
1206
1207// =======================================================================
1208// function : SetUniform
1209// purpose : Specifies the value of the int2 uniform array
1210// =======================================================================
1211Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1212 GLint theLocation,
1213 GLuint theCount,
1214 const OpenGl_Vec2i* theData)
1215{
1216 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1217 {
1218 return Standard_False;
1219 }
1220
4e1523ef 1221 theCtx->core20fwd->glUniform2iv (theLocation, theCount, theData[0].GetData());
4fe9ad57 1222 return Standard_True;
1223}
1224
1225// =======================================================================
1226// function : SetUniform
1227// purpose : Specifies the value of the int3 uniform array
1228// =======================================================================
1229Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1230 GLint theLocation,
1231 GLuint theCount,
1232 const OpenGl_Vec3i* theData)
1233{
1234 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1235 {
1236 return Standard_False;
1237 }
1238
4e1523ef 1239 theCtx->core20fwd->glUniform3iv (theLocation, theCount, theData[0].GetData());
4fe9ad57 1240 return Standard_True;
1241}
1242
1243// =======================================================================
1244// function : SetUniform
1245// purpose : Specifies the value of the int4 uniform array
1246// =======================================================================
1247Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
1248 GLint theLocation,
1249 GLuint theCount,
1250 const OpenGl_Vec4i* theData)
1251{
1252 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1253 {
1254 return Standard_False;
1255 }
1256
4e1523ef 1257 theCtx->core20fwd->glUniform4iv (theLocation, theCount, theData[0].GetData());
4fe9ad57 1258 return Standard_True;
1259}
1260
30f0ad28 1261// =======================================================================
1262// function : SetSampler
1263// purpose : Specifies the value of the sampler uniform variable
1264// =======================================================================
1265Standard_Boolean OpenGl_ShaderProgram::SetSampler (const Handle(OpenGl_Context)& theCtx,
1266 const GLchar* theName,
1267 const GLenum theTextureUnit)
1268{
1269 return SetSampler (theCtx, GetUniformLocation (theCtx, theName), theTextureUnit);
1270}
1271
1272// =======================================================================
1273// function : SetSampler
1274// purpose : Specifies the value of the sampler uniform variable
1275// =======================================================================
1276Standard_Boolean OpenGl_ShaderProgram::SetSampler (const Handle(OpenGl_Context)& theCtx,
1277 GLint theLocation,
1278 const GLenum theTextureUnit)
1279{
1280 if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
1281 {
1282 return Standard_False;
1283 }
1284
4e1523ef 1285 theCtx->core20fwd->glUniform1i (theLocation, theTextureUnit);
30f0ad28 1286 return Standard_True;
1287}
1288
1289// =======================================================================
1290// function : Create
1291// purpose : Creates new empty shader program of specified type
1292// =======================================================================
1293Standard_Boolean OpenGl_ShaderProgram::Create (const Handle(OpenGl_Context)& theCtx)
1294{
1295 if (myProgramID == NO_PROGRAM
4e1523ef 1296 && theCtx->core20fwd != NULL)
30f0ad28 1297 {
4e1523ef 1298 myProgramID = theCtx->core20fwd->glCreateProgram();
30f0ad28 1299 }
1300
1301 return myProgramID != NO_PROGRAM;
1302}
1303
1304// =======================================================================
1305// function : Release
1306// purpose : Destroys shader program
1307// =======================================================================
10b9c7df 1308void OpenGl_ShaderProgram::Release (OpenGl_Context* theCtx)
30f0ad28 1309{
1310 if (myProgramID == NO_PROGRAM)
1311 {
1312 return;
1313 }
1314
1315 Standard_ASSERT_RETURN (theCtx != NULL,
1316 "OpenGl_ShaderProgram destroyed without GL context! Possible GPU memory leakage...",);
1317
1318 for (OpenGl_ShaderList::Iterator anIter (myShaderObjects); anIter.More(); anIter.Next())
1319 {
fc73a202 1320 if (!anIter.Value().IsNull())
1321 {
1322 anIter.ChangeValue()->Release (theCtx);
1323 anIter.ChangeValue().Nullify();
1324 }
30f0ad28 1325 }
1326
4e1523ef 1327 if (theCtx->core20fwd != NULL
ec2eeb2d 1328 && theCtx->IsValid())
30f0ad28 1329 {
4e1523ef 1330 theCtx->core20fwd->glDeleteProgram (myProgramID);
30f0ad28 1331 }
1332
1333 myProgramID = NO_PROGRAM;
1334}