From Mike Weiblen, Progra/Shader fixes

This commit is contained in:
Robert Osfield
2005-04-30 07:02:02 +00:00
parent 7d69b5e562
commit a5fcddc5e5
4 changed files with 801 additions and 787 deletions

View File

@@ -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<std::string,GLuint> AttribBindingList;
const AttribBindingList& getAttribBindingList() const { return _attribBindingList; }
/** Add an attribute location binding. */
void bindAttribLocation( GLuint index, const char* name );
typedef std::map<std::string,GLuint> 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<GL2Extensions> _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<GL2Extensions> _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<std::string, GLint> 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<PerContextProgram> > _pcpList;
AttribBindingList _attribBindingList;
AttribBindingList _attribBindingList;
typedef std::vector< ref_ptr<Shader> > ShaderList;
ShaderList _shaderList;
typedef std::vector< ref_ptr<Shader> > ShaderList;
ShaderList _shaderList;
private:
Program& operator=(const Program&); // disallowed
Program& operator=(const Program&); // disallowed
};
}

View File

@@ -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<osg::GL2Extensions> _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<osg::GL2Extensions> _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<PerContextShader> > _pcsList;
private:
Shader& operator=(const Shader&); // disallowed
Shader& operator=(const Shader&); // disallowed
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,7 @@
*/
/* file: src/osg/Shader.cpp
* author: Mike Weiblen 2005-04-07
* author: Mike Weiblen 2005-04-29
*/
#include <fstream>
@@ -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