Adds GL::activeTexture()

`GL::activeTexture()` is the cached version of `glActiveTexture`
All code must use it.
This commit is contained in:
Ricardo Quesada 2014-01-16 13:44:18 -08:00
parent a724fd9f6a
commit ce633b44ab
3 changed files with 28 additions and 7 deletions

View File

@ -1,13 +1,15 @@
cocos2d-x-3.0final ?.? ? cocos2d-x-3.0final ?.? ?
[All] [All]
[NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier.
[NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands
[NEW] GLCache: glActiveTexture() is cached with GL::activeTexture(). All code MUST call the cached version in order to work correctly
[NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use.
[NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10%
[FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work. [FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work.
[FIX] Crash if file doesn't exist when using FileUtils::getStringFromFile. [FIX] Crash if file doesn't exist when using FileUtils::getStringFromFile.
[FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong. [FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong.
[NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use.
[FIX] Label: Crash when using unknown characters. [FIX] Label: Crash when using unknown characters.
[NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands
[NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier.
[NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10%
[FIX] Console: log(format, va_args) is private to prevent possible resolution errors [FIX] Console: log(format, va_args) is private to prevent possible resolution errors
[FIX] Configuration: dumpInfo() -> getInfo() [FIX] Configuration: dumpInfo() -> getInfo()
[FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlSlider doesn't support to set selected thumb sprite.
@ -17,7 +19,7 @@ cocos2d-x-3.0final ?.? ?
[FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20% [FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20%
[FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well [FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well
[FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: TestCpp works with CMake on Windows.
[FIX] Tests: Sprites Performance Test has 3 new tests [FIX] Tests: Sprites Performance Test has 4 new tests
[FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected
[FIX] TextureCache: dumpCachedTextureInfo() -> getCachedTextureInfo() [FIX] TextureCache: dumpCachedTextureInfo() -> getCachedTextureInfo()
[FIX] Websocket doesn't support send/receive data which larger than 4096 bytes. [FIX] Websocket doesn't support send/receive data which larger than 4096 bytes.

View File

@ -44,7 +44,6 @@ namespace
static bool s_vertexAttribColor = false; static bool s_vertexAttribColor = false;
static bool s_vertexAttribTexCoords = false; static bool s_vertexAttribTexCoords = false;
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
#define kMaxActiveTexture 16 #define kMaxActiveTexture 16
@ -55,6 +54,8 @@ namespace
static GLenum s_blendingDest = -1; static GLenum s_blendingDest = -1;
static int s_GLServerState = 0; static int s_GLServerState = 0;
static GLuint s_VAO = 0; static GLuint s_VAO = 0;
static GLenum s_activeTexture = -1;
#endif // CC_ENABLE_GL_STATE_CACHE #endif // CC_ENABLE_GL_STATE_CACHE
} }
@ -159,7 +160,7 @@ void bindTexture2DN(GLuint textureUnit, GLuint textureId)
if (s_currentBoundTexture[textureUnit] != textureId) if (s_currentBoundTexture[textureUnit] != textureId)
{ {
s_currentBoundTexture[textureUnit] = textureId; s_currentBoundTexture[textureUnit] = textureId;
glActiveTexture(GL_TEXTURE0 + textureUnit); activeTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, textureId); glBindTexture(GL_TEXTURE_2D, textureId);
} }
#else #else
@ -186,6 +187,18 @@ void deleteTextureN(GLuint textureUnit, GLuint textureId)
glDeleteTextures(1, &textureId); glDeleteTextures(1, &textureId);
} }
void activeTexture(GLenum texture)
{
#if CC_ENABLE_GL_STATE_CACHE
if(s_activeTexture != texture) {
s_activeTexture = texture;
glActiveTexture(s_activeTexture);
}
#else
glActiveTexture(texture);
#endif
}
void bindVAO(GLuint vaoId) void bindVAO(GLuint vaoId)
{ {
if (Configuration::getInstance()->supportsShareableVAO()) if (Configuration::getInstance()->supportsShareableVAO())

View File

@ -129,6 +129,12 @@ void CC_DLL deleteTexture(GLuint textureId);
*/ */
void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId); void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId);
/** Select active texture unit.
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
@since v3.0
*/
void CC_DLL activeTexture(GLenum texture);
/** If the vertex array is not already bound, it binds it. /** If the vertex array is not already bound, it binds it.
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly. If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
@since v2.0.0 @since v2.0.0