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