2013-11-05 01:14:22 +08:00
|
|
|
//
|
|
|
|
// Created by NiTe Luo on 10/31/13.
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-12 03:54:08 +08:00
|
|
|
#ifndef __CC_RENDERER_H_
|
|
|
|
#define __CC_RENDERER_H_
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
#include "CCPlatformMacros.h"
|
|
|
|
#include "RenderCommand.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
|
|
|
|
2013-11-05 01:14:22 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-12-17 15:32:24 +08:00
|
|
|
typedef std::vector<RenderCommand*> RenderQueue;
|
2013-11-14 09:31:12 +08:00
|
|
|
|
|
|
|
struct RenderStackElement
|
|
|
|
{
|
|
|
|
int renderQueueID;
|
|
|
|
size_t currentIndex;
|
|
|
|
};
|
|
|
|
|
2013-12-18 09:50:17 +08:00
|
|
|
class Renderer
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-12-18 09:50:17 +08:00
|
|
|
static const int vbo_size = 65536 / 6;
|
|
|
|
|
|
|
|
Renderer();
|
|
|
|
~Renderer();
|
|
|
|
|
2013-11-22 08:36:19 +08:00
|
|
|
//TODO manage GLView inside Render itself
|
|
|
|
void initGLView();
|
|
|
|
|
2013-11-08 02:09:53 +08:00
|
|
|
//TODO support multiple viewport
|
2013-11-16 09:32:29 +08:00
|
|
|
void addCommand(RenderCommand* command);
|
|
|
|
void addCommand(RenderCommand* command, int renderQueue);
|
2013-11-21 03:05:01 +08:00
|
|
|
void pushGroup(int renderQueueID);
|
|
|
|
void popGroup();
|
|
|
|
|
2013-11-16 03:29:11 +08:00
|
|
|
int createRenderQueue();
|
2013-11-05 01:14:22 +08:00
|
|
|
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();
|
|
|
|
|
2013-11-22 08:36:19 +08:00
|
|
|
void drawBatchedQuads();
|
2013-11-09 04:06:39 +08:00
|
|
|
//Draw the previews queued quads and flush previous context
|
|
|
|
void flush();
|
|
|
|
|
2013-12-17 14:18:41 +08:00
|
|
|
void onBackToForeground(Object* obj);
|
2013-12-05 09:02:02 +08:00
|
|
|
|
2013-12-17 15:32:24 +08:00
|
|
|
std::stack<int> _commandGroupStack;
|
2013-11-21 03:05:01 +08:00
|
|
|
|
2013-12-17 15:32:24 +08:00
|
|
|
std::stack<RenderStackElement> _renderStack;
|
|
|
|
std::vector<RenderQueue> _renderGroups;
|
2013-11-14 09:31:12 +08:00
|
|
|
|
2013-11-08 02:09:53 +08:00
|
|
|
int _lastMaterialID;
|
2013-11-08 08:50:53 +08:00
|
|
|
|
2013-11-11 16:14:29 +08:00
|
|
|
size_t _firstCommand;
|
|
|
|
size_t _lastCommand;
|
|
|
|
|
2013-12-18 09:50:17 +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;
|
2013-11-22 08:36:19 +08:00
|
|
|
|
|
|
|
bool _glViewAssigned;
|
2013-11-05 01:14:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2013-11-12 03:54:08 +08:00
|
|
|
#endif //__CC_RENDERER_H_
|