mirror of https://github.com/axmolengine/axmol.git
Only init render after GLview has been initialized
This commit is contained in:
parent
96d2910a99
commit
43941bcbe0
|
@ -358,6 +358,8 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
setGLDefaultValues();
|
||||
}
|
||||
|
||||
Renderer::getInstance()->initGLView();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// _touchDispatcher->setDispatchEvents(true);
|
||||
|
|
|
@ -75,10 +75,11 @@ int64_t QuadCommand::generateID()
|
|||
void QuadCommand::useMaterial()
|
||||
{
|
||||
_shader->use();
|
||||
//TODO once everything is using world coordinate, we can reduce the uniforms for shaders
|
||||
|
||||
_shader->setUniformsForBuiltins();
|
||||
|
||||
//TODO set blend mode
|
||||
//set blend mode
|
||||
GL::blendFunc(_blendType.src, _blendType.dst);
|
||||
|
||||
//Set texture
|
||||
GL::bindTexture2D(_textureID);
|
||||
|
|
|
@ -39,6 +39,7 @@ Renderer::Renderer()
|
|||
,_numQuads(0)
|
||||
,_firstCommand(0)
|
||||
,_lastCommand(0)
|
||||
,_glViewAssigned(false)
|
||||
{
|
||||
_commandGroupStack.push(DEFAULT_RENDER_QUEUE);
|
||||
|
||||
|
@ -50,15 +51,28 @@ Renderer::Renderer()
|
|||
Renderer::~Renderer()
|
||||
{
|
||||
_renderGroups.clear();
|
||||
|
||||
glDeleteBuffers(2, _buffersVBO);
|
||||
|
||||
// if (Configuration::getInstance()->supportsShareableVAO())
|
||||
// {
|
||||
glDeleteVertexArrays(1, &_VAOname);
|
||||
GL::bindVAO(0);
|
||||
// }
|
||||
}
|
||||
|
||||
bool Renderer::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::initGLView()
|
||||
{
|
||||
setupIndices();
|
||||
|
||||
setupVBOAndVAO();
|
||||
|
||||
return true;
|
||||
_glViewAssigned = true;
|
||||
}
|
||||
|
||||
void Renderer::setupIndices()
|
||||
|
@ -148,6 +162,8 @@ void Renderer::render()
|
|||
|
||||
//TODO setup camera or MVP
|
||||
|
||||
if (_glViewAssigned)
|
||||
{
|
||||
//Process render commands
|
||||
//1. Sort render commands based on ID
|
||||
for (auto it = _renderGroups.begin(); it != _renderGroups.end(); ++it)
|
||||
|
@ -224,6 +240,7 @@ void Renderer::render()
|
|||
_renderStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO give command back to command pool
|
||||
for (size_t j = 0 ; j < _renderGroups.size(); j++)
|
||||
|
@ -232,6 +249,11 @@ void Renderer::render()
|
|||
_renderGroups[j].clear();
|
||||
}
|
||||
|
||||
//Clear the stack incase gl view hasn't been initialized yet
|
||||
while(!_renderStack.empty())
|
||||
{
|
||||
_renderStack.pop();
|
||||
}
|
||||
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
|
||||
_firstCommand = _lastCommand = 0;
|
||||
_lastMaterialID = 0;
|
||||
|
@ -276,17 +298,17 @@ void Renderer::drawBatchedQuads()
|
|||
//Draw quads
|
||||
if(quadsToDraw > 0)
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) quadsToDraw*6, GL_UNSIGNED_SHORT, (GLvoid*) (startQuad*6*sizeof(_indices[0])) );
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
// GL::bindVAO(0);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
startQuad += quadsToDraw;
|
||||
quadsToDraw = 0;
|
||||
}
|
||||
|
||||
//Use new material
|
||||
cmd->useMaterial();
|
||||
// GL::bindVAO(_VAOname);
|
||||
_lastMaterialID = cmd->getMaterialID();
|
||||
}
|
||||
|
||||
|
@ -297,11 +319,13 @@ void Renderer::drawBatchedQuads()
|
|||
//Draw any remaining quad
|
||||
if(quadsToDraw > 0)
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) quadsToDraw*6, GL_UNSIGNED_SHORT, (GLvoid*) (startQuad*6*sizeof(_indices[0])) );
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
//Unbind VAO
|
||||
GL::bindVAO(0);
|
||||
|
||||
_firstCommand = _lastCommand;
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
static Renderer* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
//TODO manage GLView inside Render itself
|
||||
void initGLView();
|
||||
|
||||
//TODO support multiple viewport
|
||||
void addCommand(RenderCommand* command);
|
||||
void addCommand(RenderCommand* command, int renderQueue);
|
||||
|
@ -48,9 +51,10 @@ protected:
|
|||
~Renderer();
|
||||
|
||||
bool init();
|
||||
|
||||
void setupIndices();
|
||||
void setupVBOAndVAO();
|
||||
|
||||
void drawBatchedQuads();
|
||||
//Draw the previews queued quads and flush previous context
|
||||
void flush();
|
||||
|
||||
|
@ -72,7 +76,7 @@ protected:
|
|||
|
||||
int _numQuads;
|
||||
|
||||
void drawBatchedQuads();
|
||||
bool _glViewAssigned;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
Loading…
Reference in New Issue