void GLProgramState::setUniformFloat(GLint uniformLocation, float value)
{
    auto v = getUniformValue(uniformLocation);
    if (v)
        v->setFloat(value);
    else
        CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformCallback(GLint uniformLocation, const std::function<void(GLProgram*, Uniform*)> &callback)
{
    auto v = getUniformValue(uniformLocation);
    if (v)
        v->setCallback(callback);
    else
        CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformVec4v(const std::string& uniformName, ssize_t size, const Vec4* value)
{
    auto v = getUniformValue(uniformName);
    if (v)
        v->setVec4v(size, value);
    else
        CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformFloatv(const std::string& uniformName, ssize_t size, const float* pointer)
{
    auto v = getUniformValue(uniformName);
    if (v)
        v->setFloatv(size, pointer);
    else
        CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformMat4(const std::string& uniformName, const Mat4& value)
{
    auto v = getUniformValue(uniformName);
    if (v)
        v->setMat4(value);
    else
        CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformVec4v(GLint uniformLocation, ssize_t size, const Vec4* pointer)
{
    auto v = getUniformValue(uniformLocation);
    if (v)
        v->setVec4v(size, pointer);
    else
        CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformMat4(GLint uniformLocation, const Mat4& value)
{
    auto v = getUniformValue(uniformLocation);
    if (v)
        v->setMat4(value);
    else
        CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformCallback(const std::string& uniformName, const std::function<void(GLProgram*, Uniform*)> &callback)
{
    auto v = getUniformValue(uniformName);
    if (v)
        v->setCallback(callback);
    else
        CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
Esempio n. 9
0
double Matrix::sum() const
{
    if (isUniform()) {
        return getUniformValue() * getShape().getNumEl();
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        const double sum = matty::getDevice(dev)->sum(getArray(dev));
        readUnlock(dev);
        return sum;
    }
}
Esempio n. 10
0
double Matrix::average() const
{
    if (isUniform()) {
        return getUniformValue();
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        const double avg = matty::getDevice(dev)->average(getArray(dev));
        readUnlock(dev);
        return avg;
    }
}
Esempio n. 11
0
double Matrix::minimum() const
{
    if (isUniform()) {
        return getUniformValue();
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        const double min = matty::getDevice(dev)->minimum(getArray(dev));
        readUnlock(dev);
        return min;
    }
}
Esempio n. 12
0
void Matrix::scale(double factor)
{
    if (factor == 0.0) {
        fill(0.0);
    } else if (isUniform()) {
        fill(getUniformValue() * factor);
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        matty::getDevice(dev)->scale(getArray(dev), factor);
        readUnlock(dev);
    }
}
Esempio n. 13
0
void VectorMatrix::normalize(const Matrix &len)
{
	if (isUniform() && len.isUniform()) {
		Vector3d uni = getUniformValue();
		uni.normalize(len.getUniformValue());
		fill(uni);
	} else {
		const int dev = computeStrategy2(len);
		writeLock(dev); len.readLock(dev);
		getDevice(dev)->normalize3(getArray(dev, 0), getArray(dev, 1), getArray(dev, 2), len.getArray(dev));
		len.readUnlock(dev); writeUnlock(dev); 
	}
}
Esempio n. 14
0
void VectorMatrix::scale(double factor)
{
	if (factor == 0.0) {
		fill(Vector3d(0.0, 0.0, 0.0));
	} else if (isUniform()) {
		fill(getUniformValue() * factor);
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->scale(getArray(dev, c), factor);
		}
		readUnlock(dev);
	}
}
Esempio n. 15
0
void VectorMatrix::add(const VectorMatrix &op, double factor)
{
	if (this == &op) {
		scale(1.0 + factor);
	} else if (isUniform() && op.isUniform()) {
		fill(getUniformValue() + op.getUniformValue() * factor);
	} else {
		const int dev = computeStrategy2(op);
		writeLock(dev); op.readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->add(getArray(dev, c), op.getArray(dev, c), factor);
		}
		writeUnlock(dev); op.readUnlock(dev);
	}
}
Esempio n. 16
0
void VectorMatrix::scale(const Vector3d &factors)
{
	if (factors == Vector3d(0.0, 0.0, 0.0)) {
		fill(Vector3d(0.0, 0.0, 0.0));
	} else if (isUniform()) {
		const Vector3d uni = getUniformValue();
		fill(Vector3d(uni.x*factors.x, uni.y*factors.y, uni.z*factors.z));
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		matty::getDevice(dev)->scale(getArray(dev, 0), factors.x);
		matty::getDevice(dev)->scale(getArray(dev, 1), factors.y);
		matty::getDevice(dev)->scale(getArray(dev, 2), factors.z);
		readUnlock(dev);
	}
}
Esempio n. 17
0
Vector3d VectorMatrix::maximum() const
{
	if (isUniform()) {
		return getUniformValue();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		const Vector3d max(
			matty::getDevice(dev)->maximum(getArray(dev, 0)),
			matty::getDevice(dev)->maximum(getArray(dev, 1)),
			matty::getDevice(dev)->maximum(getArray(dev, 2))
		);
		readUnlock(dev);
		return max;
	}
}
Esempio n. 18
0
Vector3d VectorMatrix::average() const
{
	if (isUniform()) {
		return getUniformValue();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		const Vector3d avg(
			matty::getDevice(dev)->average(getArray(dev, 0)),
			matty::getDevice(dev)->average(getArray(dev, 1)),
			matty::getDevice(dev)->average(getArray(dev, 2))
		);
		readUnlock(dev);
		return avg;
	}
}
Esempio n. 19
0
Vector3d VectorMatrix::sum() const
{
	if (isUniform()) {
		return getUniformValue() * getShape().getNumEl();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		
		const Vector3d sum(
			matty::getDevice(dev)->sum(getArray(dev, 0)),
			matty::getDevice(dev)->sum(getArray(dev, 1)),
			matty::getDevice(dev)->sum(getArray(dev, 2))
		);
		readUnlock(dev);
		return sum;
	}
}
void GLProgramState::setUniformTexture(GLint uniformLocation, GLuint textureId)
{
    auto v = getUniformValue(uniformLocation);
    if (v)
    {
        if (_boundTextureUnits.find(v->_uniform->name) != _boundTextureUnits.end())
        {
            v->setTexture(textureId, _boundTextureUnits[v->_uniform->name]);
        }
        else
        {
            v->setTexture(textureId, _textureUnitIndex);
            _boundTextureUnits[v->_uniform->name] = _textureUnitIndex++;
        }
    }
    else
    {
        CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
    }
}
void GLProgramState::setUniformTexture(const std::string& uniformName, GLuint textureId)
{
    auto v = getUniformValue(uniformName);
    if (v)
    {
        if (_boundTextureUnits.find(uniformName) != _boundTextureUnits.end())
        {
            v->setTexture(textureId, _boundTextureUnits[uniformName]);
        }
        else
        {
            v->setTexture(textureId, _textureUnitIndex);
            _boundTextureUnits[uniformName] = _textureUnitIndex++;
        }
    }
    else
    {
        CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
    }
}
Esempio n. 22
0
void GLProgramState::setUniformTexture(const std::string& uniformName, Texture2D *texture)
{
    CCASSERT(texture, "Invalid texture");
    auto v = getUniformValue(uniformName);
    if (v)
    {
        if (_boundTextureUnits.find(uniformName) != _boundTextureUnits.end())
        {
            v->setTexture(texture, _boundTextureUnits[uniformName]);
        }
        else
        {
            v->setTexture(texture, _textureUnitIndex);
            _boundTextureUnits[uniformName] = _textureUnitIndex++;
        }
    }
    else
    {
        CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
    }
}