StelQGLGLSLShader.hpp   StelQGLGLSLShader.hpp 
skipping to change at line 218 skipping to change at line 218
} }
//! Upload the stored uniform variables. //! Upload the stored uniform variables.
//! //!
//! Called when the internally used shader program has been bound, b efore drawing, //! Called when the internally used shader program has been bound, b efore drawing,
//! by the drawVertexBufferBackend() member function of the renderer backend. //! by the drawVertexBufferBackend() member function of the renderer backend.
void uploadUniforms() void uploadUniforms()
{ {
Q_ASSERT_X(bound && state == State_Built, Q_FUNC_INFO, Q_ASSERT_X(bound && state == State_Built, Q_FUNC_INFO,
"uploadUniforms called on a shader that is not bo und"); "uploadUniforms called on a shader that is not bo und");
const unsigned char* data = uniformStorage; void * const * data = uniformStorage;
for (int u = 0; u < uniformCount; u++) for (int u = 0; u < uniformCount; u++)
{ {
const UniformType type = static_cast<UniformType>(un iformTypes[u]); const UniformType type = static_cast<UniformType>(un iformTypes[u]);
switch(type) switch(type)
{ {
case UniformType_float: case UniformType_float:
{ {
const float& value(*reinterpret_cast <const float* const>(data)); const float& value(*reinterpret_cast <const float* const>(data));
program->setUniformValue(uniformName s[u], value); program->setUniformValue(uniformName s[u], value);
break; break;
skipping to change at line 312 skipping to change at line 312
//! //!
//! @see pushUniformStorage //! @see pushUniformStorage
void popUniformStorage() void popUniformStorage()
{ {
Q_ASSERT_X(bound && state == State_Built, Q_FUNC_INFO, Q_ASSERT_X(bound && state == State_Built, Q_FUNC_INFO,
"popUniformStorage() called when the shader is no t bound"); "popUniformStorage() called when the shader is no t bound");
Q_ASSERT_X(uniformStorageStackSize >= 1, Q_FUNC_INFO, Q_ASSERT_X(uniformStorageStackSize >= 1, Q_FUNC_INFO,
"Too many uniform storage stack pops (nothing lef t to pop)"); "Too many uniform storage stack pops (nothing lef t to pop)");
--uniformStorageStackSize; --uniformStorageStackSize;
uniformStorageUsed = uniformStorageUsedStack[uniformStora geStackSize]; uniformStorageUsed = uniformStorageUsedStack[uniformStora geStackSize];
uniformStoragePointer = &(uniformStorage[uniformStorageUsed] );
uniformCount = uniformCountStack[uniformStorageStackSi ze]; uniformCount = uniformCountStack[uniformStorageStackSi ze];
} }
//! Clear all stored uniforms, freeing uniform storage. //! Clear all stored uniforms, freeing uniform storage.
//! //!
//! Called by release(). //! Called by release().
void clearUniforms() void clearUniforms()
{ {
Q_ASSERT_X(bound && state == State_Built, Q_FUNC_INFO, Q_ASSERT_X(bound && state == State_Built, Q_FUNC_INFO,
"clearUniforms() called when the shader is not bo und"); "clearUniforms() called when the shader is not bo und");
// We don't zero out the storage - we'll overwrite it as we add new uniforms. // We don't zero out the storage - we'll overwrite it as we add new uniforms.
uniformStorageUsed = uniformCount = uniformStorageStackSize = 0; uniformStorageUsed = uniformCount = uniformStorageStackSize = 0;
uniformStoragePointer = uniformStorage;
} }
protected: protected:
//! Renderer that created this shader. //! Renderer that created this shader.
class StelQGL2Renderer* renderer; class StelQGL2Renderer* renderer;
//! Vertex shaders that are always linked in (added by the nameless addVertexShader() overload). //! Vertex shaders that are always linked in (added by the nameless addVertexShader() overload).
QVector<QGLShader*> defaultVertexShaders; QVector<QGLShader*> defaultVertexShaders;
//! Optional vertex shaders that may be enabled or disabled. //! Optional vertex shaders that may be enabled or disabled.
skipping to change at line 396 skipping to change at line 394
const bool internal; const bool internal;
//! Storage used for uniform data. //! Storage used for uniform data.
//! //!
//! As we're linking shaders dynamically and the final shader progra m is only //! As we're linking shaders dynamically and the final shader progra m is only
//! bound directly before drawing, we need to delay uniform upload u ntil that //! bound directly before drawing, we need to delay uniform upload u ntil that
//! point. Therefore, setUniformValue_ functions just add data to th is storage. //! point. Therefore, setUniformValue_ functions just add data to th is storage.
//! The data is then uploaded by uploadUniforms(). //! The data is then uploaded by uploadUniforms().
//! //!
//! @see uploadUniforms, clearUniforms, pushUniformStorage //! @see uploadUniforms, clearUniforms, pushUniformStorage
unsigned char uniformStorage [UNIFORM_STORAGE]; void* uniformStorage [UNIFORM_STORAGE / sizeof(void*)];
//! Pointer to uniformStorage[uniformStorageUsed]. Avoids breaking s
trict aliasing.
void* uniformStoragePointer;
//! Types of consecutive uniforms in uniformStorage. //! Types of consecutive uniforms in uniformStorage.
//! //!
//! Needed to interpret uniformStorage data when uploading. //! Needed to interpret uniformStorage data when uploading.
unsigned char uniformTypes [MAX_UNIFORMS]; unsigned char uniformTypes [MAX_UNIFORMS];
//! Names of consecutive uniforms in uniformStorage. //! Names of consecutive uniforms in uniformStorage.
//! //!
//! We don't own these strings, we just have pointers to them. //! We don't own these strings, we just have pointers to them.
//! This means the user code needs to preserve the string until rele ase() is called. //! This means the user code needs to preserve the string until rele ase() is called.
const char* uniformNames [MAX_UNIFORMS]; const char* uniformNames [MAX_UNIFORMS];
//! Bytes in uniformStorage used up at this moment. //! Elements in uniformStorage used up at this moment.
int uniformStorageUsed; int uniformStorageUsed;
//! Number of uniforms in uniformStorage at this moment. //! Number of uniforms in uniformStorage at this moment.
int uniformCount; int uniformCount;
//! Stack of uniformStorageUsed values used with pushUniformStorage/ popUniformStorage. //! Stack of uniformStorageUsed values used with pushUniformStorage/ popUniformStorage.
//! //!
//! @see pushUniformStorage, popUniformStorage //! @see pushUniformStorage, popUniformStorage
unsigned int uniformStorageUsedStack[MAX_UNIFORMS]; unsigned int uniformStorageUsedStack[MAX_UNIFORMS];
//! Stack of uniformCount values used with pushUniformStorage/popUni formStorage. //! Stack of uniformCount values used with pushUniformStorage/popUni formStorage.
//! //!
//! @see pushUniformStorage, popUniformStorage //! @see pushUniformStorage, popUniformStorage
unsigned char uniformCountStack[MAX_UNIFORMS]; unsigned char uniformCountStack[MAX_UNIFORMS];
//! Number of items in uniformStorageUsedStack and uniformCountStack . //! Number of items in uniformStorageUsedStack and uniformCountStack .
int uniformStorageStackSize; int uniformStorageStackSize;
virtual void setUniformValue_(const char* const name, const float va lue) void* setUniformValue_helper(const char* const name, const enum Unif ormType kind)
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, Q_ASSERT_X(bound, Q_FUNC_INFO,
"Trying to set a uniform value with an unbound sh ader"); "Trying to set a uniform value with an unbound sh ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma ny uniforms"); Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma ny uniforms");
Q_ASSERT_X((uniformStorageUsed + sizeof(float)) < UNIFORM_ST ORAGE, Q_FUNC_INFO, Q_ASSERT_X((unsigned)(uniformStorageUsed + UNIFORM_SIZES[kin d]) < (UNIFORM_STORAGE / sizeof uniformStorage[0]), Q_FUNC_INFO,
"Uniform storage exceeded"); "Uniform storage exceeded");
*static_cast<float*>(uniformStoragePointer) = value; void* ret = static_cast<void*>(&uniformStorage[uniformStorag eUsed]);
uniformNames[uniformCount] = name; uniformNames[uniformCount] = name;
uniformTypes[uniformCount++] = UniformType_float; uniformTypes[uniformCount++] = kind;
uniformStorageUsed += sizeof(float); uniformStorageUsed += UNIFORM_SIZES[kind];
uniformStoragePointer = &(uniformStorage[uniformStorageUsed] return ret;
); }
virtual void setUniformValue_(const char* const name, const float va
lue)
{
*static_cast<float*>(setUniformValue_helper(name, UniformTyp
e_float)) = value;
} }
virtual void setUniformValue_(const char* const name, const Vec2f va lue) virtual void setUniformValue_(const char* const name, const Vec2f va lue)
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, *static_cast<Vec2f*>(setUniformValue_helper(name, UniformTyp
"Trying to set a uniform value with an unbound sh e_vec2)) = value;
ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma
ny uniforms");
Q_ASSERT_X((uniformStorageUsed + sizeof(Vec2f)) < UNIFORM_ST
ORAGE, Q_FUNC_INFO,
"Uniform storage exceeded");
*static_cast<Vec2f*>(uniformStoragePointer) = value;
uniformNames[uniformCount] = name;
uniformTypes[uniformCount] = UniformType_vec2;
++uniformCount;
uniformStorageUsed += sizeof(Vec2f);
uniformStoragePointer = &(uniformStorage[uniformStorageUsed]
);
} }
virtual void setUniformValue_(const char* const name, const Vec3f& v alue) virtual void setUniformValue_(const char* const name, const Vec3f& v alue)
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, *static_cast<Vec3f*>(setUniformValue_helper(name, UniformTyp
"Trying to set a uniform value with an unbound sh e_vec3)) = value;
ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma
ny uniforms");
Q_ASSERT_X((uniformStorageUsed + sizeof(Vec3f)) < UNIFORM_ST
ORAGE, Q_FUNC_INFO,
"Uniform storage exceeded");
*static_cast<Vec3f*>(uniformStoragePointer) = value;
uniformNames[uniformCount] = name;
uniformTypes[uniformCount] = UniformType_vec3;
++uniformCount;
uniformStorageUsed += sizeof(Vec3f);
uniformStoragePointer = &(uniformStorage[uniformStorageUsed]
);
} }
virtual void setUniformValue_(const char* const name, const Vec4f& v alue) virtual void setUniformValue_(const char* const name, const Vec4f& v alue)
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, *static_cast<Vec4f*>(setUniformValue_helper(name, UniformTyp
"Trying to set a uniform value with an unbound sh e_vec4)) = value;
ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma
ny uniforms");
*static_cast<Vec4f*>(uniformStoragePointer) = value;
Q_ASSERT_X((uniformStorageUsed + sizeof(Vec4f)) < UNIFORM_ST
ORAGE, Q_FUNC_INFO,
"Uniform storage exceeded");
uniformNames[uniformCount] = name;
uniformTypes[uniformCount] = UniformType_vec4;
++uniformCount;
uniformStorageUsed += sizeof(Vec4f);
uniformStoragePointer = &(uniformStorage[uniformStorageUsed]
);
} }
virtual void setUniformValue_(const char* const name, const Mat4f& m ) virtual void setUniformValue_(const char* const name, const Mat4f& m )
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, *static_cast<Mat4f*>(setUniformValue_helper(name, UniformTyp
"Trying to set a uniform value with an unbound sh e_mat4)) = m;
ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma
ny uniforms");
Q_ASSERT_X((uniformStorageUsed + sizeof(Mat4f)) < UNIFORM_ST
ORAGE, Q_FUNC_INFO,
"Uniform storage exceeded");
*static_cast<Mat4f*>(uniformStoragePointer) = m;
uniformNames[uniformCount] = name;
uniformTypes[uniformCount] = UniformType_mat4;
++uniformCount;
uniformStorageUsed += sizeof(Mat4f);
uniformStoragePointer = &(uniformStorage[uniformStorageUsed]
);
} }
virtual void setUniformValue_(const char* const name, const bool val ue) virtual void setUniformValue_(const char* const name, const bool val ue)
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, *static_cast<bool*>(setUniformValue_helper(name, UniformType
"Trying to set a uniform value with an unbound sh _bool)) = value;
ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma
ny uniforms");
Q_ASSERT_X((uniformStorageUsed + sizeof(bool)) < UNIFORM_STO
RAGE, Q_FUNC_INFO,
"Uniform storage exceeded");
*static_cast<bool*>(uniformStoragePointer) = value;
uniformNames[uniformCount] = name;
uniformTypes[uniformCount] = UniformType_bool;
++uniformCount;
uniformStorageUsed += sizeof(bool);
uniformStoragePointer = &(uniformStorage[uniformStorageUsed]
);
} }
virtual void setUniformValue_(const char* const name, const int valu e) virtual void setUniformValue_(const char* const name, const int valu e)
{ {
Q_ASSERT_X(bound, Q_FUNC_INFO, *static_cast<int*>(setUniformValue_helper(name, UniformType_
"Trying to set a uniform value with an unbound sh int)) = value;
ader");
Q_ASSERT_X(uniformCount < MAX_UNIFORMS, Q_FUNC_INFO, "Too ma
ny uniforms");
Q_ASSERT_X((uniformStorageUsed + sizeof(int)) < UNIFORM_STOR
AGE, Q_FUNC_INFO,
"Uniform storage exceeded");
*static_cast<int*>(uniformStoragePointer) = value;
uniformNames[uniformCount] = name;
uniformTypes[uniformCount] = UniformType_int;
++uniformCount;
uniformStorageUsed += sizeof(int);
uniformStoragePointer = &(uniformStorage[uniformStorageUsed]
);
} }
private: private:
//! Get the vertex program matching currently enabled shaders from c ache. //! Get the vertex program matching currently enabled shaders from c ache.
//! //!
//! If there is no matching program, return NULL. //! If there is no matching program, return NULL.
//! //!
//! @see programCache //! @see programCache
QGLShaderProgram* getProgramFromCache(); QGLShaderProgram* getProgramFromCache();
 End of changes. 15 change blocks. 
106 lines changed or deleted 28 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/