25ef750e |
1 | // Created on: 2014-10-08 |
2 | // Created by: Denis BOGOLEPOV |
3 | // Copyright (c) 2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <OpenGl_Sampler.hxx> |
17 | #include <OpenGl_GlCore33.hxx> |
18 | #include <Standard_Assert.hxx> |
19 | |
25ef750e |
20 | |
21 | // ======================================================================= |
22 | // function : OpenGl_Sampler |
23 | // purpose : |
24 | // ======================================================================= |
25 | OpenGl_Sampler::OpenGl_Sampler() |
26 | : mySamplerID (NO_SAMPLER) |
27 | { |
28 | // |
29 | } |
30 | |
31 | // ======================================================================= |
32 | // function : ~OpenGl_Sampler |
33 | // purpose : |
34 | // ======================================================================= |
35 | OpenGl_Sampler::~OpenGl_Sampler() |
36 | { |
37 | Release (NULL); |
38 | } |
39 | |
40 | // ======================================================================= |
41 | // function : Release |
42 | // purpose : |
43 | // ======================================================================= |
44 | void OpenGl_Sampler::Release (OpenGl_Context* theContext) |
45 | { |
46 | if (isValidSampler()) |
47 | { |
48 | // application can not handle this case by exception - this is bug in code |
49 | Standard_ASSERT_RETURN (theContext != NULL, |
50 | "OpenGl_Sampler destroyed without GL context! Possible GPU memory leakage...",); |
51 | |
52 | if (theContext->IsValid()) |
53 | { |
54 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
55 | theContext->core33->glDeleteSamplers (1, &mySamplerID); |
56 | #endif |
57 | } |
58 | |
59 | mySamplerID = NO_SAMPLER; |
60 | } |
61 | } |
62 | |
63 | // ======================================================================= |
64 | // function : Init |
65 | // purpose : Initializes sampler object |
66 | // ======================================================================= |
67 | Standard_Boolean OpenGl_Sampler::Init (OpenGl_Context& theContext) |
68 | { |
69 | if (theContext.core33 == NULL) |
70 | { |
71 | return Standard_False; |
72 | } |
73 | |
74 | if (isValidSampler()) |
75 | { |
76 | Release (&theContext); |
77 | } |
78 | |
79 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
80 | theContext.core33->glGenSamplers (1, &mySamplerID); |
81 | return Standard_True; |
82 | #else |
83 | return Standard_False; |
84 | #endif |
85 | } |
86 | |
87 | // ======================================================================= |
88 | // function : Bind |
89 | // purpose : Binds sampler object to the given texture unit |
90 | // ======================================================================= |
91 | void OpenGl_Sampler::Bind (OpenGl_Context& theContext, |
92 | const GLuint theUnit) |
93 | { |
94 | if (isValidSampler()) |
95 | { |
96 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
97 | theContext.core33->glBindSampler (theUnit, mySamplerID); |
98 | #endif |
99 | } |
100 | } |
101 | |
102 | // ======================================================================= |
103 | // function : Unbind |
104 | // purpose : Unbinds sampler object from the given texture unit |
105 | // ======================================================================= |
106 | void OpenGl_Sampler::Unbind (OpenGl_Context& theContext, |
107 | const GLuint theUnit) |
108 | { |
109 | if (isValidSampler()) |
110 | { |
111 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
112 | theContext.core33->glBindSampler (theUnit, NO_SAMPLER); |
113 | #endif |
114 | } |
115 | } |
116 | |
117 | // ======================================================================= |
118 | // function : SetParameter |
119 | // purpose : Sets sampler parameters |
120 | // ======================================================================= |
121 | void OpenGl_Sampler::SetParameter (OpenGl_Context& theContext, |
122 | const GLenum theParam, |
123 | const GLint theValue) |
124 | { |
125 | if (isValidSampler()) |
126 | { |
127 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
128 | theContext.core33->glSamplerParameteri (mySamplerID, theParam, theValue); |
129 | #endif |
130 | } |
131 | } |