mirror of https://github.com/axmolengine/axmol.git
The Renderer is not a singleton
In order to access, you have to get it from the Director `Director::getInstance()->getRenderer()`
This commit is contained in:
parent
9f10054a99
commit
d6be81b7a8
|
@ -149,7 +149,10 @@ bool Director::init(void)
|
|||
_eventDispatcher = new EventDispatcher();
|
||||
//init TextureCache
|
||||
initTextureCache();
|
||||
|
||||
|
||||
// Renderer
|
||||
_renderer = new Renderer;
|
||||
|
||||
// create autorelease pool
|
||||
PoolManager::sharedPoolManager()->push();
|
||||
|
||||
|
@ -169,7 +172,9 @@ Director::~Director(void)
|
|||
CC_SAFE_RELEASE(_scheduler);
|
||||
CC_SAFE_RELEASE(_actionManager);
|
||||
CC_SAFE_RELEASE(_eventDispatcher);
|
||||
|
||||
|
||||
delete _renderer;
|
||||
|
||||
// pop the autorelease pool
|
||||
PoolManager::sharedPoolManager()->pop();
|
||||
PoolManager::purgePoolManager();
|
||||
|
@ -288,7 +293,7 @@ void Director::drawScene()
|
|||
showStats();
|
||||
}
|
||||
|
||||
Renderer::getInstance()->render();
|
||||
_renderer->render();
|
||||
|
||||
kmGLPopMatrix();
|
||||
|
||||
|
@ -368,7 +373,7 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
setGLDefaultValues();
|
||||
}
|
||||
|
||||
Renderer::getInstance()->initGLView();
|
||||
_renderer->initGLView();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
|
@ -1027,6 +1032,12 @@ void Director::setEventDispatcher(EventDispatcher* dispatcher)
|
|||
}
|
||||
}
|
||||
|
||||
Renderer* Director::getRenderer() const
|
||||
{
|
||||
return _renderer;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
|
|
@ -56,6 +56,7 @@ class ActionManager;
|
|||
class EventDispatcher;
|
||||
class TextureCache;
|
||||
class Frustum;
|
||||
class Renderer;
|
||||
|
||||
/**
|
||||
@brief Class that creates and handles the main Window and manages how
|
||||
|
@ -338,7 +339,6 @@ public:
|
|||
|
||||
Frustum* getFrustum() const { return _cullingFrustum; }
|
||||
|
||||
public:
|
||||
/** Gets the Scheduler associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
|
@ -368,7 +368,12 @@ public:
|
|||
@since v3.0
|
||||
*/
|
||||
void setEventDispatcher(EventDispatcher* dispatcher);
|
||||
|
||||
|
||||
/** Returns the Renderer
|
||||
@since v3.0
|
||||
*/
|
||||
Renderer* getRenderer() const;
|
||||
|
||||
/* Gets delta time since last tick to main loop */
|
||||
float getDeltaTime() const;
|
||||
|
||||
|
@ -395,16 +400,15 @@ protected:
|
|||
void initTextureCache();
|
||||
void destroyTextureCache();
|
||||
|
||||
protected:
|
||||
/** Scheduler associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
Scheduler* _scheduler;
|
||||
Scheduler *_scheduler;
|
||||
|
||||
/** ActionManager associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
ActionManager* _actionManager;
|
||||
ActionManager *_actionManager;
|
||||
|
||||
/** EventDispatcher associated with this director
|
||||
@since v3.0
|
||||
|
@ -415,7 +419,7 @@ protected:
|
|||
float _deltaTime;
|
||||
|
||||
/* The EGLView, where everything is rendered */
|
||||
EGLView *_openGLView;
|
||||
EGLView *_openGLView;
|
||||
|
||||
//texture cache belongs to this director
|
||||
TextureCache *_textureCache;
|
||||
|
@ -442,7 +446,7 @@ protected:
|
|||
unsigned int _frames;
|
||||
float _secondsPerFrame;
|
||||
|
||||
Frustum* _cullingFrustum;
|
||||
Frustum *_cullingFrustum;
|
||||
|
||||
/* The running scene */
|
||||
Scene *_runningScene;
|
||||
|
@ -452,7 +456,7 @@ protected:
|
|||
Scene *_nextScene;
|
||||
|
||||
/* If true, then "old" scene will receive the cleanup message */
|
||||
bool _sendCleanupToScene;
|
||||
bool _sendCleanupToScene;
|
||||
|
||||
/* scheduled scenes */
|
||||
Vector<Scene*> _scenesStack;
|
||||
|
@ -467,10 +471,10 @@ protected:
|
|||
Projection _projection;
|
||||
|
||||
/* window size in points */
|
||||
Size _winSizeInPoints;
|
||||
Size _winSizeInPoints;
|
||||
|
||||
/* content scale factor */
|
||||
float _contentScaleFactor;
|
||||
float _contentScaleFactor;
|
||||
|
||||
/* store the fps string */
|
||||
char *_FPS;
|
||||
|
@ -480,6 +484,8 @@ protected:
|
|||
|
||||
/* Projection protocol delegate */
|
||||
DirectorDelegate *_projectionDelegate;
|
||||
|
||||
Renderer *_renderer;
|
||||
|
||||
// EGLViewProtocol will recreate stats labels to fit visible rect
|
||||
friend class EGLViewProtocol;
|
||||
|
|
|
@ -704,7 +704,7 @@ void LayerColor::draw()
|
|||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void LayerColor::onDraw()
|
||||
|
|
|
@ -423,7 +423,7 @@ void ParticleBatchNode::draw(void)
|
|||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
||||
}
|
||||
|
||||
|
|
|
@ -446,7 +446,7 @@ void ParticleSystemQuad::draw()
|
|||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -557,7 +557,7 @@ void ProgressTimer::draw()
|
|||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -673,7 +673,7 @@ void Sprite::draw(void)
|
|||
//TODO implement z order
|
||||
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
|
||||
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
|
||||
Renderer::getInstance()->addCommand(renderCommand);
|
||||
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
void Sprite::updateQuadVertices()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "QuadCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "CustomCommand.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -45,7 +46,7 @@ void NewDrawNode::draw()
|
|||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(NewDrawNode::onDraw, this);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void NewDrawNode::onDraw()
|
||||
|
|
|
@ -60,7 +60,7 @@ void NewLabelAtlas::draw()
|
|||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ void NewRenderTexture::draw()
|
|||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
|
||||
Renderer::getInstance()->addCommand(clearCmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
|
||||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
@ -109,7 +109,7 @@ void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float
|
|||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
|
||||
Renderer::getInstance()->addCommand(clearCmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::begin()
|
||||
|
@ -125,14 +125,15 @@ void NewRenderTexture::begin()
|
|||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0, _vertexZ);
|
||||
|
||||
Renderer::getInstance()->addCommand(groupCommand);
|
||||
Renderer::getInstance()->pushGroup(groupCommand->getRenderQueueID());
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(groupCommand);
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beginCmd->init(0, _vertexZ);
|
||||
beginCmd->func = CC_CALLBACK_0(NewRenderTexture::onBegin, this);
|
||||
|
||||
Renderer::getInstance()->addCommand(beginCmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(beginCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::end()
|
||||
|
@ -141,9 +142,9 @@ void NewRenderTexture::end()
|
|||
endCmd->init(0, _vertexZ);
|
||||
endCmd->func = CC_CALLBACK_0(NewRenderTexture::onEnd, this);
|
||||
|
||||
Renderer::getInstance()->addCommand(endCmd);
|
||||
|
||||
Renderer::getInstance()->popGroup();
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(endCmd);
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
void NewRenderTexture::onBegin()
|
||||
|
@ -263,7 +264,7 @@ void NewRenderTexture::clearDepth(float depthValue)
|
|||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(NewRenderTexture::onClearDepth, this);
|
||||
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
|
||||
this->end();
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ void NewSprite::draw(void)
|
|||
return;
|
||||
}
|
||||
|
||||
Renderer::getInstance()->addCommand(renderCommand);
|
||||
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
bool NewSprite::culling() const
|
||||
|
|
|
@ -77,7 +77,7 @@ void NewSpriteBatchNode::draw()
|
|||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "GroupCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
RenderCommandPool<GroupCommand> GroupCommand::_commandPool;
|
||||
|
@ -53,7 +54,7 @@ int GroupCommandManager::getGroupID()
|
|||
|
||||
//Create new ID
|
||||
// int newID = _groupMapping.size();
|
||||
int newID = Renderer::getInstance()->createRenderQueue();
|
||||
int newID = Director::getInstance()->getRenderer()->createRenderQueue();
|
||||
_groupMapping[newID] = true;
|
||||
|
||||
return newID;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "Renderer.h"
|
||||
#include "CustomCommand.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -79,7 +80,7 @@ void NewClippingNode::visit()
|
|||
{
|
||||
//Add group command
|
||||
|
||||
Renderer* renderer = Renderer::getInstance();
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
|
|
|
@ -17,25 +17,8 @@
|
|||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
static Renderer* s_instance = nullptr;
|
||||
|
||||
Renderer *Renderer::getInstance()
|
||||
{
|
||||
if(!s_instance)
|
||||
{
|
||||
s_instance = new Renderer();
|
||||
if(!s_instance->init())
|
||||
{
|
||||
CC_SAFE_DELETE(s_instance);
|
||||
}
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void Renderer::destroyInstance()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_instance);
|
||||
}
|
||||
#define DEFAULT_RENDER_QUEUE 0
|
||||
|
||||
Renderer::Renderer()
|
||||
:_lastMaterialID(0)
|
||||
|
@ -64,11 +47,6 @@ Renderer::~Renderer()
|
|||
}
|
||||
}
|
||||
|
||||
bool Renderer::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::initGLView()
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
|
@ -94,7 +72,7 @@ void Renderer::onBackToForeground(Object* obj)
|
|||
|
||||
void Renderer::setupIndices()
|
||||
{
|
||||
for( int i=0; i < VBO_SIZE; i++)
|
||||
for( int i=0; i < vbo_size; i++)
|
||||
{
|
||||
_indices[i*6+0] = (GLushort) (i*4+0);
|
||||
_indices[i*6+1] = (GLushort) (i*4+1);
|
||||
|
@ -125,7 +103,7 @@ void Renderer::setupVBOAndVAO()
|
|||
glGenBuffers(2, &_buffersVBO[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * VBO_SIZE, _quads, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * vbo_size, _quads, GL_DYNAMIC_DRAW);
|
||||
|
||||
// vertices
|
||||
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
|
||||
|
@ -140,7 +118,7 @@ void Renderer::setupVBOAndVAO()
|
|||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * VBO_SIZE * 6, _indices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * vbo_size * 6, _indices, GL_STATIC_DRAW);
|
||||
|
||||
// Must unbind the VAO before changing the element buffer.
|
||||
GL::bindVAO(0);
|
||||
|
@ -163,11 +141,11 @@ void Renderer::mapBuffers()
|
|||
GL::bindVAO(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * VBO_SIZE, _quads, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * vbo_size, _quads, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * VBO_SIZE * 6, _indices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * vbo_size * 6, _indices, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
@ -242,9 +220,9 @@ void Renderer::render()
|
|||
QuadCommand* cmd = static_cast<QuadCommand*>(command);
|
||||
|
||||
//Batch quads
|
||||
if(_numQuads + cmd->getQuadCount() > VBO_SIZE)
|
||||
if(_numQuads + cmd->getQuadCount() > vbo_size)
|
||||
{
|
||||
CCASSERT(cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
|
||||
CCASSERT(cmd->getQuadCount() < vbo_size, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
|
||||
|
||||
//Draw batched quads if VBO is full
|
||||
drawBatchedQuads();
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
#define VBO_SIZE 10500
|
||||
#define DEFAULT_RENDER_QUEUE 0
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
typedef std::vector<RenderCommand*> RenderQueue;
|
||||
|
@ -27,12 +24,14 @@ struct RenderStackElement
|
|||
size_t currentIndex;
|
||||
};
|
||||
|
||||
class Renderer : public Object
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
static Renderer* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
static const int vbo_size = 65536 / 6;
|
||||
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
//TODO manage GLView inside Render itself
|
||||
void initGLView();
|
||||
|
||||
|
@ -46,11 +45,7 @@ public:
|
|||
void render();
|
||||
|
||||
protected:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
bool init();
|
||||
|
||||
void setupIndices();
|
||||
//Setup VBO or VAO based on OpenGL extensions
|
||||
void setupBuffer();
|
||||
|
@ -64,7 +59,6 @@ protected:
|
|||
|
||||
void onBackToForeground(Object* obj);
|
||||
|
||||
protected:
|
||||
std::stack<int> _commandGroupStack;
|
||||
|
||||
std::stack<RenderStackElement> _renderStack;
|
||||
|
@ -75,8 +69,8 @@ protected:
|
|||
size_t _firstCommand;
|
||||
size_t _lastCommand;
|
||||
|
||||
V3F_C4B_T2F_Quad _quads[VBO_SIZE];
|
||||
GLushort _indices[6 * VBO_SIZE];
|
||||
V3F_C4B_T2F_Quad _quads[vbo_size];
|
||||
GLushort _indices[6 * vbo_size];
|
||||
GLuint _quadVAO;
|
||||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ void BatchNode::draw()
|
|||
}
|
||||
else
|
||||
{
|
||||
Renderer::getInstance()->popGroup();
|
||||
Director::getInstance()->getRenderer()->popGroup();
|
||||
_popGroupCommand = true;
|
||||
|
||||
((Node *)object)->visit();
|
||||
|
@ -156,7 +156,7 @@ void BatchNode::draw()
|
|||
|
||||
void BatchNode::generateGroupCommand()
|
||||
{
|
||||
Renderer* renderer = Renderer::getInstance();
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
|
|
Loading…
Reference in New Issue