diff --git a/include/osg/Program b/include/osg/Program index 004dedb02..63941bb0a 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -11,8 +11,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -/* file: include/osg/Program - * author: Mike Weiblen 2005-04-06 +/* file: include/osg/Program + * author: Mike Weiblen 2005-04-29 */ #ifndef OSG_PROGRAM @@ -37,254 +37,254 @@ class Shader; class OSG_EXPORT GL2Extensions : public osg::Referenced { public: - GL2Extensions(unsigned int contextID); - GL2Extensions(const GL2Extensions& rhs); + GL2Extensions(unsigned int contextID); + GL2Extensions(const GL2Extensions& rhs); - void lowestCommonDenominator(const GL2Extensions& rhs); + void lowestCommonDenominator(const GL2Extensions& rhs); - void setupGL2Extensions(unsigned int contextID); + void setupGL2Extensions(unsigned int contextID); - /** Does the GL driver support OpenGL Shading Language? */ - bool isGlslSupported() const; + /** Does the GL driver support OpenGL Shading Language? */ + bool isGlslSupported() const; - float getGlVersion() const { return _glVersion; } - float getLanguageVersion() const { return _glslLanguageVersion; } + float getGlVersion() const { return _glVersion; } + float getLanguageVersion() const { return _glslLanguageVersion; } - void setShaderObjectsSupported(bool flag) { _isShaderObjectsSupported = flag; } - bool isShaderObjectsSupported() const { return _isShaderObjectsSupported; } + void setShaderObjectsSupported(bool flag) { _isShaderObjectsSupported = flag; } + bool isShaderObjectsSupported() const { return _isShaderObjectsSupported; } - void setVertexShaderSupported(bool flag) { _isVertexShaderSupported = flag; } - bool isVertexShaderSupported() const { return _isVertexShaderSupported; } + void setVertexShaderSupported(bool flag) { _isVertexShaderSupported = flag; } + bool isVertexShaderSupported() const { return _isVertexShaderSupported; } - void setFragmentShaderSupported(bool flag) { _isFragmentShaderSupported = flag; } - bool isFragmentShaderSupported() const { return _isFragmentShaderSupported; } + void setFragmentShaderSupported(bool flag) { _isFragmentShaderSupported = flag; } + bool isFragmentShaderSupported() const { return _isFragmentShaderSupported; } - void setLanguage100Supported(bool flag) { _isLanguage100Supported = flag; } - bool isLanguage100Supported() const { return _isLanguage100Supported; } + void setLanguage100Supported(bool flag) { _isLanguage100Supported = flag; } + bool isLanguage100Supported() const { return _isLanguage100Supported; } - /** Function to call to get the extension of a specified context. - * If the Exentsion object for that context has not yet been created then - * and the 'createIfNotInitalized' flag been set to false then returns NULL. - * If 'createIfNotInitalized' is true then the Extensions object is - * automatically created. However, in this case the extension object - * only be created with the graphics context associated with ContextID..*/ - static GL2Extensions* Get(unsigned int contextID,bool createIfNotInitalized); + /** Function to call to get the extension of a specified context. + * If the Exentsion object for that context has not yet been created then + * and the 'createIfNotInitalized' flag been set to false then returns NULL. + * If 'createIfNotInitalized' is true then the Extensions object is + * automatically created. However, in this case the extension object + * only be created with the graphics context associated with ContextID..*/ + static GL2Extensions* Get(unsigned int contextID,bool createIfNotInitalized); - /** allows users to override the extensions across graphics contexts. - * typically used when you have different extensions supported across graphics pipes - * but need to ensure that they all use the same low common denominator extensions.*/ - static void Set(unsigned int contextID, GL2Extensions* extensions); + /** allows users to override the extensions across graphics contexts. + * typically used when you have different extensions supported across graphics pipes + * but need to ensure that they all use the same low common denominator extensions.*/ + static void Set(unsigned int contextID, GL2Extensions* extensions); - void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) const; - void glDrawBuffers(GLsizei n, const GLenum *bufs) const; - void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) const; - void glStencilFuncSeparate(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask) const; - void glStencilMaskSeparate(GLenum face, GLuint mask) const; - void glAttachShader(GLuint program, GLuint shader) const; - void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) const; - void glCompileShader(GLuint shader) const; - GLuint glCreateProgram(void) const; - GLuint glCreateShader(GLenum type) const; - void glDeleteProgram(GLuint program) const; - void glDeleteShader(GLuint shader) const; - void glDetachShader(GLuint program, GLuint shader) const; - void glDisableVertexAttribArray(GLuint index) const; - void glEnableVertexAttribArray(GLuint index) const; - void glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; - void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; - void glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj) const; - GLint glGetAttribLocation(GLuint program, const GLchar *name) const; - void glGetProgramiv(GLuint program, GLenum pname, GLint *params) const; - void glGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) const; - void glGetShaderiv(GLuint shader, GLenum pname, GLint *params) const; - void glGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) const; - void glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source) const; - GLint glGetUniformLocation(GLuint program, const GLchar *name) const; - void glGetUniformfv(GLuint program, GLint location, GLfloat *params) const; - void glGetUniformiv(GLuint program, GLint location, GLint *params) const; - void glGetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) const; - void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) const; - void glGetVertexAttribiv(GLuint index, GLenum pname, GLint *params) const; - void glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid* *pointer) const; - GLboolean glIsProgram(GLuint program) const; - GLboolean glIsShader(GLuint shader) const; - void glLinkProgram(GLuint program) const; - void glShaderSource(GLuint shader, GLsizei count, const GLchar* *string, const GLint *length) const; - void glUseProgram(GLuint program) const; - void glUniform1f(GLint location, GLfloat v0) const; - void glUniform2f(GLint location, GLfloat v0, GLfloat v1) const; - void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) const; - void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) const; - void glUniform1i(GLint location, GLint v0) const; - void glUniform2i(GLint location, GLint v0, GLint v1) const; - void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) const; - void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) const; - void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) const; - void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) const; - void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) const; - void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) const; - void glUniform1iv(GLint location, GLsizei count, const GLint *value) const; - void glUniform2iv(GLint location, GLsizei count, const GLint *value) const; - void glUniform3iv(GLint location, GLsizei count, const GLint *value) const; - void glUniform4iv(GLint location, GLsizei count, const GLint *value) const; - void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const; - void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const; - void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const; - void glValidateProgram(GLuint program) const; - void glVertexAttrib1d(GLuint index, GLdouble x) const; - void glVertexAttrib1dv(GLuint index, const GLdouble *v) const; - void glVertexAttrib1f(GLuint index, GLfloat x) const; - void glVertexAttrib1fv(GLuint index, const GLfloat *v) const; - void glVertexAttrib1s(GLuint index, GLshort x) const; - void glVertexAttrib1sv(GLuint index, const GLshort *v) const; - void glVertexAttrib2d(GLuint index, GLdouble x, GLdouble y) const; - void glVertexAttrib2dv(GLuint index, const GLdouble *v) const; - void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) const; - void glVertexAttrib2fv(GLuint index, const GLfloat *v) const; - void glVertexAttrib2s(GLuint index, GLshort x, GLshort y) const; - void glVertexAttrib2sv(GLuint index, const GLshort *v) const; - void glVertexAttrib3d(GLuint index, GLdouble x, GLdouble y, GLdouble z) const; - void glVertexAttrib3dv(GLuint index, const GLdouble *v) const; - void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) const; - void glVertexAttrib3fv(GLuint index, const GLfloat *v) const; - void glVertexAttrib3s(GLuint index, GLshort x, GLshort y, GLshort z) const; - void glVertexAttrib3sv(GLuint index, const GLshort *v) const; - void glVertexAttrib4Nbv(GLuint index, const GLbyte *v) const; - void glVertexAttrib4Niv(GLuint index, const GLint *v) const; - void glVertexAttrib4Nsv(GLuint index, const GLshort *v) const; - void glVertexAttrib4Nub(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) const; - void glVertexAttrib4Nubv(GLuint index, const GLubyte *v) const; - void glVertexAttrib4Nuiv(GLuint index, const GLuint *v) const; - void glVertexAttrib4Nusv(GLuint index, const GLushort *v) const; - void glVertexAttrib4bv(GLuint index, const GLbyte *v) const; - void glVertexAttrib4d(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) const; - void glVertexAttrib4dv(GLuint index, const GLdouble *v) const; - void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) const; - void glVertexAttrib4fv(GLuint index, const GLfloat *v) const; - void glVertexAttrib4iv(GLuint index, const GLint *v) const; - void glVertexAttrib4s(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w) const; - void glVertexAttrib4sv(GLuint index, const GLshort *v) const; - void glVertexAttrib4ubv(GLuint index, const GLubyte *v) const; - void glVertexAttrib4uiv(GLuint index, const GLuint *v) const; - void glVertexAttrib4usv(GLuint index, const GLushort *v) const; - void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer) const; + void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) const; + void glDrawBuffers(GLsizei n, const GLenum *bufs) const; + void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) const; + void glStencilFuncSeparate(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask) const; + void glStencilMaskSeparate(GLenum face, GLuint mask) const; + void glAttachShader(GLuint program, GLuint shader) const; + void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) const; + void glCompileShader(GLuint shader) const; + GLuint glCreateProgram(void) const; + GLuint glCreateShader(GLenum type) const; + void glDeleteProgram(GLuint program) const; + void glDeleteShader(GLuint shader) const; + void glDetachShader(GLuint program, GLuint shader) const; + void glDisableVertexAttribArray(GLuint index) const; + void glEnableVertexAttribArray(GLuint index) const; + void glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; + void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; + void glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj) const; + GLint glGetAttribLocation(GLuint program, const GLchar *name) const; + void glGetProgramiv(GLuint program, GLenum pname, GLint *params) const; + void glGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) const; + void glGetShaderiv(GLuint shader, GLenum pname, GLint *params) const; + void glGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) const; + void glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source) const; + GLint glGetUniformLocation(GLuint program, const GLchar *name) const; + void glGetUniformfv(GLuint program, GLint location, GLfloat *params) const; + void glGetUniformiv(GLuint program, GLint location, GLint *params) const; + void glGetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) const; + void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) const; + void glGetVertexAttribiv(GLuint index, GLenum pname, GLint *params) const; + void glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid* *pointer) const; + GLboolean glIsProgram(GLuint program) const; + GLboolean glIsShader(GLuint shader) const; + void glLinkProgram(GLuint program) const; + void glShaderSource(GLuint shader, GLsizei count, const GLchar* *string, const GLint *length) const; + void glUseProgram(GLuint program) const; + void glUniform1f(GLint location, GLfloat v0) const; + void glUniform2f(GLint location, GLfloat v0, GLfloat v1) const; + void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) const; + void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) const; + void glUniform1i(GLint location, GLint v0) const; + void glUniform2i(GLint location, GLint v0, GLint v1) const; + void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) const; + void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) const; + void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) const; + void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) const; + void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) const; + void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) const; + void glUniform1iv(GLint location, GLsizei count, const GLint *value) const; + void glUniform2iv(GLint location, GLsizei count, const GLint *value) const; + void glUniform3iv(GLint location, GLsizei count, const GLint *value) const; + void glUniform4iv(GLint location, GLsizei count, const GLint *value) const; + void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const; + void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const; + void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const; + void glValidateProgram(GLuint program) const; + void glVertexAttrib1d(GLuint index, GLdouble x) const; + void glVertexAttrib1dv(GLuint index, const GLdouble *v) const; + void glVertexAttrib1f(GLuint index, GLfloat x) const; + void glVertexAttrib1fv(GLuint index, const GLfloat *v) const; + void glVertexAttrib1s(GLuint index, GLshort x) const; + void glVertexAttrib1sv(GLuint index, const GLshort *v) const; + void glVertexAttrib2d(GLuint index, GLdouble x, GLdouble y) const; + void glVertexAttrib2dv(GLuint index, const GLdouble *v) const; + void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) const; + void glVertexAttrib2fv(GLuint index, const GLfloat *v) const; + void glVertexAttrib2s(GLuint index, GLshort x, GLshort y) const; + void glVertexAttrib2sv(GLuint index, const GLshort *v) const; + void glVertexAttrib3d(GLuint index, GLdouble x, GLdouble y, GLdouble z) const; + void glVertexAttrib3dv(GLuint index, const GLdouble *v) const; + void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) const; + void glVertexAttrib3fv(GLuint index, const GLfloat *v) const; + void glVertexAttrib3s(GLuint index, GLshort x, GLshort y, GLshort z) const; + void glVertexAttrib3sv(GLuint index, const GLshort *v) const; + void glVertexAttrib4Nbv(GLuint index, const GLbyte *v) const; + void glVertexAttrib4Niv(GLuint index, const GLint *v) const; + void glVertexAttrib4Nsv(GLuint index, const GLshort *v) const; + void glVertexAttrib4Nub(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) const; + void glVertexAttrib4Nubv(GLuint index, const GLubyte *v) const; + void glVertexAttrib4Nuiv(GLuint index, const GLuint *v) const; + void glVertexAttrib4Nusv(GLuint index, const GLushort *v) const; + void glVertexAttrib4bv(GLuint index, const GLbyte *v) const; + void glVertexAttrib4d(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) const; + void glVertexAttrib4dv(GLuint index, const GLdouble *v) const; + void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) const; + void glVertexAttrib4fv(GLuint index, const GLfloat *v) const; + void glVertexAttrib4iv(GLuint index, const GLint *v) const; + void glVertexAttrib4s(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w) const; + void glVertexAttrib4sv(GLuint index, const GLshort *v) const; + void glVertexAttrib4ubv(GLuint index, const GLubyte *v) const; + void glVertexAttrib4uiv(GLuint index, const GLuint *v) const; + void glVertexAttrib4usv(GLuint index, const GLushort *v) const; + void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer) const; - // C++-friendly convenience wrapper methods - GLuint getCurrentProgram() const; - bool getProgramInfoLog( GLuint program, std::string& result ) const; - bool getShaderInfoLog( GLuint shader, std::string& result ) const; - bool getAttribLocation( const char* attribName, GLuint& slot ) const; + // C++-friendly convenience wrapper methods + GLuint getCurrentProgram() const; + bool getProgramInfoLog( GLuint program, std::string& result ) const; + bool getShaderInfoLog( GLuint shader, std::string& result ) const; + bool getAttribLocation( const char* attribName, GLuint& slot ) const; protected: - ~GL2Extensions() {} + ~GL2Extensions() {} - float _glVersion; - float _glslLanguageVersion; + float _glVersion; + float _glslLanguageVersion; - bool _isShaderObjectsSupported; - bool _isVertexShaderSupported; - bool _isFragmentShaderSupported; - bool _isLanguage100Supported; + bool _isShaderObjectsSupported; + bool _isVertexShaderSupported; + bool _isFragmentShaderSupported; + bool _isLanguage100Supported; - void* _glBlendEquationSeparate; - void* _glDrawBuffers; - void* _glStencilOpSeparate; - void* _glStencilFuncSeparate; - void* _glStencilMaskSeparate; - void* _glAttachShader; - void* _glBindAttribLocation; - void* _glCompileShader; - void* _glCreateProgram; - void* _glCreateShader; - void* _glDeleteProgram; - void* _glDeleteShader; - void* _glDetachShader; - void* _glDisableVertexAttribArray; - void* _glEnableVertexAttribArray; - void* _glGetActiveAttrib; - void* _glGetActiveUniform; - void* _glGetAttachedShaders; - void* _glGetAttribLocation; - void* _glGetProgramiv; - void* _glGetProgramInfoLog; - void* _glGetShaderiv; - void* _glGetShaderInfoLog; - void* _glGetShaderSource; - void* _glGetUniformLocation; - void* _glGetUniformfv; - void* _glGetUniformiv; - void* _glGetVertexAttribdv; - void* _glGetVertexAttribfv; - void* _glGetVertexAttribiv; - void* _glGetVertexAttribPointerv; - void* _glIsProgram; - void* _glIsShader; - void* _glLinkProgram; - void* _glShaderSource; - void* _glUseProgram; - void* _glUniform1f; - void* _glUniform2f; - void* _glUniform3f; - void* _glUniform4f; - void* _glUniform1i; - void* _glUniform2i; - void* _glUniform3i; - void* _glUniform4i; - void* _glUniform1fv; - void* _glUniform2fv; - void* _glUniform3fv; - void* _glUniform4fv; - void* _glUniform1iv; - void* _glUniform2iv; - void* _glUniform3iv; - void* _glUniform4iv; - void* _glUniformMatrix2fv; - void* _glUniformMatrix3fv; - void* _glUniformMatrix4fv; - void* _glValidateProgram; - void* _glVertexAttrib1d; - void* _glVertexAttrib1dv; - void* _glVertexAttrib1f; - void* _glVertexAttrib1fv; - void* _glVertexAttrib1s; - void* _glVertexAttrib1sv; - void* _glVertexAttrib2d; - void* _glVertexAttrib2dv; - void* _glVertexAttrib2f; - void* _glVertexAttrib2fv; - void* _glVertexAttrib2s; - void* _glVertexAttrib2sv; - void* _glVertexAttrib3d; - void* _glVertexAttrib3dv; - void* _glVertexAttrib3f; - void* _glVertexAttrib3fv; - void* _glVertexAttrib3s; - void* _glVertexAttrib3sv; - void* _glVertexAttrib4Nbv; - void* _glVertexAttrib4Niv; - void* _glVertexAttrib4Nsv; - void* _glVertexAttrib4Nub; - void* _glVertexAttrib4Nubv; - void* _glVertexAttrib4Nuiv; - void* _glVertexAttrib4Nusv; - void* _glVertexAttrib4bv; - void* _glVertexAttrib4d; - void* _glVertexAttrib4dv; - void* _glVertexAttrib4f; - void* _glVertexAttrib4fv; - void* _glVertexAttrib4iv; - void* _glVertexAttrib4s; - void* _glVertexAttrib4sv; - void* _glVertexAttrib4ubv; - void* _glVertexAttrib4uiv; - void* _glVertexAttrib4usv; - void* _glVertexAttribPointer; + void* _glBlendEquationSeparate; + void* _glDrawBuffers; + void* _glStencilOpSeparate; + void* _glStencilFuncSeparate; + void* _glStencilMaskSeparate; + void* _glAttachShader; + void* _glBindAttribLocation; + void* _glCompileShader; + void* _glCreateProgram; + void* _glCreateShader; + void* _glDeleteProgram; + void* _glDeleteShader; + void* _glDetachShader; + void* _glDisableVertexAttribArray; + void* _glEnableVertexAttribArray; + void* _glGetActiveAttrib; + void* _glGetActiveUniform; + void* _glGetAttachedShaders; + void* _glGetAttribLocation; + void* _glGetProgramiv; + void* _glGetProgramInfoLog; + void* _glGetShaderiv; + void* _glGetShaderInfoLog; + void* _glGetShaderSource; + void* _glGetUniformLocation; + void* _glGetUniformfv; + void* _glGetUniformiv; + void* _glGetVertexAttribdv; + void* _glGetVertexAttribfv; + void* _glGetVertexAttribiv; + void* _glGetVertexAttribPointerv; + void* _glIsProgram; + void* _glIsShader; + void* _glLinkProgram; + void* _glShaderSource; + void* _glUseProgram; + void* _glUniform1f; + void* _glUniform2f; + void* _glUniform3f; + void* _glUniform4f; + void* _glUniform1i; + void* _glUniform2i; + void* _glUniform3i; + void* _glUniform4i; + void* _glUniform1fv; + void* _glUniform2fv; + void* _glUniform3fv; + void* _glUniform4fv; + void* _glUniform1iv; + void* _glUniform2iv; + void* _glUniform3iv; + void* _glUniform4iv; + void* _glUniformMatrix2fv; + void* _glUniformMatrix3fv; + void* _glUniformMatrix4fv; + void* _glValidateProgram; + void* _glVertexAttrib1d; + void* _glVertexAttrib1dv; + void* _glVertexAttrib1f; + void* _glVertexAttrib1fv; + void* _glVertexAttrib1s; + void* _glVertexAttrib1sv; + void* _glVertexAttrib2d; + void* _glVertexAttrib2dv; + void* _glVertexAttrib2f; + void* _glVertexAttrib2fv; + void* _glVertexAttrib2s; + void* _glVertexAttrib2sv; + void* _glVertexAttrib3d; + void* _glVertexAttrib3dv; + void* _glVertexAttrib3f; + void* _glVertexAttrib3fv; + void* _glVertexAttrib3s; + void* _glVertexAttrib3sv; + void* _glVertexAttrib4Nbv; + void* _glVertexAttrib4Niv; + void* _glVertexAttrib4Nsv; + void* _glVertexAttrib4Nub; + void* _glVertexAttrib4Nubv; + void* _glVertexAttrib4Nuiv; + void* _glVertexAttrib4Nusv; + void* _glVertexAttrib4bv; + void* _glVertexAttrib4d; + void* _glVertexAttrib4dv; + void* _glVertexAttrib4f; + void* _glVertexAttrib4fv; + void* _glVertexAttrib4iv; + void* _glVertexAttrib4s; + void* _glVertexAttrib4sv; + void* _glVertexAttrib4ubv; + void* _glVertexAttrib4uiv; + void* _glVertexAttrib4usv; + void* _glVertexAttribPointer; - void* _glGetInfoLogARB; - void* _glGetObjectParameterivARB; - void* _glDeleteObjectARB; - void* _glGetHandleARB; + void* _glGetInfoLogARB; + void* _glGetObjectParameterivARB; + void* _glDeleteObjectARB; + void* _glGetHandleARB; }; /////////////////////////////////////////////////////////////////////////// @@ -312,52 +312,52 @@ class OSG_EXPORT Program : public osg::StateAttribute /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ virtual int compare(const osg::StateAttribute& sa) const; - /** If enabled, activate our program in the GL pipeline, - * performing any rebuild operations that might be pending. */ - virtual void apply(osg::State& state) const; + /** If enabled, activate our program in the GL pipeline, + * performing any rebuild operations that might be pending. */ + virtual void apply(osg::State& state) const; - virtual void compileGLObjects(osg::State& state) const; + virtual void compileGLObjects(osg::State& state) const; /** release OpenGL objects in specified graphics context if State object is passed, otherwise release OpenGL objects for all graphics context if State object pointer NULL.*/ virtual void releaseGLObjects(osg::State* state=0) const; - /** Mark our PCSOs as needing relink */ - void dirtyProgram(); + /** Mark our PCSOs as needing relink */ + void dirtyProgram(); - /** Attach an osg::Shader to this osg::Program. - * Mark Program as needing relink. Return true for success */ - bool addShader( Shader* shader ); + /** Attach an osg::Shader to this osg::Program. + * Mark Program as needing relink. Return true for success */ + bool addShader( Shader* shader ); - unsigned int getNumShaders() const { return _shaderList.size(); } + unsigned int getNumShaders() const { return _shaderList.size(); } - Shader* getShader( unsigned int i ) { return _shaderList[i].get(); } - const Shader* getShader( unsigned int i ) const { return _shaderList[i].get(); } + Shader* getShader( unsigned int i ) { return _shaderList[i].get(); } + const Shader* getShader( unsigned int i ) const { return _shaderList[i].get(); } - /** Remove osg::Shader from this osg::Program. - * Mark Program as needing relink. Return true for success */ - bool removeShader( Shader* shader ); + /** Remove osg::Shader from this osg::Program. + * Mark Program as needing relink. Return true for success */ + bool removeShader( Shader* shader ); - /** Add an attribute location binding. */ - void bindAttribLocation( GLuint index, const char* name ); - typedef std::map AttribBindingList; - const AttribBindingList& getAttribBindingList() const { return _attribBindingList; } + /** Add an attribute location binding. */ + void bindAttribLocation( GLuint index, const char* name ); + typedef std::map AttribBindingList; + const AttribBindingList& getAttribBindingList() const { return _attribBindingList; } - /** Return true if this Program represents "fixed-functionality" rendering */ - bool isFixedFunction() const; + /** Return true if this Program represents "fixed-functionality" rendering */ + bool isFixedFunction() const; - /** Query InfoLog from a glProgram */ - void getGlProgramInfoLog(unsigned int contextID, std::string& log) const; + /** Query InfoLog from a glProgram */ + bool getGlProgramInfoLog(unsigned int contextID, std::string& log) const; - /** A name for use by the application */ - void setName( const std::string& name ) { _name = name; } - void setName( const char* name ) { _name = name; } - const std::string& getName() const { return _name; } + /** A name for use by the application */ + void setName( const std::string& name ) { _name = name; } + void setName( const char* name ) { _name = name; } + const std::string& getName() const { return _name; } /** Mark internal glProgram for deletion. - * Deletion requests are queued until they can be executed - * in the proper GL context. */ + * Deletion requests are queued until they can be executed + * in the proper GL context. */ static void deleteGlProgram(unsigned int contextID, GLuint program); /** flush all the cached glPrograms which need to be deleted @@ -372,23 +372,23 @@ class OSG_EXPORT Program : public osg::StateAttribute class PerContextProgram; friend class PerContextProgram; - /** PerContextProgram (PCP) is an OSG-internal encapsulation of glPrograms per-GL context. */ - class OSG_EXPORT PerContextProgram : public osg::Referenced - { - public: + /** PerContextProgram (PCP) is an OSG-internal encapsulation of glPrograms per-GL context. */ + class OSG_EXPORT PerContextProgram : public osg::Referenced + { + public: - PerContextProgram(const Program* program, unsigned int contextID); + PerContextProgram(const Program* program, unsigned int contextID); - GLuint getHandle() const {return _glProgramHandle;} + GLuint getHandle() const {return _glProgramHandle;} - void requestLink(); - void linkProgram(); - bool needsLink() const {return _needsLink;} - bool isLinked() const {return _isLinked;} - void getInfoLog( std::string& infoLog ) const; + void requestLink(); + void linkProgram(); + bool needsLink() const {return _needsLink;} + bool isLinked() const {return _isLinked;} + bool getInfoLog( std::string& infoLog ) const; - void useProgram() const; + void useProgram() const; void apply(const Uniform& uniform) const { @@ -396,52 +396,52 @@ class OSG_EXPORT Program : public osg::StateAttribute if (location>=0) uniform.apply(_extensions.get(),location); } - inline GLint getUniformLocation( const std::string& name ) const { NameLocationMap::const_iterator itr = _uniformLocationMap.find(name); return (itr!=_uniformLocationMap.end()) ? itr->second : -1; } - inline GLint getAttribLocation( const std::string& name ) const { NameLocationMap::const_iterator itr = _attribLocationMap.find(name); return (itr!=_attribLocationMap.end()) ? itr->second : -1; } + inline GLint getUniformLocation( const std::string& name ) const { NameLocationMap::const_iterator itr = _uniformLocationMap.find(name); return (itr!=_uniformLocationMap.end()) ? itr->second : -1; } + inline GLint getAttribLocation( const std::string& name ) const { NameLocationMap::const_iterator itr = _attribLocationMap.find(name); return (itr!=_attribLocationMap.end()) ? itr->second : -1; } - protected: /*methods*/ - ~PerContextProgram(); + protected: /*methods*/ + ~PerContextProgram(); - protected: /*data*/ - /** Pointer to our parent Program */ - const Program* _program; - /** Pointer to this context's extension functions */ - osg::ref_ptr _extensions; - /** Handle to the actual OpenGL glProgram */ - GLuint _glProgramHandle; - /** Does our glProgram need to be linked? */ - bool _needsLink; - /** Is our glProgram successfully linked? */ - bool _isLinked; - const unsigned int _contextID; + protected: /*data*/ + /** Pointer to our parent Program */ + const Program* _program; + /** Pointer to this context's extension functions */ + osg::ref_ptr _extensions; + /** Handle to the actual OpenGL glProgram */ + GLuint _glProgramHandle; + /** Does our glProgram need to be linked? */ + bool _needsLink; + /** Is our glProgram successfully linked? */ + bool _isLinked; + const unsigned int _contextID; typedef std::map NameLocationMap; NameLocationMap _uniformLocationMap; NameLocationMap _attribLocationMap; - private: - PerContextProgram(); // disallowed - PerContextProgram(const PerContextProgram&); // disallowed - PerContextProgram& operator=(const PerContextProgram&); // disallowed - }; + private: + PerContextProgram(); // disallowed + PerContextProgram(const PerContextProgram&); // disallowed + PerContextProgram& operator=(const PerContextProgram&); // disallowed + }; - /** Get the PCP for a particular GL context */ + /** Get the PCP for a particular GL context */ PerContextProgram* getPCP(unsigned int contextID) const; - protected: /*methods*/ + protected: /*methods*/ virtual ~Program(); - protected: /*data*/ - std::string _name; + protected: /*data*/ + std::string _name; mutable osg::buffered_value< osg::ref_ptr > _pcpList; - AttribBindingList _attribBindingList; + AttribBindingList _attribBindingList; - typedef std::vector< ref_ptr > ShaderList; - ShaderList _shaderList; + typedef std::vector< ref_ptr > ShaderList; + ShaderList _shaderList; private: - Program& operator=(const Program&); // disallowed + Program& operator=(const Program&); // disallowed }; } diff --git a/include/osg/Shader b/include/osg/Shader index 8b2f203cb..66d343b9c 100644 --- a/include/osg/Shader +++ b/include/osg/Shader @@ -11,8 +11,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -/* file: include/osg/Shader - * author: Mike Weiblen 2005-04-06 +/* file: include/osg/Shader + * author: Mike Weiblen 2005-04-29 */ #ifndef OSG_SHADER @@ -39,11 +39,11 @@ class OSG_EXPORT Shader : public osg::Object { public: - enum Type { - VERTEX = GL_VERTEX_SHADER, - FRAGMENT = GL_FRAGMENT_SHADER, - UNDEFINED = -1 - }; + enum Type { + VERTEX = GL_VERTEX_SHADER, + FRAGMENT = GL_FRAGMENT_SHADER, + UNDEFINED = -1 + }; Shader( Type type = UNDEFINED); Shader( Type type, const std::string& source ); @@ -51,122 +51,122 @@ class OSG_EXPORT Shader : public osg::Object /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ Shader(const Shader& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - META_Object(osg, Shader); + META_Object(osg, Shader); int compare(const Shader& rhs) const; - bool setType( Type t ); + bool setType( Type t ); - /** Load the Shader's source code text from a string. */ - void setShaderSource( const std::string& sourceText ); + /** Load the Shader's source code text from a string. */ + void setShaderSource( const std::string& sourceText ); /** Read shader source from file and then constructor shader of specified type. * Return the resulting Shader or 0 if no valid shader source code be read.*/ static Shader* readShaderFile( Type type, const std::string& fileName ); - /** Load the Shader's source code text from a file. */ - bool loadShaderSourceFromFile( const std::string& fileName ); + /** Load the Shader's source code text from a file. */ + bool loadShaderSourceFromFile( const std::string& fileName ); - /** Query the shader's source code text */ - inline const std::string& getShaderSource() const { return _shaderSource; } + /** Query the shader's source code text */ + inline const std::string& getShaderSource() const { return _shaderSource; } - /** Get the Shader type as an enum. */ - inline Type getType() const { return _type; } + /** Get the Shader type as an enum. */ + inline Type getType() const { return _type; } - /** Get the Shader type as a descriptive string. */ - const char* getTypename() const; + /** Get the Shader type as a descriptive string. */ + const char* getTypename() const; /** Mark our PCSs as needing recompilation. - * Also mark Programs that depend on us as needing relink */ + * Also mark Programs that depend on us as needing relink */ void dirtyShader(); - /** If needed, compile the PCS's glShader */ - void compileShader(unsigned int contextID) const; + /** If needed, compile the PCS's glShader */ + void compileShader(unsigned int contextID) const; - /** For a given GL context, attach a glShader to a glProgram */ - void attachShader(unsigned int contextID, GLuint program) const; + /** For a given GL context, attach a glShader to a glProgram */ + void attachShader(unsigned int contextID, GLuint program) const; - /** Query InfoLog from a glShader */ - void getGlShaderInfoLog(unsigned int contextID, std::string& log) const; + /** Query InfoLog from a glShader */ + bool getGlShaderInfoLog(unsigned int contextID, std::string& log) const; - /** A name for use by the application */ - void setName( const std::string& name ) { _name = name; } - void setName( const char* name ) { _name = name; } - const std::string& getName() const { return _name; }; + /** A name for use by the application */ + void setName( const std::string& name ) { _name = name; } + void setName( const char* name ) { _name = name; } + const std::string& getName() const { return _name; }; - /** Mark internal glShader for deletion. - * Deletion requests are queued tuntil they can be executed - * in the proper GL context. */ - static void deleteGlShader(unsigned int contextID, GLuint shader); + /** Mark internal glShader for deletion. + * Deletion requests are queued tuntil they can be executed + * in the proper GL context. */ + static void deleteGlShader(unsigned int contextID, GLuint shader); /** flush all the cached glShaders which need to be deleted * in the OpenGL context related to contextID.*/ static void flushDeletedGlShaders(unsigned int contextID,double currentTime, double& availableTime); - static Shader::Type getTypeId( const std::string& tname ); + static Shader::Type getTypeId( const std::string& tname ); protected: - /** PerContextShader (PCS) is an OSG-internal encapsulation of glShader per-GL context. */ - class PerContextShader : public osg::Referenced - { - public: - PerContextShader(const Shader* shader, unsigned int contextID); + /** PerContextShader (PCS) is an OSG-internal encapsulation of glShader per-GL context. */ + class PerContextShader : public osg::Referenced + { + public: + PerContextShader(const Shader* shader, unsigned int contextID); - GLuint getHandle() const {return _glShaderHandle;} + GLuint getHandle() const {return _glShaderHandle;} - void requestCompile(); - void compileShader(); - void getInfoLog( std::string& infoLog ) const; + void requestCompile(); + void compileShader(); + bool getInfoLog( std::string& infoLog ) const; - /** Attach our glShader to a glProgram */ - void attachShader(GLuint program) const; + /** Attach our glShader to a glProgram */ + void attachShader(GLuint program) const; - /** Detach our glShader from a glProgram */ - void detachShader(GLuint program) const; + /** Detach our glShader from a glProgram */ + void detachShader(GLuint program) const; - protected: /*methods*/ - ~PerContextShader(); + protected: /*methods*/ + ~PerContextShader(); - protected: /*data*/ - /** Pointer to our parent osg::Shader */ - const Shader* _shader; - /** Pointer to this context's extension functions. */ - osg::ref_ptr _extensions; - /** Handle to the actual glShader. */ - GLuint _glShaderHandle; - /** Does our glShader need to be recompiled? */ - bool _needsCompile; - /** Is our glShader successfully compiled? */ - bool _isCompiled; - const unsigned int _contextID; + protected: /*data*/ + /** Pointer to our parent osg::Shader */ + const Shader* _shader; + /** Pointer to this context's extension functions. */ + osg::ref_ptr _extensions; + /** Handle to the actual glShader. */ + GLuint _glShaderHandle; + /** Does our glShader need to be recompiled? */ + bool _needsCompile; + /** Is our glShader successfully compiled? */ + bool _isCompiled; + const unsigned int _contextID; - private: - PerContextShader(); // disallowed - PerContextShader(const PerContextShader&); // disallowed - PerContextShader& operator=(const PerContextShader&); // disallowed - }; + private: + PerContextShader(); // disallowed + PerContextShader(const PerContextShader&); // disallowed + PerContextShader& operator=(const PerContextShader&); // disallowed + }; - protected: /*methods*/ + protected: /*methods*/ virtual ~Shader(); PerContextShader* getPCS(unsigned int contextID) const; - friend class Program; - bool addProgramRef( Program* program ); - bool removeProgramRef( Program* program ); + friend class Program; + bool addProgramRef( Program* program ); + bool removeProgramRef( Program* program ); - protected: /*data*/ - Type _type; - std::string _name; - std::string _shaderSource; - /** osg::Programs that this osg::Shader is attached to */ - typedef std::set< Program* > ProgramSet; - ProgramSet _programSet; + protected: /*data*/ + Type _type; + std::string _name; + std::string _shaderSource; + /** osg::Programs that this osg::Shader is attached to */ + typedef std::set< Program* > ProgramSet; + ProgramSet _programSet; mutable osg::buffered_value< osg::ref_ptr > _pcsList; private: - Shader& operator=(const Shader&); // disallowed + Shader& operator=(const Shader&); // disallowed }; } diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index 79cfc58c8..e12cfd815 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -12,8 +12,8 @@ * */ -/* file: src/osg/Program.cpp - * author: Mike Weiblen 2005-04-15 +/* file: src/osg/Program.cpp + * author: Mike Weiblen 2005-04-29 */ #include @@ -160,7 +160,7 @@ void GL2Extensions::lowestCommonDenominator(const GL2Extensions& rhs) { if (rhs._glVersion < _glVersion) _glVersion = rhs._glVersion; if (rhs._glslLanguageVersion < _glslLanguageVersion) - _glslLanguageVersion = rhs._glslLanguageVersion; + _glslLanguageVersion = rhs._glslLanguageVersion; if (!rhs._isShaderObjectsSupported) _isShaderObjectsSupported = false; if (!rhs._isVertexShaderSupported) _isVertexShaderSupported = false; @@ -280,20 +280,20 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) if( isGlslSupported() ) { - // If glGetString raises an error, assume initial release "1.00" - while(glGetError() != GL_NO_ERROR) {} // reset error flag - const char* langVerStr = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); - if( (glGetError() == GL_NO_ERROR) && langVerStr ) - _glslLanguageVersion = atof( langVerStr ); - else - _glslLanguageVersion = 1.0f; + // If glGetString raises an error, assume initial release "1.00" + while(glGetError() != GL_NO_ERROR) {} // reset error flag + const char* langVerStr = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + if( (glGetError() == GL_NO_ERROR) && langVerStr ) + _glslLanguageVersion = atof( langVerStr ); + else + _glslLanguageVersion = 1.0f; } osg::notify(osg::INFO) - << "glVersion=" << getGlVersion() << ", " - << "isGlslSupported=" << (isGlslSupported() ? "YES" : "NO") << ", " - << "glslLanguageVersion=" << getLanguageVersion() - << std::endl; + << "glVersion=" << getGlVersion() << ", " + << "isGlslSupported=" << (isGlslSupported() ? "YES" : "NO") << ", " + << "glslLanguageVersion=" << getLanguageVersion() + << std::endl; _glBlendEquationSeparate = osg::getGLExtensionFuncPtr("glBlendEquationSeparate"); @@ -401,10 +401,10 @@ void GL2Extensions::setupGL2Extensions(unsigned int contextID) bool GL2Extensions::isGlslSupported() const { return ( _glVersion >= 2.0f ) || - ( _isShaderObjectsSupported && - _isVertexShaderSupported && - _isFragmentShaderSupported && - _isLanguage100Supported ); + ( _isShaderObjectsSupported && + _isVertexShaderSupported && + _isFragmentShaderSupported && + _isLanguage100Supported ); } @@ -418,7 +418,7 @@ GL2Extensions* GL2Extensions::Get(unsigned int contextID, bool createIfNotInitalized) { if (!s_extensions[contextID] && createIfNotInitalized) - s_extensions[contextID] = new GL2Extensions(contextID); + s_extensions[contextID] = new GL2Extensions(contextID); return s_extensions[contextID].get(); } @@ -434,7 +434,7 @@ void GL2Extensions::Set(unsigned int contextID, GL2Extensions* extensions) static void NotSupported( const char* funcName ) { osg::notify(osg::WARN) - <<"Error: "<= 2.0f ) { - // GLSL as GL v2.0 core functionality - GLint result = 0; - glGetIntegerv( GL_CURRENT_PROGRAM, &result ); - return static_cast(result); + // GLSL as GL v2.0 core functionality + GLint result = 0; + glGetIntegerv( GL_CURRENT_PROGRAM, &result ); + return static_cast(result); } else if (_glGetHandleARB) { - // fallback for GLSL as GL v1.5 ARB extension + // fallback for GLSL as GL v1.5 ARB extension #ifndef GL_PROGRAM_OBJECT_ARB #define GL_PROGRAM_OBJECT_ARB 0x8B40 #endif - typedef GLuint (APIENTRY * GetHandleProc) (GLenum pname); - return ((GetHandleProc)_glGetHandleARB)( GL_PROGRAM_OBJECT_ARB ); + typedef GLuint (APIENTRY * GetHandleProc) (GLenum pname); + return ((GetHandleProc)_glGetHandleARB)( GL_PROGRAM_OBJECT_ARB ); } else { - NotSupported( "getCurrentProgram" ); - return 0; + NotSupported( "getCurrentProgram" ); + return 0; } } bool GL2Extensions::getProgramInfoLog( GLuint program, std::string& result ) const { - GLsizei bufLen = 0; // length of buffer to allocate - GLsizei strLen = 0; // strlen GL actually wrote to buffer + GLsizei bufLen = 0; // length of buffer to allocate + GLsizei strLen = 0; // strlen GL actually wrote to buffer glGetProgramiv( program, GL_INFO_LOG_LENGTH, &bufLen ); if( bufLen > 1 ) { - GLchar* infoLog = new GLchar[bufLen]; - glGetProgramInfoLog( program, bufLen, &strLen, infoLog ); - if( strLen > 0 ) result = infoLog; - delete [] infoLog; + GLchar* infoLog = new GLchar[bufLen]; + glGetProgramInfoLog( program, bufLen, &strLen, infoLog ); + if( strLen > 0 ) result = infoLog; + delete [] infoLog; } return (strLen > 0); } @@ -1825,16 +1825,16 @@ bool GL2Extensions::getProgramInfoLog( GLuint program, std::string& result ) con bool GL2Extensions::getShaderInfoLog( GLuint shader, std::string& result ) const { - GLsizei bufLen = 0; // length of buffer to allocate - GLsizei strLen = 0; // strlen GL actually wrote to buffer + GLsizei bufLen = 0; // length of buffer to allocate + GLsizei strLen = 0; // strlen GL actually wrote to buffer glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &bufLen ); if( bufLen > 1 ) { - GLchar* infoLog = new GLchar[bufLen]; - glGetShaderInfoLog( shader, bufLen, &strLen, infoLog ); - if( strLen > 0 ) result = infoLog; - delete [] infoLog; + GLchar* infoLog = new GLchar[bufLen]; + glGetShaderInfoLog( shader, bufLen, &strLen, infoLog ); + if( strLen > 0 ) result = infoLog; + delete [] infoLog; } return (strLen > 0); } @@ -1936,7 +1936,7 @@ Program::~Program() // inform any attached Shaders that we're going away for( unsigned int i=0; i < _shaderList.size(); ++i ) { - _shaderList[i]->removeProgramRef( this ); + _shaderList[i]->removeProgramRef( this ); } } @@ -1975,7 +1975,7 @@ void Program::compileGLObjects( osg::State& state ) const for( unsigned int i=0; i < _shaderList.size(); ++i ) { - _shaderList[i]->compileShader( contextID ); + _shaderList[i]->compileShader( contextID ); } getPCP( contextID )->linkProgram(); @@ -2005,7 +2005,7 @@ bool Program::addShader( Shader* shader ) // Shader can only be added once to a Program for( unsigned int i=0; i < _shaderList.size(); ++i ) { - if( shader == _shaderList[i].get() ) return false; + if( shader == _shaderList[i].get() ) return false; } shader->addProgramRef( this ); @@ -2022,13 +2022,13 @@ bool Program::removeShader( Shader* shader ) // Shader must exist to be removed. for( unsigned int i=0; i < _shaderList.size(); ++i ) { - if( shader == _shaderList[i].get() ) - { - shader->removeProgramRef( this ); - _shaderList[i] = 0; - dirtyProgram(); - return true; - } + if( shader == _shaderList[i].get() ) + { + shader->removeProgramRef( this ); + _shaderList[i] = 0; + dirtyProgram(); + return true; + } } return false; } @@ -2049,22 +2049,22 @@ void Program::apply( osg::State& state ) const if( isFixedFunction() ) { - extensions->glUseProgram( 0 ); + extensions->glUseProgram( 0 ); state.setLastAppliedProgramObject(0); - return; + return; } PerContextProgram* pcp = getPCP( contextID ); if( pcp->needsLink() ) compileGLObjects( state ); if( pcp->isLinked() ) { - pcp->useProgram(); + pcp->useProgram(); state.setLastAppliedProgramObject(pcp); } else { - // program not usable, fallback to fixed function. - extensions->glUseProgram( 0 ); + // program not usable, fallback to fixed function. + extensions->glUseProgram( 0 ); state.setLastAppliedProgramObject(0); } } @@ -2074,13 +2074,13 @@ Program::PerContextProgram* Program::getPCP(unsigned int contextID) const { if( ! _pcpList[contextID].valid() ) { - _pcpList[contextID] = new PerContextProgram( this, contextID ); + _pcpList[contextID] = new PerContextProgram( this, contextID ); - // attach all PCSs to this new PCP - for( unsigned int i=0; i < _shaderList.size(); ++i ) - { - _shaderList[i]->attachShader( contextID, _pcpList[contextID]->getHandle() ); - } + // attach all PCSs to this new PCP + for( unsigned int i=0; i < _shaderList.size(); ++i ) + { + _shaderList[i]->attachShader( contextID, _pcpList[contextID]->getHandle() ); + } } return _pcpList[contextID].get(); } @@ -2095,9 +2095,9 @@ bool Program::isFixedFunction() const } -void Program::getGlProgramInfoLog(unsigned int contextID, std::string& log) const +bool Program::getGlProgramInfoLog(unsigned int contextID, std::string& log) const { - getPCP( contextID )->getInfoLog( log ); + return getPCP( contextID )->getInfoLog( log ); } /////////////////////////////////////////////////////////////////////////// @@ -2106,8 +2106,8 @@ void Program::getGlProgramInfoLog(unsigned int contextID, std::string& log) cons /////////////////////////////////////////////////////////////////////////// Program::PerContextProgram::PerContextProgram(const Program* program, unsigned int contextID ) : - osg::Referenced(), - _contextID( contextID ) + osg::Referenced(), + _contextID( contextID ) { _program = program; _extensions = GL2Extensions::Get( _contextID, true ); @@ -2138,12 +2138,15 @@ void Program::PerContextProgram::linkProgram() << " id=" << _glProgramHandle << std::endl; + _uniformLocationMap.clear(); + _attribLocationMap.clear(); + // set any explicit vertex attribute bindings const AttribBindingList& bindlist = _program->getAttribBindingList(); for( AttribBindingList::const_iterator itr = bindlist.begin(); itr != bindlist.end(); ++itr ) { - _extensions->glBindAttribLocation( _glProgramHandle, itr->second, itr->first.c_str() ); + _extensions->glBindAttribLocation( _glProgramHandle, itr->second, itr->first.c_str() ); } // link the glProgram @@ -2153,13 +2156,20 @@ void Program::PerContextProgram::linkProgram() _isLinked = (linked == GL_TRUE); if( ! _isLinked ) { - // link failed - std::string infoLog; - getInfoLog( infoLog ); - osg::notify(osg::WARN) << "glLinkProgram FAILED:\n" << infoLog << std::endl; - return; + osg::notify(osg::WARN) << "glLinkProgram \"" + << _program->getName() << "\" FAILED" << std::endl; } + std::string infoLog; + if( getInfoLog(infoLog) ) + { + osg::notify(osg::INFO) << "Program \"" + << _program->getName() << "\" infolog:\n" << infoLog << std::endl; + } + + // dont build maps if link failed + if( ! _isLinked ) return; + // build _uniformLocationMap GLint numUniforms = 0; GLsizei maxLen = 0; @@ -2167,19 +2177,19 @@ void Program::PerContextProgram::linkProgram() _extensions->glGetProgramiv( _glProgramHandle, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLen ); if( (numUniforms > 0) && (maxLen > 1) ) { - GLint size = 0; - GLenum type = 0; - GLchar* name = new GLchar[maxLen]; + GLint size = 0; + GLenum type = 0; + GLchar* name = new GLchar[maxLen]; - for( GLint i = 0; i < numUniforms; ++i ) - { - _extensions->glGetActiveUniform( _glProgramHandle, - i, maxLen, 0, &size, &type, name ); + for( GLint i = 0; i < numUniforms; ++i ) + { + _extensions->glGetActiveUniform( _glProgramHandle, + i, maxLen, 0, &size, &type, name ); - GLint loc = _extensions->glGetUniformLocation( _glProgramHandle, name ); + GLint loc = _extensions->glGetUniformLocation( _glProgramHandle, name ); - if( loc != -1 ) - { + if( loc != -1 ) + { _uniformLocationMap[name] = loc; osg::notify(osg::INFO) @@ -2187,9 +2197,9 @@ void Program::PerContextProgram::linkProgram() << " loc="<< loc << " type=" << Uniform::getTypename((Uniform::Type)type) << std::endl; - } - } - delete [] name; + } + } + delete [] name; } // build _attribLocationMap @@ -2198,35 +2208,35 @@ void Program::PerContextProgram::linkProgram() _extensions->glGetProgramiv( _glProgramHandle, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLen ); if( (numAttrib > 0) && (maxLen > 1) ) { - GLint size = 0; - GLenum type = 0; - GLchar* name = new GLchar[maxLen]; + GLint size = 0; + GLenum type = 0; + GLchar* name = new GLchar[maxLen]; - for( GLint i = 0; i < numAttrib; ++i ) - { - _extensions->glGetActiveAttrib( _glProgramHandle, - i, maxLen, 0, &size, &type, name ); + for( GLint i = 0; i < numAttrib; ++i ) + { + _extensions->glGetActiveAttrib( _glProgramHandle, + i, maxLen, 0, &size, &type, name ); - GLint loc = _extensions->glGetAttribLocation( _glProgramHandle, name ); + GLint loc = _extensions->glGetAttribLocation( _glProgramHandle, name ); - if( loc != -1 ) - { + if( loc != -1 ) + { _attribLocationMap[name] = loc; osg::notify(osg::INFO) << "\tAttrib \"" << name << "\"" << " loc=" << loc << std::endl; - } - } - delete [] name; + } + } + delete [] name; } osg::notify(osg::INFO) << std::endl; } -void Program::PerContextProgram::getInfoLog( std::string& infoLog ) const +bool Program::PerContextProgram::getInfoLog( std::string& infoLog ) const { - _extensions->getProgramInfoLog( _glProgramHandle, infoLog ); + return _extensions->getProgramInfoLog( _glProgramHandle, infoLog ); } void Program::PerContextProgram::useProgram() const diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index e2dd23ee5..2499073ce 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -13,7 +13,7 @@ */ /* file: src/osg/Shader.cpp - * author: Mike Weiblen 2005-04-07 + * author: Mike Weiblen 2005-04-29 */ #include @@ -232,10 +232,10 @@ void Shader::attachShader(unsigned int contextID, GLuint program) const } -void Shader::getGlShaderInfoLog(unsigned int contextID, std::string& log) const +bool Shader::getGlShaderInfoLog(unsigned int contextID, std::string& log) const { PerContextShader* pcs = getPCS( contextID ); - if( pcs ) pcs->getInfoLog( log ); + return (pcs) ? pcs->getInfoLog( log ) : false; } @@ -324,17 +324,21 @@ void Shader::PerContextShader::compileShader() _isCompiled = (compiled == GL_TRUE); if( ! _isCompiled ) { - // compile failed - std::string infoLog; - getInfoLog( infoLog ); - osg::notify(osg::WARN) << _shader->getTypename() << - " glCompileShader FAILED:\n" << infoLog << std::endl; + osg::notify(osg::WARN) << _shader->getTypename() << " glCompileShader \"" + << _shader->getName() << "\" FAILED" << std::endl; + } + + std::string infoLog; + if( getInfoLog(infoLog) ) + { + osg::notify(osg::INFO) << _shader->getTypename() << " Shader \"" + << _shader->getName() << "\" infolog:\n" << infoLog << std::endl; } } -void Shader::PerContextShader::getInfoLog( std::string& infoLog ) const +bool Shader::PerContextShader::getInfoLog( std::string& infoLog ) const { - _extensions->getShaderInfoLog( _glShaderHandle, infoLog ); + return _extensions->getShaderInfoLog( _glShaderHandle, infoLog ); } void Shader::PerContextShader::attachShader(GLuint program) const