1 // Created on: 2014-10-08
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_Sampler.hxx>
17 #include <OpenGl_GlCore33.hxx>
18 #include <Standard_Assert.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Sampler,OpenGl_Resource)
23 // =======================================================================
24 // function : OpenGl_Sampler
26 // =======================================================================
27 OpenGl_Sampler::OpenGl_Sampler()
28 : mySamplerID (NO_SAMPLER)
33 // =======================================================================
34 // function : ~OpenGl_Sampler
36 // =======================================================================
37 OpenGl_Sampler::~OpenGl_Sampler()
42 // =======================================================================
45 // =======================================================================
46 void OpenGl_Sampler::Release (OpenGl_Context* theContext)
50 // application can not handle this case by exception - this is bug in code
51 Standard_ASSERT_RETURN (theContext != NULL,
52 "OpenGl_Sampler destroyed without GL context! Possible GPU memory leakage...",);
54 if (theContext->IsValid())
56 #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0)
57 theContext->core33->glDeleteSamplers (1, &mySamplerID);
61 mySamplerID = NO_SAMPLER;
65 // =======================================================================
67 // purpose : Initializes sampler object
68 // =======================================================================
69 Standard_Boolean OpenGl_Sampler::Init (OpenGl_Context& theContext)
71 if (theContext.core33 == NULL)
73 return Standard_False;
78 Release (&theContext);
81 #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0)
82 theContext.core33->glGenSamplers (1, &mySamplerID);
85 return Standard_False;
89 // =======================================================================
91 // purpose : Binds sampler object to the given texture unit
92 // =======================================================================
93 void OpenGl_Sampler::Bind (OpenGl_Context& theContext,
98 #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0)
99 theContext.core33->glBindSampler (theUnit, mySamplerID);
104 // =======================================================================
106 // purpose : Unbinds sampler object from the given texture unit
107 // =======================================================================
108 void OpenGl_Sampler::Unbind (OpenGl_Context& theContext,
109 const GLuint theUnit)
111 if (isValidSampler())
113 #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0)
114 theContext.core33->glBindSampler (theUnit, NO_SAMPLER);
119 // =======================================================================
120 // function : SetParameter
121 // purpose : Sets sampler parameters
122 // =======================================================================
123 void OpenGl_Sampler::SetParameter (OpenGl_Context& theContext,
124 const GLenum theParam,
125 const GLint theValue)
127 if (isValidSampler())
129 #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0)
130 theContext.core33->glSamplerParameteri (mySamplerID, theParam, theValue);