3dphotoshoot

diff src/shader.cc @ 22:d7fe157c402d

fonts
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 13 Jun 2015 05:32:07 +0300
parents 4ca4e3c5a754
children
line diff
     1.1 --- a/src/shader.cc	Thu Jun 11 04:56:33 2015 +0300
     1.2 +++ b/src/shader.cc	Sat Jun 13 05:32:07 2015 +0300
     1.3 @@ -187,6 +187,122 @@
     1.4  	return true;
     1.5  }
     1.6  
     1.7 +void SdrProg::set_uniform(const char *name, int count, const int *val) const
     1.8 +{
     1.9 +	if(!bind()) return;
    1.10 +
    1.11 +	int loc = glGetUniformLocation(prog, name);
    1.12 +	if(loc == -1) return;
    1.13 +
    1.14 +	switch(count) {
    1.15 +	case 1:
    1.16 +		glUniform1iv(loc, 1, val);
    1.17 +		break;
    1.18 +	case 2:
    1.19 +		glUniform2iv(loc, 1, val);
    1.20 +		break;
    1.21 +	case 3:
    1.22 +		glUniform3iv(loc, 1, val);
    1.23 +	case 4:
    1.24 +		glUniform4iv(loc, 1, val);
    1.25 +	default:
    1.26 +		break;
    1.27 +	}
    1.28 +}
    1.29 +
    1.30 +void SdrProg::set_uniform(const char *name, int count, const float *val) const
    1.31 +{
    1.32 +	if(!bind()) return;
    1.33 +
    1.34 +	int loc = glGetUniformLocation(prog, name);
    1.35 +	if(loc == -1) return;
    1.36 +
    1.37 +	switch(count) {
    1.38 +	case 1:
    1.39 +		glUniform1fv(loc, 1, val);
    1.40 +		break;
    1.41 +	case 2:
    1.42 +		glUniform2fv(loc, 1, val);
    1.43 +		break;
    1.44 +	case 3:
    1.45 +		glUniform3fv(loc, 1, val);
    1.46 +	case 4:
    1.47 +		glUniform4fv(loc, 1, val);
    1.48 +	default:
    1.49 +		break;
    1.50 +	}
    1.51 +}
    1.52 +
    1.53 +void SdrProg::set_uniform(const char *name, const Vector4 &v) const
    1.54 +{
    1.55 +	set_uniform(name, 4, &v.x);
    1.56 +}
    1.57 +
    1.58 +
    1.59 +void SdrProg::set_uniform1i(const char *name, int x) const
    1.60 +{
    1.61 +	set_uniform(name, 1, &x);
    1.62 +}
    1.63 +
    1.64 +void SdrProg::set_uniform2i(const char *name, int x, int y) const
    1.65 +{
    1.66 +	int v[] = {x, y};
    1.67 +	set_uniform(name, 2, v);
    1.68 +}
    1.69 +
    1.70 +void SdrProg::set_uniform3i(const char *name, int x, int y, int z) const
    1.71 +{
    1.72 +	int v[] = {x, y, z};
    1.73 +	set_uniform(name, 3, v);
    1.74 +}
    1.75 +
    1.76 +void SdrProg::set_uniform4i(const char *name, int x, int y, int z, int w) const
    1.77 +{
    1.78 +	int v[] = {x, y, z, w};
    1.79 +	set_uniform(name, 4, v);
    1.80 +}
    1.81 +
    1.82 +void SdrProg::set_uniform1f(const char *name, float x) const
    1.83 +{
    1.84 +	set_uniform(name, 1, &x);
    1.85 +}
    1.86 +
    1.87 +void SdrProg::set_uniform2f(const char *name, float x, float y) const
    1.88 +{
    1.89 +	float v[] = {x, y};
    1.90 +	set_uniform(name, 2, v);
    1.91 +}
    1.92 +
    1.93 +void SdrProg::set_uniform3f(const char *name, float x, float y, float z) const
    1.94 +{
    1.95 +	float v[] = {x, y, z};
    1.96 +	set_uniform(name, 3, v);
    1.97 +}
    1.98 +
    1.99 +void SdrProg::set_uniform4f(const char *name, float x, float y, float z, float w) const
   1.100 +{
   1.101 +	float v[] = {x, y, z, w};
   1.102 +	set_uniform(name, 4, v);
   1.103 +}
   1.104 +
   1.105 +void SdrProg::set_uniform_matrix(const char *name, const float *m) const
   1.106 +{
   1.107 +	if(!bind()) return;
   1.108 +
   1.109 +	int loc = glGetUniformLocation(prog, name);
   1.110 +	if(loc == -1) return;
   1.111 +
   1.112 +	glUniformMatrix4fv(loc, 1, 0, m);
   1.113 +}
   1.114 +
   1.115 +void SdrProg::set_uniform_matrix(const char *name, const Matrix4x4 &m) const
   1.116 +{
   1.117 +	Matrix4x4 tmp = m.transposed();
   1.118 +	set_uniform_matrix(name, tmp[0]);
   1.119 +}
   1.120 +
   1.121 +
   1.122 +
   1.123  unsigned int get_shader(const char *name, unsigned int type)
   1.124  {
   1.125  	std::map<std::string, unsigned int>::const_iterator it = sdrdb.find(name);