1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 #include "SoGLShaderObject.h"
34 #include "coindefs.h"
35 
36 #include <cassert>
37 
38 #include "SoGLARBShaderObject.h"
39 #include "SoGLCgShaderObject.h"
40 #include "SoGLSLShaderObject.h"
41 
42 
43 static uint32_t shaderid = 0;
44 
45 // *************************************************************************
46 
SoGLShaderObject(const uint32_t cachecontext)47 SoGLShaderObject::SoGLShaderObject(const uint32_t cachecontext)
48 {
49   this->isActiveFlag = TRUE;
50   this->shadertype = VERTEX;
51   this->paramsdirty = TRUE;
52   this->glctx = cc_glglue_instance(cachecontext);
53   this->cachecontext = cachecontext;
54   this->id = ++shaderid;
55 }
56 
57 const cc_glglue *
GLContext(void) const58 SoGLShaderObject::GLContext(void) const
59 {
60   return this->glctx;
61 }
62 
63 uint32_t
getCacheContext(void) const64 SoGLShaderObject::getCacheContext(void) const
65 {
66   return this->cachecontext;
67 }
68 
69 void
setShaderType(const ShaderType type)70 SoGLShaderObject::setShaderType(const ShaderType type)
71 {
72   if (this->shadertype != type) {
73     this->unload();
74     this->shadertype = type;
75   }
76 }
77 
78 SoGLShaderObject::ShaderType
getShaderType(void) const79 SoGLShaderObject::getShaderType(void) const
80 {
81   return this->shadertype;
82 }
83 
setIsActive(SbBool flag)84 void SoGLShaderObject::setIsActive(SbBool flag)
85 {
86   this->isActiveFlag = flag;
87 }
88 
89 SbBool
isActive(void) const90 SoGLShaderObject::isActive(void) const
91 {
92   return (!this->isLoaded()) ? FALSE : this->isActiveFlag;
93 }
94 
95 void
setParametersDirty(SbBool flag)96 SoGLShaderObject::setParametersDirty(SbBool flag)
97 {
98   this->paramsdirty = flag;
99 }
100 
101 SbBool
getParametersDirty(void) const102 SoGLShaderObject::getParametersDirty(void) const
103 {
104   return this->paramsdirty;
105 }
106 
107 void
updateCoinParameter(SoState * COIN_UNUSED_ARG (state),const SbName & COIN_UNUSED_ARG (name),SoShaderParameter * COIN_UNUSED_ARG (param),const int COIN_UNUSED_ARG (val))108 SoGLShaderObject::updateCoinParameter(SoState * COIN_UNUSED_ARG(state), const SbName & COIN_UNUSED_ARG(name), SoShaderParameter * COIN_UNUSED_ARG(param), const int COIN_UNUSED_ARG(val))
109 {
110 }
111 
112 uint32_t
getShaderObjectId(void) const113 SoGLShaderObject::getShaderObjectId(void) const
114 {
115   return this->id;
116 }
117