/** Populates the initial values of the uniform, based on the size and type. */ void CC3GLSLUniform::populateInitialValue() { for (GLint vIdx = 0 ; vIdx < _size; vIdx++) { CC3Matrix3x3 m3x3; CC3Matrix4x4 m4x4; switch (_type) { case GL_FLOAT: case GL_FLOAT_VEC2: case GL_FLOAT_VEC3: case GL_FLOAT_VEC4: setVector4( CC3Vector4(0.0f, 0.0f, 0.0f, 1.0f), vIdx ); return; case GL_FLOAT_MAT2: setVector4( CC3Vector4(1.0f, 0.0f, 0.0f, 1.0f), vIdx ); return; case GL_FLOAT_MAT3: CC3Matrix3x3PopulateIdentity(&m3x3); setMatrix3x3( &m3x3, vIdx ); return; case GL_FLOAT_MAT4: CC3Matrix4x4PopulateIdentity(&m4x4); setMatrix4x4( &m4x4, vIdx ); return; case GL_INT: case GL_INT_VEC2: case GL_INT_VEC3: case GL_INT_VEC4: case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: case GL_BOOL: case GL_BOOL_VEC2: case GL_BOOL_VEC3: case GL_BOOL_VEC4: setIntVector4( CC3IntVector4Make(0, 0, 0, 1), vIdx ); return; default: CCAssert(false, "CC3GLSLUniform could not set value because type %s is not understood"/*, stringFromGLEnum(_type).c_str()*/); return; } } }
void CC3GLSLUniform::setIntVector4( const CC3IntVector4& value, GLuint index ) { CCAssert((GLint)index < _size, "CC3GLSLUniform could not set value because index %d is out of bounds"/*, index*/); switch (_type) { case GL_FLOAT: case GL_FLOAT_VEC2: case GL_FLOAT_VEC3: case GL_FLOAT_VEC4: case GL_FLOAT_MAT2: setVector4( CC3Vector4((GLfloat)value.x, (GLfloat)value.y, (GLfloat)value.z, (GLfloat)value.w), index ); return; case GL_FLOAT_MAT3: case GL_FLOAT_MAT4: CCAssert(false, "CC3GLSLUniform attempted to set scalar or vector when matrix type %s expected."/*, stringFromGLEnum(_type).c_str()*/); return; case GL_INT: case GL_BOOL: case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: ((GLint*)m_varValue)[index] = *(GLint*)&value; return; case GL_INT_VEC2: case GL_BOOL_VEC2: ((CC3IntPoint*)m_varValue)[index] = *(CC3IntPoint*)&value; return; case GL_INT_VEC3: case GL_BOOL_VEC3: ((CC3IntVector*)m_varValue)[index] = *(CC3IntVector*)&value; return; case GL_INT_VEC4: case GL_BOOL_VEC4: ((CC3IntVector4*)m_varValue)[index] = value; return; default: CCAssert(false, "CC3GLSLUniform could not set value because type %s is not understood"/*, stringFromGLEnum(_type).c_str()*/); return; } CC3_TRACE("CC3GLSLUniform setting value to (%d, %d, %d, %d)", value.x, value.y, value.z, value.w); }
Material::Material() { // initialise pointers m_baseTexture = 0; m_normalTexture = 0; m_alphaTexture = 0; m_noiseTexture = 0; m_distortionTexture = 0; m_perturbTexture = 0; // initialise colours m_tint = Colour::White; m_specularAmount = 32.0f; // Add Default Data setVector4("BaseColour", D3DXVECTOR4(1,1,1,1)); }
void CC3GLSLUniform::setColor4F( const ccColor4F& value, GLuint index ) { switch (_type) { case GL_FLOAT: case GL_FLOAT_VEC2: case GL_FLOAT_VEC3: case GL_FLOAT_VEC4: case GL_FLOAT_MAT2: setVector4( CC3Vector4(value.r, value.g, value.b, value.a), index ); return; case GL_FLOAT_MAT3: case GL_FLOAT_MAT4: CCAssert(false, "CC3GLSLUniform attempted to set color when matrix type %s expected."/*, stringFromGLEnum(_type).c_str()*/); return; case GL_INT: case GL_BOOL: case GL_INT_VEC2: case GL_BOOL_VEC2: case GL_INT_VEC3: case GL_BOOL_VEC3: case GL_INT_VEC4: case GL_BOOL_VEC4: case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: setColor4B( CCC4BFromCCC4F(value) ); return; default: CCAssert(false, "CC3GLSLUniform could not set value because type %s is not understood"/*, stringFromGLEnum(_type).c_str()*/ ); return; } }
void CC3GLSLUniform::setQuaternion( const CC3Quaternion& value, GLuint index ) { setVector4( value, index ); }
void CC3GLSLUniform::setVector4( const CC3Vector4& value ) { setVector4( value, 0 ); }
void CC3GLSLUniform::setVector( const CC3Vector& value, GLuint index ) { setVector4( CC3Vector4(value.x, value.y, value.z, 1.0f), index ); }
void CC3GLSLUniform::setPoint( const CCPoint& value, GLuint index ) { setVector4( CC3Vector4(value.x, value.y, 0.0f, 1.0f), index ); }
void CC3GLSLUniform::setFloat( GLfloat value, GLuint index ) { setVector4( CC3Vector4(value, 0.0f, 0.0f, 1.0f), index ); }
void MappedValues::fromJson(const Json::Value& root) { Json::Value floats = root["Floats"], ints = root["Ints"], uints = root["Uints"], strings = root["Strings"], vector2s = root["Vector2s"], vector3s = root["Vector3s"], vector4s = root["Vector4s"], matrix2s = root["Matrix2s"], matrix3s = root["Matrix3s"], matrix4s = root["Matrix4s"], textures = root["Textures"]; for (auto i = floats.begin(); i != floats.end(); i++) { setFloat(i.name(), (*i).asFloat()); } for (auto i = ints.begin(); i != ints.end(); i++) { setI32(i.name(), (*i).asInt()); } for (auto i = uints.begin(); i != uints.end(); i++) { setU32(i.name(), (*i).asUInt()); } for (auto i = strings.begin(); i != strings.end(); i++) { setString(i.name(), (*i).asString()); } for (auto i = vector2s.begin(); i != vector2s.end(); i++) { Vector2 vec((*i)[0].asFloat(), (*i)[1].asFloat()); setVector2(i.name(), vec); } for (auto i = vector3s.begin(); i != vector3s.end(); i++) { Vector3 vec((*i)[0].asFloat(), (*i)[1].asFloat(), (*i)[2].asFloat()); setVector3(i.name(), vec); } for (auto i = vector4s.begin(); i != vector4s.end(); i++) { Vector4 vec((*i)[0].asFloat(), (*i)[1].asFloat(), (*i)[2].asFloat(), (*i)[3].asFloat()); setVector4(i.name(), vec); } for (auto i = matrix2s.begin(); i != matrix2s.end(); i++) { Matrix2 mat((*i)[0].asFloat(), (*i)[1].asFloat(), (*i)[2].asFloat(), (*i)[3].asFloat()); setMatrix2(i.name(), mat); } for (auto i = matrix3s.begin(); i != matrix3s.end(); i++) { Matrix3 mat((*i)[0].asFloat(), (*i)[1].asFloat(), (*i)[2].asFloat(), (*i)[3].asFloat(), (*i)[4].asFloat(), (*i)[5].asFloat(), (*i)[6].asFloat(), (*i)[7].asFloat(), (*i)[8].asFloat()); setMatrix3(i.name(), mat); } for (auto i = matrix4s.begin(); i != matrix4s.end(); i++) { Matrix4 mat((*i)[0].asFloat(), (*i)[1].asFloat(), (*i)[2].asFloat(), (*i)[3].asFloat(), (*i)[4].asFloat(), (*i)[5].asFloat(), (*i)[6].asFloat(), (*i)[7].asFloat(), (*i)[8].asFloat(), (*i)[9].asFloat(), (*i)[10].asFloat(), (*i)[11].asFloat(), (*i)[12].asFloat(), (*i)[13].asFloat(), (*i)[14].asFloat(), (*i)[15].asFloat()); setMatrix4(i.name(), mat); } for (auto i = textures.begin(); i != textures.end(); i++) { setTexture(i.name(), resourceManager->fetchTextureLoad((*i).asString())); } }