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-08 07:48:37 +08:00
|
|
|
|
2013-11-13 03:14:34 +08:00
|
|
|
#define VBO_SIZE 1024
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
using namespace std;
|
|
|
|
|
2013-11-08 08:50:53 +08:00
|
|
|
class Renderer : public Object
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Renderer* getInstance();
|
2013-11-08 08:50:53 +08:00
|
|
|
static void destroyInstance();
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-11-08 02:09:53 +08:00
|
|
|
//TODO support multiple viewport
|
2013-11-08 07:48:37 +08:00
|
|
|
void addRenderCommand(RenderCommand* command);
|
2013-11-05 01:14:22 +08:00
|
|
|
void render();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Renderer();
|
2013-11-08 07:48:37 +08:00
|
|
|
~Renderer();
|
|
|
|
|
2013-11-08 08:50:53 +08:00
|
|
|
bool init();
|
|
|
|
void setupIndices();
|
|
|
|
void setupVBOAndVAO();
|
|
|
|
|
2013-11-09 04:06:39 +08:00
|
|
|
//Draw the previews queued quads and flush previous context
|
|
|
|
void flush();
|
|
|
|
|
2013-11-05 01:14:22 +08:00
|
|
|
protected:
|
|
|
|
vector<RenderCommand*> _renderQueue;
|
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;
|
|
|
|
|
|
|
|
V3F_C4B_T2F_Quad _quads[VBO_SIZE];
|
|
|
|
GLushort _indices[6 * VBO_SIZE];
|
2013-11-08 08:50:53 +08:00
|
|
|
GLuint _VAOname;
|
|
|
|
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
|
|
|
|
2013-11-08 07:48:37 +08:00
|
|
|
int _numQuads;
|
2013-11-11 16:14:29 +08:00
|
|
|
|
|
|
|
void drawBatchedQuads();
|
2013-11-05 01:14:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2013-11-12 03:54:08 +08:00
|
|
|
#endif //__CC_RENDERER_H_
|