axmol/cocos/2d/renderer/CCRenderer.h

130 lines
3.5 KiB
C
Raw Normal View History

2013-12-18 10:12:15 +08:00
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
2013-12-18 10:12:15 +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.
****************************************************************************/
2013-11-12 03:54:08 +08:00
#ifndef __CC_RENDERER_H_
#define __CC_RENDERER_H_
#include "CCPlatformMacros.h"
2013-12-18 10:41:09 +08:00
#include "CCRenderCommand.h"
#include "CCGLProgram.h"
2013-11-09 04:06:39 +08:00
#include "CCGL.h"
2013-11-12 03:54:08 +08:00
#include <vector>
2013-11-14 09:31:12 +08:00
#include <stack>
2013-11-08 07:48:37 +08:00
NS_CC_BEGIN
class EventListenerCustom;
/** Class that knows how to sort the Commands.
Since the commands that have z==0 are "pushed back" in
the correct order, the only Commands that need to be sorted,
are the ones that have z <0 and z >0.
And that is what this class does.
*/
class RenderQueue {
public:
void push_back(RenderCommand* command);
ssize_t size() const;
void sort();
RenderCommand* operator[](ssize_t index) const;
void clear();
protected:
std::vector<RenderCommand*> _queueNegZ;
std::vector<RenderCommand*> _queue0;
std::vector<RenderCommand*> _queuePosZ;
};
2013-11-14 09:31:12 +08:00
struct RenderStackElement
{
int renderQueueID;
ssize_t currentIndex;
2013-11-14 09:31:12 +08:00
};
class Renderer
{
public:
static const int VBO_SIZE = 65536 / 6;
Renderer();
~Renderer();
//TODO manage GLView inside Render itself
void initGLView();
//TODO support multiple viewport
2013-11-16 09:32:29 +08:00
void addCommand(RenderCommand* command);
void addCommand(RenderCommand* command, int renderQueue);
void pushGroup(int renderQueueID);
void popGroup();
2013-11-16 03:29:11 +08:00
int createRenderQueue();
void render();
protected:
2013-11-08 07:48:37 +08:00
2013-11-08 08:50:53 +08:00
void setupIndices();
2013-12-05 09:02:02 +08:00
//Setup VBO or VAO based on OpenGL extensions
void setupBuffer();
2013-11-08 08:50:53 +08:00
void setupVBOAndVAO();
2013-12-05 09:02:02 +08:00
void setupVBO();
void mapBuffers();
void drawBatchedQuads();
2013-11-09 04:06:39 +08:00
//Draw the previews queued quads and flush previous context
void flush();
void convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView);
std::stack<int> _commandGroupStack;
std::stack<RenderStackElement> _renderStack;
std::vector<RenderQueue> _renderGroups;
2013-11-14 09:31:12 +08:00
uint32_t _lastMaterialID;
2013-11-08 08:50:53 +08:00
ssize_t _firstCommand;
ssize_t _lastCommand;
2013-11-11 16:14:29 +08:00
V3F_C4B_T2F_Quad _quads[VBO_SIZE];
GLushort _indices[6 * VBO_SIZE];
2013-11-23 02:24:52 +08:00
GLuint _quadVAO;
2013-11-08 08:50:53 +08:00
GLuint _buffersVBO[2]; //0: vertex 1: indices
2013-11-08 07:48:37 +08:00
int _numQuads;
bool _glViewAssigned;
#if CC_ENABLE_CACHE_TEXTURE_DATA
EventListenerCustom* _cacheTextureListener;
#endif
};
NS_CC_END
2013-11-12 03:54:08 +08:00
#endif //__CC_RENDERER_H_