Beispiel #1
0
// Returns true if the texture was found and bound; 
// returns false otherwise.
bool MTextureCache::bind(MObject textureObj, 
						 MTexture::Type type /* = MTexture::RGBA */, 
						 bool mipmapped /* = true */,
 						 GLenum target /* = GL_TEXTURE_2D */)
{
	// Get a reference to the texture, allocating it if necessary.
	MTexture* pTex = texture(textureObj, type, mipmapped, target);

	if (pTex)
	{
		// bind the texture.
		pTex->bind();
	
		return true;
	}
	
	return false;
}
    /**
     * GPUにアップロードを行う
     */
    bool upload(MTexture tex, MDeviceContext context) {
        assert(tex);

        if (!valid()) {
            return false;
        }

        MShaderState state = context->getShaderState();
        int texUnit = -1;
        // バインドされていなければ、テクスチャをバインドする
        if (!tex->isBinded(&texUnit, state)) {
            texUnit = tex->bind(context);
        }

        if (bindUnit != texUnit) {
            glUniform1i(location, texUnit);
            assert_gl();
            bindUnit = texUnit;
            return true;
        }
        return false;
    }