axmol/cocos/renderer/CCGLProgramState.h

324 lines
10 KiB
C
Raw Normal View History

2014-05-08 11:20:19 +08:00
/****************************************************************************
Copyright 2014 Chukong Technologies 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.
****************************************************************************/
#ifndef __CCGLPROGRAMSTATE_H__
#define __CCGLPROGRAMSTATE_H__
Squashed commit of the following: commit a794d107ad85667e3d754f0b6251fc864dfbf288 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 14:33:49 2014 -0700 Yeah... everything compiles on win32 and wp8 commit 4740be6e4a0d16f742c27996e7ab2c100adc76af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:58:38 2014 -0700 CCIME moved to base and compiles on Android commit ff3e1bf1eb27a01019f4e1b56d1aebbe2d385f72 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:02:57 2014 -0700 compiles Ok for Windows Phone 8 commit 8160a4eb2ecdc61b5bd1cf56b90d2da6f11e3ebd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 12:25:31 2014 -0700 fixes for Windows Phone 8 commit 418197649efc93032aee0adc205e502101cdb53d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 11:15:13 2014 -0700 Compiles on Win32 commit 08813ed7cf8ac1079ffadeb1ce78ea9e833e1a33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 10:08:31 2014 -0700 Compiles on linux! commit 118896521e5b335a5257090b6863f1fb2a2002fe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 09:30:42 2014 -0700 moves cocos/2d/platform -> cocos/platform commit 4fe9319d7717b0c1bccb2db0156eeb86255a89e0 Merge: bd68ec2 511295e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 08:24:41 2014 -0700 Merge remote-tracking branch 'cocos2d/v3' into files commit bd68ec2f0e3a826d8b2f4b60564ba65ce766bc56 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu May 15 19:36:23 2014 -0700 files in the correct directory
2014-05-17 05:36:00 +08:00
#include <unordered_map>
2014-05-08 11:20:19 +08:00
#include "base/ccTypes.h"
#include "base/CCVector.h"
Squashed commit of the following: commit a794d107ad85667e3d754f0b6251fc864dfbf288 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 14:33:49 2014 -0700 Yeah... everything compiles on win32 and wp8 commit 4740be6e4a0d16f742c27996e7ab2c100adc76af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:58:38 2014 -0700 CCIME moved to base and compiles on Android commit ff3e1bf1eb27a01019f4e1b56d1aebbe2d385f72 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:02:57 2014 -0700 compiles Ok for Windows Phone 8 commit 8160a4eb2ecdc61b5bd1cf56b90d2da6f11e3ebd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 12:25:31 2014 -0700 fixes for Windows Phone 8 commit 418197649efc93032aee0adc205e502101cdb53d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 11:15:13 2014 -0700 Compiles on Win32 commit 08813ed7cf8ac1079ffadeb1ce78ea9e833e1a33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 10:08:31 2014 -0700 Compiles on linux! commit 118896521e5b335a5257090b6863f1fb2a2002fe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 09:30:42 2014 -0700 moves cocos/2d/platform -> cocos/platform commit 4fe9319d7717b0c1bccb2db0156eeb86255a89e0 Merge: bd68ec2 511295e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 08:24:41 2014 -0700 Merge remote-tracking branch 'cocos2d/v3' into files commit bd68ec2f0e3a826d8b2f4b60564ba65ce766bc56 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu May 15 19:36:23 2014 -0700 files in the correct directory
2014-05-17 05:36:00 +08:00
#include "math/Vec2.h"
#include "math/Vec3.h"
#include "math/Vec4.h"
2014-05-08 11:20:19 +08:00
/**
* @addtogroup support
* @{
*/
2014-05-08 11:20:19 +08:00
NS_CC_BEGIN
class GLProgram;
2014-05-13 14:51:37 +08:00
class Texture2D;
struct Uniform;
struct VertexAttrib;
class EventListenerCustom;
class EventCustom;
2014-05-08 11:20:19 +08:00
2015-03-20 11:24:52 +08:00
/**
2015-03-30 15:47:47 +08:00
* Uniform Value, which is used to store to value send to openGL pipe line by glUniformXXX.
*
* @lua NA
2015-03-20 11:24:52 +08:00
*/
2014-07-14 17:02:06 +08:00
class CC_DLL UniformValue
2014-05-08 11:20:19 +08:00
{
friend class GLProgram;
friend class GLProgramState;
2014-05-08 11:20:19 +08:00
public:
2015-03-27 11:03:21 +08:00
/**
Construtor. The Uniform and Glprogram will be nullptr.
2015-03-20 11:24:52 +08:00
*/
2014-05-08 11:20:19 +08:00
UniformValue();
2015-03-20 11:24:52 +08:00
/**
2015-03-27 11:03:21 +08:00
Construtor with uniform and glprogram.
@param uniform Uniform to apply the value.
@param glprogram Specify the owner GLProgram of this uniform and uniform value.
2015-03-20 11:24:52 +08:00
*/
2015-03-27 11:03:21 +08:00
UniformValue(Uniform *uniform, GLProgram* glprogram);
2015-03-20 11:24:52 +08:00
/**Destructor.*/
2014-05-08 11:20:19 +08:00
~UniformValue();
2015-03-20 11:24:52 +08:00
/**@{
Set data to Uniform value. Generally, there are many type of data could be supported,
2015-03-27 11:03:21 +08:00
including float, int, Vec2/3/4, Mat4.
2015-03-20 11:24:52 +08:00
@param value Value to be sent, support float, int, Vec2/3/4, Mat4.
*/
2014-05-13 15:10:01 +08:00
void setFloat(float value);
void setInt(int value);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void setVec2(const Vec2& value);
void setVec3(const Vec3& value);
void setVec4(const Vec4& value);
void setMat4(const Mat4& value);
2015-03-20 11:24:52 +08:00
/**
@}
*/
2015-03-27 11:03:21 +08:00
/**
Set call back to uniform value, which could be used for array and struct.
@param callback Callback function to send data to OpenGL pipeline.
*/
void setCallback(const std::function<void(GLProgram*, Uniform*)> &callback);
/**
Set texture to uniform value.
2015-03-27 11:05:01 +08:00
@param textureId The texture handle.
2015-03-27 11:03:21 +08:00
@param textureUnit The binding texture unit to be used in shader.
*/
void setTexture(GLuint textureId, GLuint textureUnit);
2015-03-20 11:24:52 +08:00
/**Apply the uniform value to openGL pipeline.*/
2014-05-08 11:20:19 +08:00
void apply();
protected:
2015-03-20 11:24:52 +08:00
/**Weak reference to Uniform.*/
Uniform* _uniform;
/**Weak reference to GLprogram.*/
GLProgram* _glprogram;
/**Whether or not callback is used.*/
2014-05-08 11:20:19 +08:00
bool _useCallback;
2015-03-20 11:24:52 +08:00
/**
@name Uniform Value Uniform
@{
*/
2014-05-08 11:20:19 +08:00
union U{
2014-05-13 15:10:01 +08:00
float floatValue;
int intValue;
float v2Value[2];
float v3Value[3];
float v4Value[4];
float matrixValue[16];
2014-05-13 14:51:37 +08:00
struct {
GLuint textureId;
GLuint textureUnit;
} tex;
2014-06-11 14:05:35 +08:00
std::function<void(GLProgram*, Uniform*)> *callback;
2014-05-10 05:38:36 +08:00
2014-05-08 11:20:19 +08:00
U() { memset( this, 0, sizeof(*this) ); }
~U(){}
U& operator=( const U& other ) {
memcpy(this, &other, sizeof(*this));
return *this;
}
} _value;
2015-03-20 11:24:52 +08:00
/**
@}
*/
2014-05-08 11:20:19 +08:00
};
2015-03-30 15:47:47 +08:00
/**
* Vertex Attribute Value, which is an abstraction of VertexAttribute and data pointer.
*
* @lua NA
*/
2014-07-14 17:02:06 +08:00
class CC_DLL VertexAttribValue
2014-05-08 11:20:19 +08:00
{
friend class GLProgram;
2014-05-09 03:34:26 +08:00
friend class GLProgramState;
2014-05-08 11:20:19 +08:00
public:
/**
2015-03-27 11:03:21 +08:00
Constructor.
@param vertexAttrib VertexAttrib from shader.
*/
2014-05-08 11:20:19 +08:00
VertexAttribValue(VertexAttrib *vertexAttrib);
2015-03-27 11:03:21 +08:00
/**
Constructor.
*/
2014-05-08 11:20:19 +08:00
VertexAttribValue();
2015-03-27 11:03:21 +08:00
/**
Destructor.
*/
2014-05-08 11:20:19 +08:00
~VertexAttribValue();
/**
Set the data pointer, which is similar as glVertexAttribPointer.
@param size The number of type in the vertex attribute.
@param type The type of data in vertex attribute.
@param normalized If true, 0-255 data will be mapped to 0.0-1.0.
@param stride The number of bytes if an interleaved vertex array is used. 0 means array is not interleaved.
@param pointer The pointer to the vertex data.
*/
2014-05-09 03:34:26 +08:00
void setPointer(GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer);
/**Set a user call back for set VertexAttrib array.*/
void setCallback(const std::function<void(VertexAttrib*)> &callback);
/**Apply the vertex attribute to the openGL pipeline.*/
2014-05-08 11:20:19 +08:00
void apply();
protected:
VertexAttrib* _vertexAttrib; // weak ref
bool _useCallback;
bool _enabled;
2014-05-08 11:20:19 +08:00
union U{
struct {
GLint size;
GLenum type;
GLboolean normalized;
GLsizei stride;
GLvoid *pointer;
} pointer;
2014-05-10 04:24:56 +08:00
std::function<void(VertexAttrib*)> *callback;
2014-05-08 11:20:19 +08:00
U() { memset( this, 0, sizeof(*this) ); }
~U(){}
U& operator=( const U& other ) {
memcpy(this, &other, sizeof(*this));
return *this;
}
} _value;
};
2014-05-10 09:39:25 +08:00
/**
GLProgramState holds the 'state' (uniforms and attributes) of the GLProgram.
A GLProgram can be used by thousands of Nodes, but if different uniform values
are going to be used, then each node will need its own GLProgramState
*/
2014-07-14 17:02:06 +08:00
class CC_DLL GLProgramState : public Ref
2014-05-08 11:20:19 +08:00
{
2014-05-09 12:54:49 +08:00
friend class GLProgramStateCache;
2014-05-08 11:20:19 +08:00
public:
2014-05-10 09:39:25 +08:00
/** returns a new instance of GLProgramState for a given GLProgram */
static GLProgramState* create(GLProgram* glprogram);
/** gets-or-creates an instance of GLProgramState for a given GLProgram */
2014-05-14 09:12:58 +08:00
static GLProgramState* getOrCreateWithGLProgram(GLProgram* glprogram);
2014-05-10 09:39:25 +08:00
/** gets-or-creates an instance of GLProgramState for a given GLProgramName */
static GLProgramState* getOrCreateWithGLProgramName(const std::string &glProgramName );
2014-05-08 11:20:19 +08:00
2015-03-27 11:03:21 +08:00
/**
Apply GLProgram, attributes and uniforms.
2015-03-27 11:03:21 +08:00
@param modelView The applied modelView matrix to shader.
*/
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void apply(const Mat4& modelView);
2015-03-27 11:03:21 +08:00
/**
Apply GLProgram, and built in uniforms.
@param modelView The applied modelView matrix to shader.
*/
2014-06-24 19:45:51 +08:00
void applyGLProgram(const Mat4& modelView);
2015-03-27 11:03:21 +08:00
/**
Apply attributes.
@param applyAttribFlags Call GL::enableVertexAttribs(_vertexAttribsFlags) or not.
*/
2014-06-25 17:36:55 +08:00
void applyAttributes(bool applyAttribFlags = true);
2015-03-27 11:03:21 +08:00
/**
Apply user defined uniforms.
*/
2014-06-24 19:45:51 +08:00
void applyUniforms();
/**@{
Setter and Getter of the owner GLProgram binded in this program state.
*/
2014-05-09 03:34:26 +08:00
void setGLProgram(GLProgram* glprogram);
GLProgram* getGLProgram() const { return _glprogram; }
/**@}*/
/** Get the flag of vertex attribs used by OR operation.*/
uint32_t getVertexAttribsFlags() const { return _vertexAttribsFlags; }
/**Get the number of vertex attributes.*/
ssize_t getVertexAttribCount() const { return _attributes.size(); }
/**@{
Set the vertex attribute value.
*/
void setVertexAttribCallback(const std::string &name, const std::function<void(VertexAttrib*)> &callback);
2014-05-09 03:34:26 +08:00
void setVertexAttribPointer(const std::string &name, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer);
/**@}*/
/**Get the number of user defined uniform count.*/
ssize_t getUniformCount() const { return _uniforms.size(); }
/** @{
Setting user defined uniforms by uniform string name in the shader.
*/
2014-05-13 15:10:01 +08:00
void setUniformInt(const std::string &uniformName, int value);
2014-05-13 14:51:37 +08:00
void setUniformFloat(const std::string &uniformName, float value);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void setUniformVec2(const std::string &uniformName, const Vec2& value);
void setUniformVec3(const std::string &uniformName, const Vec3& value);
void setUniformVec4(const std::string &uniformName, const Vec4& value);
void setUniformMat4(const std::string &uniformName, const Mat4& value);
2014-06-11 14:05:35 +08:00
void setUniformCallback(const std::string &uniformName, const std::function<void(GLProgram*, Uniform*)> &callback);
2014-05-13 14:51:37 +08:00
void setUniformTexture(const std::string &uniformName, Texture2D *texture);
void setUniformTexture(const std::string &uniformName, GLuint textureId);
/**@}*/
/** @{
Setting user defined uniforms by uniform location in the shader.
*/
void setUniformInt(GLint uniformLocation, int value);
void setUniformFloat(GLint uniformLocation, float value);
void setUniformVec2(GLint uniformLocation, const Vec2& value);
void setUniformVec3(GLint uniformLocation, const Vec3& value);
void setUniformVec4(GLint uniformLocation, const Vec4& value);
void setUniformMat4(GLint uniformLocation, const Mat4& value);
void setUniformCallback(GLint uniformLocation, const std::function<void(GLProgram*, Uniform*)> &callback);
void setUniformTexture(GLint uniformLocation, Texture2D *texture);
void setUniformTexture(GLint uniformLocation, GLuint textureId);
/**@}*/
2014-05-08 11:20:19 +08:00
protected:
GLProgramState();
~GLProgramState();
bool init(GLProgram* program);
2014-05-09 03:34:26 +08:00
void resetGLProgram();
2014-12-30 11:13:14 +08:00
void updateUniformsAndAttributes();
2014-05-09 03:34:26 +08:00
VertexAttribValue* getVertexAttribValue(const std::string &attributeName);
UniformValue* getUniformValue(const std::string &uniformName);
UniformValue* getUniformValue(GLint uniformLocation);
bool _uniformAttributeValueDirty;
std::unordered_map<std::string, GLint> _uniformsByName;
std::unordered_map<GLint, UniformValue> _uniforms;
2014-05-08 11:20:19 +08:00
std::unordered_map<std::string, VertexAttribValue> _attributes;
std::unordered_map<std::string, int> _boundTextureUnits;
2014-05-09 03:34:26 +08:00
2014-05-13 14:51:37 +08:00
int _textureUnitIndex;
2014-05-09 03:34:26 +08:00
uint32_t _vertexAttribsFlags;
2014-05-08 11:20:19 +08:00
GLProgram *_glprogram;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
EventListenerCustom* _backToForegroundlistener;
#endif
2014-05-08 11:20:19 +08:00
};
NS_CC_END
/**
end of support group
@}
*/
2014-05-08 11:20:19 +08:00
#endif /* __CCGLPROGRAMSTATE_H__ */