修正Shader/GLSL类的一些设计错误

This commit is contained in:
hyzboy 2019-01-16 17:51:06 +08:00
parent 269615b206
commit 7f68b4b420
3 changed files with 68 additions and 55 deletions

View File

@ -108,24 +108,24 @@ namespace hgl
bool SetUniform3ui(int,unsigned int,unsigned int,unsigned int);
bool SetUniform4ui(int,unsigned int,unsigned int,unsigned int,unsigned int);
bool SetUniform1fv(int,const float *);
bool SetUniform2fv(int,const float *);
bool SetUniform3fv(int,const float *);
bool SetUniform4fv(int,const float *);
bool SetUniform1fv(int,int count,const float *);
bool SetUniform2fv(int,int count,const float *);
bool SetUniform3fv(int,int count,const float *);
bool SetUniform4fv(int,int count,const float *);
bool SetUniform2fv(int index,const Vector2f &v){return SetUniform2fv(index,(const float *)&v);}
bool SetUniform3fv(int index,const Vector3f &v){return SetUniform3fv(index,(const float *)&v);}
bool SetUniform4fv(int index,const Vector4f &v){return SetUniform4fv(index,(const float *)&v);}
bool SetUniform2fv(int index,const Vector2f &v){return SetUniform2fv(index,1,(const float *)&v);}
bool SetUniform3fv(int index,const Vector3f &v){return SetUniform3fv(index,1,(const float *)&v);}
bool SetUniform4fv(int index,const Vector4f &v){return SetUniform4fv(index,1,(const float *)&v);}
bool SetUniform1iv(int,const int *);
bool SetUniform2iv(int,const int *);
bool SetUniform3iv(int,const int *);
bool SetUniform4iv(int,const int *);
bool SetUniform1iv(int,int count,const int *);
bool SetUniform2iv(int,int count,const int *);
bool SetUniform3iv(int,int count,const int *);
bool SetUniform4iv(int,int count,const int *);
bool SetUniform1uiv(int,const unsigned int *);
bool SetUniform2uiv(int,const unsigned int *);
bool SetUniform3uiv(int,const unsigned int *);
bool SetUniform4uiv(int,const unsigned int *);
bool SetUniform1uiv(int,int count,const unsigned int *);
bool SetUniform2uiv(int,int count,const unsigned int *);
bool SetUniform3uiv(int,int count,const unsigned int *);
bool SetUniform4uiv(int,int count,const unsigned int *);
bool SetUniformMatrix2fv(int,const float *);
bool SetUniformMatrix3fv(int,const float *);
@ -155,24 +155,24 @@ namespace hgl
bool SetUniform3ui(const char *,unsigned int,unsigned int,unsigned int);
bool SetUniform4ui(const char *,unsigned int,unsigned int,unsigned int,unsigned int);
bool SetUniform1fv(const char *,const float *);
bool SetUniform2fv(const char *,const float *);
bool SetUniform3fv(const char *,const float *);
bool SetUniform4fv(const char *,const float *);
bool SetUniform1fv(const char *,int count,const float *);
bool SetUniform2fv(const char *,int count,const float *);
bool SetUniform3fv(const char *,int count,const float *);
bool SetUniform4fv(const char *,int count,const float *);
bool SetUniform2fv(const char *name,const Vector2f &v){return SetUniform2fv(name,(const float *)&v);}
bool SetUniform3fv(const char *name,const Vector3f &v){return SetUniform3fv(name,(const float *)&v);}
bool SetUniform4fv(const char *name,const Vector4f &v){return SetUniform4fv(name,(const float *)&v);}
bool SetUniform2fv(const char *name,const Vector2f &v){return SetUniform2fv(name,1,(const float *)&v);}
bool SetUniform3fv(const char *name,const Vector3f &v){return SetUniform3fv(name,1,(const float *)&v);}
bool SetUniform4fv(const char *name,const Vector4f &v){return SetUniform4fv(name,1,(const float *)&v);}
bool SetUniform1iv(const char *,const int *);
bool SetUniform2iv(const char *,const int *);
bool SetUniform3iv(const char *,const int *);
bool SetUniform4iv(const char *,const int *);
bool SetUniform1iv(const char *,int count,const int *);
bool SetUniform2iv(const char *,int count,const int *);
bool SetUniform3iv(const char *,int count,const int *);
bool SetUniform4iv(const char *,int count,const int *);
bool SetUniform1uiv(const char *,const unsigned int *);
bool SetUniform2uiv(const char *,const unsigned int *);
bool SetUniform3uiv(const char *,const unsigned int *);
bool SetUniform4uiv(const char *,const unsigned int *);
bool SetUniform1uiv(const char *,int count,const unsigned int *);
bool SetUniform2uiv(const char *,int count,const unsigned int *);
bool SetUniform3uiv(const char *,int count,const unsigned int *);
bool SetUniform4uiv(const char *,int count,const unsigned int *);
bool SetUniformMatrix2fv(const char *,const float *);
bool SetUniformMatrix3fv(const char *,const float *);

View File

@ -271,13 +271,14 @@ namespace hgl
glProgramUniform4##func(program,location,v0,v1,v2,v3); \
return(true); \
}
HGL_GLSL_SetUniform1234(f,float);
HGL_GLSL_SetUniform1234(i,int);
HGL_GLSL_SetUniform1234(ui,unsigned int);
#undef HGL_GLSL_SetUniform1234
#define HGL_GLSL_SetUniformPointer(func,type) bool Shader::SetUniform##func(int location,const type *value) \
#define HGL_GLSL_SetUniformPointer(func,type) bool Shader::SetUniform##func(int location,int count,const type *value) \
{ \
if(!program) \
{ \
@ -297,7 +298,7 @@ namespace hgl
return(false); \
} \
\
glProgramUniform##func(program,location,1,value); \
glProgramUniform##func(program,location,count,value); \
return(true); \
}

View File

@ -95,6 +95,8 @@ namespace hgl
#define HGL_GLSL_SetUniform1234(func,type) bool Shader::SetUniform1##func(const char *uniform_name,type v0) \
{ \
if(!uniform_name||!*uniform_name)return(false); \
\
const int location=GetUniformLocation(uniform_name); \
\
if(location==-1)return(false); \
@ -104,6 +106,8 @@ namespace hgl
\
bool Shader::SetUniform2##func(const char *uniform_name,type v0,type v1) \
{ \
if(!uniform_name||!*uniform_name)return(false); \
\
const int location=GetUniformLocation(uniform_name); \
\
if(location==-1)return(false); \
@ -113,6 +117,8 @@ namespace hgl
\
bool Shader::SetUniform3##func(const char *uniform_name,type v0,type v1,type v2) \
{ \
if(!uniform_name||!*uniform_name)return(false); \
\
const int location=GetUniformLocation(uniform_name); \
\
if(location==-1)return(false); \
@ -122,6 +128,8 @@ namespace hgl
\
bool Shader::SetUniform4##func(const char *uniform_name,type v0,type v1,type v2,type v3) \
{ \
if(!uniform_name||!*uniform_name)return(false); \
\
const int location=GetUniformLocation(uniform_name); \
\
if(location==-1)return(false); \
@ -134,13 +142,15 @@ namespace hgl
#undef HGL_GLSL_SetUniform1234
#define HGL_GLSL_SetUniformPointer(func,type) bool Shader::SetUniform##func(const char *uniform_name,const type *value) \
#define HGL_GLSL_SetUniformPointer(func,type) bool Shader::SetUniform##func(const char *uniform_name,int count,const type *value) \
{ \
if(!uniform_name||!*uniform_name||count<=0||!value)return(false); \
\
const int location=GetUniformLocation(uniform_name); \
\
if(location==-1)return(false); \
\
return SetUniform##func(location,value); \
return SetUniform##func(location,count,value); \
}
HGL_GLSL_SetUniformPointer(1fv,float);
@ -162,6 +172,8 @@ namespace hgl
#define HGL_GLSL_SetUniformMatrixPointer(func) bool Shader::SetUniformMatrix##func(const char *uniform_name,const float *mat) \
{ \
if(!uniform_name||!*uniform_name||*mat)return(false); \
\
const int location=GetUniformLocation(uniform_name); \
\
if(location==-1)return(false); \