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 | |
92efcf78 |
21 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Sampler,OpenGl_Resource) |
22 | |
25ef750e |
23 | // ======================================================================= |
24 | // function : OpenGl_Sampler |
25 | // purpose : |
26 | // ======================================================================= |
27 | OpenGl_Sampler::OpenGl_Sampler() |
28 | : mySamplerID (NO_SAMPLER) |
29 | { |
30 | // |
31 | } |
32 | |
33 | // ======================================================================= |
34 | // function : ~OpenGl_Sampler |
35 | // purpose : |
36 | // ======================================================================= |
37 | OpenGl_Sampler::~OpenGl_Sampler() |
38 | { |
39 | Release (NULL); |
40 | } |
41 | |
42 | // ======================================================================= |
43 | // function : Release |
44 | // purpose : |
45 | // ======================================================================= |
46 | void OpenGl_Sampler::Release (OpenGl_Context* theContext) |
47 | { |
48 | if (isValidSampler()) |
49 | { |
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...",); |
53 | |
54 | if (theContext->IsValid()) |
55 | { |
56 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
57 | theContext->core33->glDeleteSamplers (1, &mySamplerID); |
58 | #endif |
59 | } |
60 | |
61 | mySamplerID = NO_SAMPLER; |
62 | } |
63 | } |
64 | |
65 | // ======================================================================= |
66 | // function : Init |
67 | // purpose : Initializes sampler object |
68 | // ======================================================================= |
69 | Standard_Boolean OpenGl_Sampler::Init (OpenGl_Context& theContext) |
70 | { |
71 | if (theContext.core33 == NULL) |
72 | { |
73 | return Standard_False; |
74 | } |
75 | |
76 | if (isValidSampler()) |
77 | { |
78 | Release (&theContext); |
79 | } |
80 | |
81 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
82 | theContext.core33->glGenSamplers (1, &mySamplerID); |
83 | return Standard_True; |
84 | #else |
85 | return Standard_False; |
86 | #endif |
87 | } |
88 | |
89 | // ======================================================================= |
90 | // function : Bind |
91 | // purpose : Binds sampler object to the given texture unit |
92 | // ======================================================================= |
93 | void OpenGl_Sampler::Bind (OpenGl_Context& theContext, |
94 | const GLuint theUnit) |
95 | { |
96 | if (isValidSampler()) |
97 | { |
98 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
99 | theContext.core33->glBindSampler (theUnit, mySamplerID); |
20aeeb7b |
100 | #else |
101 | (void )theContext; |
102 | (void )theUnit; |
25ef750e |
103 | #endif |
104 | } |
105 | } |
106 | |
107 | // ======================================================================= |
108 | // function : Unbind |
109 | // purpose : Unbinds sampler object from the given texture unit |
110 | // ======================================================================= |
111 | void OpenGl_Sampler::Unbind (OpenGl_Context& theContext, |
112 | const GLuint theUnit) |
113 | { |
114 | if (isValidSampler()) |
115 | { |
116 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
117 | theContext.core33->glBindSampler (theUnit, NO_SAMPLER); |
20aeeb7b |
118 | #else |
119 | (void )theContext; |
120 | (void )theUnit; |
25ef750e |
121 | #endif |
122 | } |
123 | } |
124 | |
125 | // ======================================================================= |
126 | // function : SetParameter |
127 | // purpose : Sets sampler parameters |
128 | // ======================================================================= |
129 | void OpenGl_Sampler::SetParameter (OpenGl_Context& theContext, |
130 | const GLenum theParam, |
131 | const GLint theValue) |
132 | { |
133 | if (isValidSampler()) |
134 | { |
135 | #if !defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) |
136 | theContext.core33->glSamplerParameteri (mySamplerID, theParam, theValue); |
20aeeb7b |
137 | #else |
138 | (void )theContext; |
139 | (void )theParam; |
140 | (void )theValue; |
25ef750e |
141 | #endif |
142 | } |
143 | } |