2012-03-16 13:42:53 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2011 Ricardo Quesada
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2012-03-16 13:42:53 +08:00
|
|
|
|
|
|
|
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__
|
|
|
|
|
2014-05-10 02:28:06 +08:00
|
|
|
#include <cstdint>
|
|
|
|
|
2014-09-10 07:50:02 +08:00
|
|
|
#include "platform/CCGL.h"
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-11-15 18:34:23 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
2015-06-01 13:43:56 +08:00
|
|
|
* @addtogroup renderer
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class GLProgram;
|
2016-08-03 14:29:34 +08:00
|
|
|
class Texture2D;
|
2013-07-26 09:42:53 +08:00
|
|
|
namespace GL {
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** Vertex attrib flags. */
|
2012-03-12 15:22:03 +08:00
|
|
|
enum {
|
2014-02-08 10:41:02 +08:00
|
|
|
VERTEX_ATTRIB_FLAG_NONE = 0,
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2013-07-25 15:04:13 +08:00
|
|
|
VERTEX_ATTRIB_FLAG_POSITION = 1 << 0,
|
|
|
|
VERTEX_ATTRIB_FLAG_COLOR = 1 << 1,
|
2014-05-13 10:12:56 +08:00
|
|
|
VERTEX_ATTRIB_FLAG_TEX_COORD = 1 << 2,
|
2014-08-05 15:15:17 +08:00
|
|
|
VERTEX_ATTRIB_FLAG_NORMAL = 1 << 3,
|
|
|
|
VERTEX_ATTRIB_FLAG_BLEND_WEIGHT = 1 << 4,
|
|
|
|
VERTEX_ATTRIB_FLAG_BLEND_INDEX = 1 << 5,
|
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = (VERTEX_ATTRIB_FLAG_POSITION | VERTEX_ATTRIB_FLAG_COLOR | VERTEX_ATTRIB_FLAG_TEX_COORD),
|
2012-03-12 15:22:03 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 10:59:04 +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-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL invalidateStateCache(void);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +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-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL useProgram(GLuint program);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +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-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL deleteProgram(GLuint program);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +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-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL blendFunc(GLenum sfactor, GLenum dfactor);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.
|
|
|
|
* @since v2.0.0
|
2012-11-09 12:08:18 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL blendResetToCache(void);
|
2012-11-09 12:08:18 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* Sets the projection matrix as dirty.
|
|
|
|
* @since v2.0.0
|
2012-03-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL setProjectionMatrixDirty(void);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* Will enable the vertex attribs that are passed as flags.
|
|
|
|
* Possible flags:
|
|
|
|
*
|
|
|
|
* * VERTEX_ATTRIB_FLAG_POSITION
|
|
|
|
* * VERTEX_ATTRIB_FLAG_COLOR
|
|
|
|
* * VERTEX_ATTRIB_FLAG_TEX_COORDS
|
|
|
|
*
|
|
|
|
* These flags can be ORed. The flags that are not present, will be disabled.
|
|
|
|
*
|
|
|
|
* @since v2.0.0
|
2012-03-12 15:22:03 +08:00
|
|
|
*/
|
2014-05-09 03:34:26 +08:00
|
|
|
void CC_DLL enableVertexAttribs(uint32_t flags);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* If the texture is not already bound to texture unit 0, it binds it.
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
|
|
|
|
* @since v2.0.0
|
2012-03-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL bindTexture2D(GLuint textureId);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2016-08-03 14:29:34 +08:00
|
|
|
/**
|
|
|
|
* If the texture is not already bound to texture unit 0, it binds it.
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
|
|
|
|
*
|
|
|
|
* @remark: It will bind alpha texture to support ETC1 alpha channel.
|
|
|
|
* @since v3.13
|
|
|
|
*/
|
|
|
|
void CC_DLL bindTexture2D(Texture2D* texture);
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* If the texture is not already bound to a given unit, it binds it.
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
|
|
|
|
* @since v2.1.0
|
2012-03-12 15:22:03 +08:00
|
|
|
*/
|
2015-01-30 17:23:30 +08:00
|
|
|
void CC_DLL bindTexture2DN(GLuint textureUnit, GLuint textureId);
|
|
|
|
|
|
|
|
/** If the texture is not already bound to a given unit, it binds it.
|
2015-03-26 11:59:26 +08:00
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
|
|
|
|
* @since v3.6
|
|
|
|
*/
|
2015-01-30 17:23:30 +08:00
|
|
|
void CC_DLL bindTextureN(GLuint textureUnit, GLuint textureId, GLuint textureType = GL_TEXTURE_2D);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +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-12 15:22:03 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL deleteTexture(GLuint textureId);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* It will delete a given texture. If the texture was bound, it will invalidate the cached for the given texture unit.
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
|
|
|
|
* @since v2.1.0
|
2012-11-09 12:08:18 +08:00
|
|
|
*/
|
2014-06-12 15:22:41 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId);
|
2012-11-09 12:08:18 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* Select active texture unit.
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
|
|
|
|
* @since v3.0
|
2014-01-17 05:44:18 +08:00
|
|
|
*/
|
|
|
|
void CC_DLL activeTexture(GLenum texture);
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/**
|
|
|
|
* If the vertex array is not already bound, it binds it.
|
|
|
|
*
|
|
|
|
* If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
|
|
|
|
* @since v2.0.0
|
2012-11-09 12:08:18 +08:00
|
|
|
*/
|
2013-07-26 09:42:53 +08:00
|
|
|
void CC_DLL bindVAO(GLuint vaoId);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
// end of support group
|
2012-06-20 18:09:11 +08:00
|
|
|
/// @}
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-07-26 09:42:53 +08:00
|
|
|
} // Namespace GL
|
2012-11-15 18:34:23 +08:00
|
|
|
NS_CC_END
|
2012-11-13 11:06:32 +08:00
|
|
|
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
#endif /* __CCGLSTATE_H__ */
|