1 /*
2  Copyright (c) 2013 yvt
3 
4  This file is part of OpenSpades.
5 
6  OpenSpades is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OpenSpades is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OpenSpades.  If not, see <http://www.gnu.org/licenses/>.
18 
19  */
20 
21 #include <cstdio>
22 
23 #include "GLProgramUniform.h"
24 #include <Core/Exception.h>
25 #include <Core/Debug.h>
26 
27 namespace spades {
28 	namespace draw {
GLProgramUniform(const std::string & n)29 		GLProgramUniform::GLProgramUniform(const std::string& n):
30 		name(n){
31 			last = NULL;
32 		}
33 
SetProgram(spades::draw::GLProgram * p)34 		void GLProgramUniform::SetProgram(spades::draw::GLProgram *p){
35 			SPADES_MARK_FUNCTION_DEBUG();
36 
37 			if(p == NULL) {
38 				SPInvalidArgument("prog");
39 			}
40 			if(last != p){
41 				last = p;
42 				last->Use();
43 				loc = p->GetDevice()->GetUniformLocation
44 				(p->GetHandle(), name.c_str())
45 				 ;
46 				if(loc == -1){
47 					fprintf(stderr,"WARNING: uniform '%s' not found\n",
48 							name.c_str());
49 				}
50 			}
51 		}
52 
SetValue(IGLDevice::Float v)53 		void GLProgramUniform::SetValue(IGLDevice::Float v){
54 			SPADES_MARK_FUNCTION_DEBUG();
55 			last->GetDevice()->Uniform(loc, v);
56 		}
SetValue(IGLDevice::Float x,IGLDevice::Float y)57 		void GLProgramUniform::SetValue(IGLDevice::Float x,
58 										IGLDevice::Float y){
59 			SPADES_MARK_FUNCTION_DEBUG();
60 			last->GetDevice()->Uniform(loc, x, y);
61 		}
SetValue(IGLDevice::Float x,IGLDevice::Float y,IGLDevice::Float z)62 		void GLProgramUniform::SetValue(IGLDevice::Float x,
63 										IGLDevice::Float y,
64 										IGLDevice::Float z){
65 			SPADES_MARK_FUNCTION_DEBUG();
66 			last->GetDevice()->Uniform(loc, x, y, z);
67 		}
SetValue(IGLDevice::Float x,IGLDevice::Float y,IGLDevice::Float z,IGLDevice::Float w)68 		void GLProgramUniform::SetValue(IGLDevice::Float x,
69 										IGLDevice::Float y,
70 										IGLDevice::Float z,
71 										IGLDevice::Float w){
72 			SPADES_MARK_FUNCTION_DEBUG();
73 			last->GetDevice()->Uniform(loc, x, y, z, w);
74 		}
75 
SetValue(IGLDevice::Integer x)76 		void GLProgramUniform::SetValue(IGLDevice::Integer x){
77 			SPADES_MARK_FUNCTION_DEBUG();
78 			last->GetDevice()->Uniform(loc, x);
79 		}
SetValue(IGLDevice::Integer x,IGLDevice::Integer y)80 		void GLProgramUniform::SetValue(IGLDevice::Integer x,
81 										IGLDevice::Integer y){
82 			SPADES_MARK_FUNCTION_DEBUG();
83 			last->GetDevice()->Uniform(loc, x, y);
84 		}
SetValue(IGLDevice::Integer x,IGLDevice::Integer y,IGLDevice::Integer z)85 		void GLProgramUniform::SetValue(IGLDevice::Integer x,
86 										IGLDevice::Integer y,
87 										IGLDevice::Integer z){
88 			SPADES_MARK_FUNCTION_DEBUG();
89 			last->GetDevice()->Uniform(loc, x, y, z);
90 		}
SetValue(IGLDevice::Integer x,IGLDevice::Integer y,IGLDevice::Integer z,IGLDevice::Integer w)91 		void GLProgramUniform::SetValue(IGLDevice::Integer x,
92 										IGLDevice::Integer y,
93 										IGLDevice::Integer z,
94 										IGLDevice::Integer w){
95 			SPADES_MARK_FUNCTION_DEBUG();
96 			last->GetDevice()->Uniform(loc, x, y, z, w);
97 		}
SetValue(const spades::Matrix4 & m,bool transpose)98 		void GLProgramUniform::SetValue(const spades::Matrix4 &m,
99 										bool transpose) {
100 			SPADES_MARK_FUNCTION_DEBUG();
101 			last->GetDevice()->Uniform(loc, transpose, m);
102 		}
103 	}
104 }
105