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 "SoGLARBShaderParameter.h"
34 #include "SoGLARBShaderObject.h"
35 #include "coindefs.h"
36 
37 #include <cstring>
38 
39 #include <Inventor/errors/SoDebugError.h>
40 
41 // *************************************************************************
42 
SoGLARBShaderParameter(void)43 SoGLARBShaderParameter::SoGLARBShaderParameter(void)
44 {
45   this->target = 0;
46   this->identifier = 0;
47 }
48 
~SoGLARBShaderParameter()49 SoGLARBShaderParameter::~SoGLARBShaderParameter()
50 {
51 }
52 
53 SoShader::Type
shaderType(void) const54 SoGLARBShaderParameter::shaderType(void) const
55 {
56   return SoShader::ARB_SHADER;
57 }
58 
59 void
set1f(const SoGLShaderObject * shader,const float value,const char *,const int idx)60 SoGLARBShaderParameter::set1f(const SoGLShaderObject * shader,
61                               const float value, const char*, const int idx)
62 {
63   if (this->isValid(shader, idx))
64     cc_glglue_glProgramLocalParameter4f(shader->GLContext(),
65                                         this->target, this->identifier,
66                                         value, value, value, value);
67 }
68 
69 void
set2f(const SoGLShaderObject * shader,const float * value,const char *,const int idx)70 SoGLARBShaderParameter::set2f(const SoGLShaderObject * shader,
71                               const float * value, const char*, const int idx)
72 {
73   if (this->isValid(shader, idx))
74     cc_glglue_glProgramLocalParameter4f(shader->GLContext(),
75                                         this->target, this->identifier,
76                                         value[0], value[1], value[0], value[0]);
77 }
78 
79 void
set3f(const SoGLShaderObject * shader,const float * value,const char *,const int idx)80 SoGLARBShaderParameter::set3f(const SoGLShaderObject * shader,
81                               const float * value, const char*, const int idx)
82 {
83   if (this->isValid(shader, idx))
84     cc_glglue_glProgramLocalParameter4f(shader->GLContext(),
85                                         this->target, this->identifier,
86                                         value[0], value[1], value[2], value[0]);
87 }
88 
89 void
set4f(const SoGLShaderObject * shader,const float * value,const char *,const int idx)90 SoGLARBShaderParameter::set4f(const SoGLShaderObject * shader,
91                               const float * value, const char*, const int idx)
92 {
93   if (this->isValid(shader, idx))
94     cc_glglue_glProgramLocalParameter4f(shader->GLContext(),
95                                         this->target, this->identifier,
96                                         value[0], value[1], value[2], value[3]);
97 }
98 
99 void
set1fv(const SoGLShaderObject *,const int,const float *,const char *,const int)100 SoGLARBShaderParameter::set1fv(const SoGLShaderObject*, const int,
101                                const float*, const char*, const int)
102 {
103   // FIXME: not implemented yet 20050127 martin
104 }
105 
106 void
set2fv(const SoGLShaderObject *,const int,const float *,const char *,const int)107 SoGLARBShaderParameter::set2fv(const SoGLShaderObject*, const int,
108                                const float*, const char*, const int)
109 {
110   // FIXME: not implemented yet 20050127 martin
111 }
112 
113 void
set3fv(const SoGLShaderObject *,const int,const float *,const char *,const int)114 SoGLARBShaderParameter::set3fv(const SoGLShaderObject*, const int,
115                                const float*, const char*, const int)
116 {
117   // FIXME: not implemented yet 20050127 martin
118 }
119 
120 void
set4fv(const SoGLShaderObject *,const int,const float *,const char *,const int)121 SoGLARBShaderParameter::set4fv(const SoGLShaderObject*, const int,
122                                const float*, const char*, const int)
123 {
124   // FIXME: not implemented yet 20050127 martin
125 }
126 
127 void
setMatrix(const SoGLShaderObject *,const float *,const char *,const int)128 SoGLARBShaderParameter::setMatrix(const SoGLShaderObject *,
129                                   const float *, const char *, const int)
130 {
131   // FIXME not implemented yet -- 20050128 martin
132 }
133 
134 
135 void
setMatrixArray(const SoGLShaderObject *,const int,const float *,const char *,const int)136 SoGLARBShaderParameter::setMatrixArray(const SoGLShaderObject *, const int,
137                                        const float *, const char *, const int)
138 {
139   // FIXME not implemented yet -- 20050128 martin
140 }
141 
142 void
set1i(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int32_t COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)143 SoGLARBShaderParameter::set1i(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
144                               const int32_t COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
145                               const int)
146 {
147   // FIXME not implemented yet -- 20050222 martin
148 }
149 
150 void
set2i(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)151 SoGLARBShaderParameter::set2i(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
152                               const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
153                               const int)
154 {
155   // FIXME not implemented yet -- 20050222 martin
156 }
157 
158 void
set3i(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)159 SoGLARBShaderParameter::set3i(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
160                               const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
161                               const int)
162 {
163   // FIXME not implemented yet -- 20050222 martin
164 }
165 
166 void
set4i(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)167 SoGLARBShaderParameter::set4i(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
168                               const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
169                               const int)
170 {
171   // FIXME not implemented yet -- 20050222 martin
172 }
173 
174 void
set1iv(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int COIN_UNUSED_ARG (num),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)175 SoGLARBShaderParameter::set1iv(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
176                                const int COIN_UNUSED_ARG(num),
177                                const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
178                                const int)
179 {
180   // probably not supported. pederb, 20070530
181 }
182 
183 void
set2iv(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int COIN_UNUSED_ARG (num),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)184 SoGLARBShaderParameter::set2iv(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
185                                const int COIN_UNUSED_ARG(num),
186                                const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
187                                const int)
188 {
189   // probably not supported. pederb, 20070530
190 }
191 
192 void
set3iv(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int COIN_UNUSED_ARG (num),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)193 SoGLARBShaderParameter::set3iv(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
194                                const int COIN_UNUSED_ARG(num),
195                                const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
196                                const int)
197 {
198   // probably not supported. pederb, 20070530
199 }
200 
201 void
set4iv(const SoGLShaderObject * COIN_UNUSED_ARG (shader),const int COIN_UNUSED_ARG (num),const int32_t * COIN_UNUSED_ARG (value),const char * COIN_UNUSED_ARG (name),const int)202 SoGLARBShaderParameter::set4iv(const SoGLShaderObject * COIN_UNUSED_ARG(shader),
203                                const int COIN_UNUSED_ARG(num),
204                                const int32_t * COIN_UNUSED_ARG(value), const char * COIN_UNUSED_ARG(name),
205                                const int)
206 {
207   // probably not supported. pederb, 20070530
208 }
209 
210 //FIXME: no type checking implemented 20050128 martin
211 SbBool
isValid(const SoGLShaderObject * shader,const int idx)212 SoGLARBShaderParameter::isValid(const SoGLShaderObject * shader, const int idx)
213 {
214   assert(shader);
215   assert(shader->shaderType() == SoShader::ARB_SHADER);
216 
217   this->target     = ((SoGLARBShaderObject*)shader)->target;
218   this->identifier = idx;
219   return TRUE;
220 }
221