diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 98b3f676bc..7008ca8012 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -483a248a4f35f5351b3ffaecb0911023bed1812b \ No newline at end of file +63359196a3b9f69ce5b8c2374708597ae31643e2 \ No newline at end of file diff --git a/cocos/2d/CustomCommand.cpp b/cocos/2d/CustomCommand.cpp new file mode 100644 index 0000000000..ee92cd6bd2 --- /dev/null +++ b/cocos/2d/CustomCommand.cpp @@ -0,0 +1,44 @@ +// +// Created by NiTe Luo on 11/8/13. +// + + +#include "CustomCommand.h" + +NS_CC_BEGIN + +CustomCommand::CustomCommand(int viewport, int32_t depth) +:RenderCommand() +, _viewport(viewport) +, _depth(depth) +, func(nullptr) +{ + _type = CUSTOM_COMMAND; +} + +CustomCommand::~CustomCommand() +{ + +} + +int64_t CustomCommand::generateID() +{ + _id = 0; + + _id = (int64_t)_viewport << 61 + | (int64_t)1 << 60 // translucent + | (int64_t)0 << 59 // is command + | (int64_t)_depth << 35; + + return _id; +} + +void CustomCommand::execute() +{ + if(func) + { + func(); + } +} + +NS_CC_END \ No newline at end of file diff --git a/cocos/2d/CustomCommand.h b/cocos/2d/CustomCommand.h new file mode 100644 index 0000000000..a0f3bcd8ff --- /dev/null +++ b/cocos/2d/CustomCommand.h @@ -0,0 +1,47 @@ +// +// Created by NiTe Luo on 11/8/13. +// + + + +#ifndef _CC_CUSTOMCOMMAND_H_ +#define _CC_CUSTOMCOMMAND_H_ + +#include "RenderCommand.h" + +NS_CC_BEGIN +using namespace std; + +class CustomCommand : public RenderCommand +{ +public: + CustomCommand(int viewport, int32_t depth); + ~CustomCommand(); + + // +----------+----------+-----+-----------------------------------+ + // | | | | | | + // | ViewPort | Transluc | Cmd | Depth | | + // | 3 bits | 1 bit | 1 | 24 bits | | + // +----------+----------+-----+----------------+------------------+ + virtual int64_t generateID(); + + void execute(); + + inline bool isTranslucent() { return true; } + + //TODO support non-graphical command + inline bool isCommand() { return false; } + +public: + function func; + +protected: + int _viewport; + + int32_t _depth; + +}; + +NS_CC_END + +#endif //_CC_CUSTOMCOMMAND_H_ diff --git a/cocos/2d/renderer/RenderCommand.h b/cocos/2d/renderer/RenderCommand.h index 5f9f945ae9..fbc6678ed5 100644 --- a/cocos/2d/renderer/RenderCommand.h +++ b/cocos/2d/renderer/RenderCommand.h @@ -17,7 +17,7 @@ NS_CC_BEGIN enum RenderCommandType { QUAD_COMMAND, - CUSTOMIZE_COMMAND, + CUSTOM_COMMAND, GROUP_COMMAND, UNKNOWN_COMMAND, }; diff --git a/cocos/2d/renderer/Renderer.cpp b/cocos/2d/renderer/Renderer.cpp index 27e21093ad..67078d4894 100644 --- a/cocos/2d/renderer/Renderer.cpp +++ b/cocos/2d/renderer/Renderer.cpp @@ -6,6 +6,8 @@ #include "Renderer.h" #include "CCShaderCache.h" #include "ccGLStateCache.h" +#include "CustomCommand.h" + NS_CC_BEGIN using namespace std; @@ -144,11 +146,12 @@ void Renderer::render() if(_lastMaterialID != cmd->getMaterialID() || _numQuads == VBO_SIZE) { //Draw batched data - if(_numQuads > 0) - { - drawQuads(); - } + drawQuads(); + } + //Reset material if needed. + if(_lastMaterialID != cmd->getMaterialID()) + { //Set new material _lastMaterialID = cmd->getMaterialID(); @@ -161,10 +164,19 @@ void Renderer::render() GL::bindTexture2D(cmd->getTextureID()); } + batchQuads(cmd); break; } + case CUSTOM_COMMAND: + { + flush(); + CustomCommand* cmd = (CustomCommand*)command; + cmd->execute(); + + break; + } default: break; } @@ -179,6 +191,9 @@ void Renderer::render() void Renderer::drawQuads() { + if(_numQuads <= 0) + return; + //Set VBO data glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); @@ -207,4 +222,10 @@ void Renderer::batchQuads(QuadCommand* cmd) _quads[_numQuads - 1] = *cmd->getQuad(); } +void Renderer::flush() +{ + drawQuads(); + _lastMaterialID = 0; +} + NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/Renderer.h b/cocos/2d/renderer/Renderer.h index 9105443281..53f0f0ae2f 100644 --- a/cocos/2d/renderer/Renderer.h +++ b/cocos/2d/renderer/Renderer.h @@ -12,6 +12,7 @@ #include "RenderCommand.h" #include "CCGLProgram.h" #include "QuadCommand.h" +#include "CCGL.h" #define VBO_SIZE 64 @@ -39,11 +40,13 @@ protected: void batchQuads(QuadCommand* cmd); void drawQuads(); + //Draw the previews queued quads and flush previous context + void flush(); + protected: vector _renderQueue; int _lastMaterialID; - V3F_C4B_T2F_Quad*_quads; GLushort* _indices; GLuint _VAOname;