2012-03-16 13:42:53 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-03-16 13:42:53 +08:00
|
|
|
Copyright (c) 2011 Ricardo Quesada
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
#ifndef __CCGLSTATE_H__
|
|
|
|
#define __CCGLSTATE_H__
|
|
|
|
|
|
|
|
#include "CCGL.h"
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup shaders
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-03-12 15:22:03 +08:00
|
|
|
class CCGLProgram;
|
|
|
|
|
|
|
|
/** vertex attrib flags */
|
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
kCCVertexAttribFlag_None = 0,
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
kCCVertexAttribFlag_Position = 1 << 0,
|
|
|
|
kCCVertexAttribFlag_Color = 1 << 1,
|
|
|
|
kCCVertexAttribFlag_TexCoords = 1 << 2,
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
kCCVertexAttribFlag_PosColorTex = ( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color | kCCVertexAttribFlag_TexCoords ),
|
2012-03-12 15:22:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** GL server side states */
|
|
|
|
typedef enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
// CC_GL_SCISSOR_TEST = 1 << 0,
|
|
|
|
// CC_GL_STENCIL_TEST = 1 << 1,
|
|
|
|
// CC_GL_DEPTH_TEST = 1 << 2,
|
|
|
|
CC_GL_BLEND = 1 << 3,
|
|
|
|
// CC_GL_DITHER = 1 << 4,
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// CC_GL_ALL = ( CC_GL_SCISSOR_TEST | CC_GL_STENCIL_TEST | CC_GL_DEPTH_TEST | CC_GL_BLEND | CC_GL_DITHER ),
|
|
|
|
CC_GL_ALL = ( CC_GL_BLEND ),
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
} ccGLServerState;
|
|
|
|
|
2012-03-15 10:42:22 +08:00
|
|
|
/** @file ccGLStateCache.h
|
2012-03-12 15:22:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** Invalidates the GL state cache.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE it will reset the GL state cache.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLInvalidateStateCache( void );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** Uses the GL program in case program is different than the current one.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLUseProgram( GLuint program );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** Deletes the GL program. If it is the one that is being used, it invalidates it.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLDeleteProgram( GLuint program );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** Uses a blending function in case it not already used.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLBlendFunc(GLenum sfactor, GLenum dfactor);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** sets the projection matrix as dirty
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccSetProjectionMatrixDirty( void );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** Will enable the vertex attribs that are passed as flags.
|
|
|
|
Possible flags:
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
* kCCVertexAttribFlag_Position
|
|
|
|
* kCCVertexAttribFlag_Color
|
|
|
|
* kCCVertexAttribFlag_TexCoords
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
These flags can be ORed. The flags that are not present, will be disabled.
|
|
|
|
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLEnableVertexAttribs( unsigned int flags );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** If the active texture is not textureEnum, then it will active it.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLActiveTexture(GLenum textureEnum );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** Returns the active texture.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glGetIntegerv(GL_ACTIVE_TEXTURE);
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
GLenum CC_DLL ccGLGetActiveTexture( void );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** If the texture is not already bound, it binds it.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLBindTexture2D(GLuint textureId );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** It will delete a given texture. If the texture was bound, it will invalidate the cached.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLDeleteTexture(GLuint textureId);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
/** It will enable / disable the server side GL states.
|
|
|
|
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly.
|
|
|
|
@since v2.0.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
void CC_DLL ccGLEnable( ccGLServerState flags );
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of shaders group
|
|
|
|
/// @}
|
|
|
|
|
2012-03-12 15:22:03 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* __CCGLSTATE_H__ */
|