Refactoring
This commit is contained in:
1 parent
7ccda081b0
commit
928600acd4
9 files changed
+46
-213
No files matched your search
+11
-52
@@ -50,17 +50,14 @@ namespace ZL {
|
||||
|
||||
Matrix4f r;
|
||||
|
||||
// ���������������
|
||||
r.data()[0] = 2.f / width;
|
||||
r.data()[5] = 2.f / height;
|
||||
r.data()[10] = -1.f / depthRange;
|
||||
|
||||
// ��������� �������������� �����������
|
||||
r.data()[1] = r.data()[2] = r.data()[3] = 0;
|
||||
r.data()[4] = r.data()[6] = r.data()[7] = 0;
|
||||
r.data()[8] = r.data()[9] = r.data()[11] = 0;
|
||||
|
||||
// ���������� (��������)
|
||||
r.data()[12] = -(xmax + xmin) / width;
|
||||
r.data()[13] = -(ymax + ymin) / height;
|
||||
r.data()[14] = zNear / depthRange;
|
||||
@@ -703,19 +700,7 @@ namespace ZL {
|
||||
Matrix4f m = Matrix4f::Identity();
|
||||
|
||||
m.block<3, 3>(0, 0) = m3;
|
||||
/*
|
||||
m.m[0] = m3.data()[0];
|
||||
m.m[1] = m3.data()[1];
|
||||
m.m[2] = m3.data()[2];
|
||||
|
||||
m.m[4] = m3.data()[3];
|
||||
m.m[5] = m3.data()[4];
|
||||
m.m[6] = m3.data()[5];
|
||||
|
||||
m.m[8] = m3.data()[6];
|
||||
m.m[9] = m3.data()[7];
|
||||
m.m[10] = m3.data()[8];
|
||||
*/
|
||||
m = ModelviewMatrixStack.top() * m;
|
||||
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
@@ -733,17 +718,7 @@ namespace ZL {
|
||||
void Renderer::RotateMatrix(const Matrix3f& m3)
|
||||
{
|
||||
Matrix4f m = Matrix4f::Identity();
|
||||
/*m.m[0] = m3.data()[0];
|
||||
m.m[1] = m3.data()[1];
|
||||
m.m[2] = m3.data()[2];
|
||||
|
||||
m.m[4] = m3.data()[3];
|
||||
m.m[5] = m3.data()[4];
|
||||
m.m[6] = m3.data()[5];
|
||||
|
||||
m.m[8] = m3.data()[6];
|
||||
m.m[9] = m3.data()[7];
|
||||
m.m[10] = m3.data()[8];*/
|
||||
m.block<3, 3>(0, 0) = m3;
|
||||
|
||||
m = ModelviewMatrixStack.top() * m;
|
||||
@@ -782,22 +757,6 @@ namespace ZL {
|
||||
SetMatrix();
|
||||
}
|
||||
|
||||
|
||||
void Renderer::EnableVertexAttribArray(const std::string& attribName)
|
||||
{
|
||||
|
||||
auto shader = shaderManager.GetCurrentShader();
|
||||
if (shader->attribList.find(attribName) != shader->attribList.end())
|
||||
glEnableVertexAttribArray(shader->attribList[attribName]);
|
||||
}
|
||||
|
||||
void Renderer::DisableVertexAttribArray(const std::string& attribName)
|
||||
{
|
||||
auto shader = shaderManager.GetCurrentShader();
|
||||
if (shader->attribList.find(attribName) != shader->attribList.end())
|
||||
glDisableVertexAttribArray(shader->attribList[attribName]);
|
||||
}
|
||||
|
||||
void Renderer::RenderUniformMatrix3fv(const std::string& uniformName, bool transpose, const float* value)
|
||||
{
|
||||
auto shader = shaderManager.GetCurrentShader();
|
||||
@@ -902,56 +861,56 @@ namespace ZL {
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.normalVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vNormal, 0, NULL);
|
||||
EnableVertexAttribArray(vNormal);
|
||||
//EnableVertexAttribArray(vNormal);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableVertexAttribArray(vNormal);
|
||||
//DisableVertexAttribArray(vNormal);
|
||||
}
|
||||
if (VertexRenderStruct.data.TangentData.size() > 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.tangentVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vTangent, 0, NULL);
|
||||
EnableVertexAttribArray(vTangent);
|
||||
//EnableVertexAttribArray(vTangent);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableVertexAttribArray(vTangent);
|
||||
//DisableVertexAttribArray(vTangent);
|
||||
}
|
||||
if (VertexRenderStruct.data.BinormalData.size() > 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.binormalVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vBinormal, 0, NULL);
|
||||
EnableVertexAttribArray(vBinormal);
|
||||
//EnableVertexAttribArray(vBinormal);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableVertexAttribArray(vBinormal);
|
||||
//DisableVertexAttribArray(vBinormal);
|
||||
}
|
||||
if (VertexRenderStruct.data.ColorData.size() > 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.colorVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vColor, 0, NULL);
|
||||
EnableVertexAttribArray(vColor);
|
||||
//EnableVertexAttribArray(vColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableVertexAttribArray(vColor);
|
||||
//DisableVertexAttribArray(vColor);
|
||||
}
|
||||
if (VertexRenderStruct.data.TexCoordData.size() > 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.texCoordVBO->getBuffer());
|
||||
VertexAttribPointer2fv(vTexCoord, 0, NULL);
|
||||
EnableVertexAttribArray(vTexCoord);
|
||||
//EnableVertexAttribArray(vTexCoord);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableVertexAttribArray(vTexCoord);
|
||||
//DisableVertexAttribArray(vTexCoord);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.positionVBO->getBuffer());
|
||||
VertexAttribPointer3fv(vPosition, 0, NULL);
|
||||
EnableVertexAttribArray(vPosition);
|
||||
//EnableVertexAttribArray(vPosition);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(VertexRenderStruct.data.PositionData.size()));
|
||||
}
|
||||
|
||||
@@ -127,13 +127,6 @@ namespace ZL {
|
||||
|
||||
void SetMatrix();
|
||||
|
||||
|
||||
|
||||
void EnableVertexAttribArray(const std::string& attribName);
|
||||
|
||||
void DisableVertexAttribArray(const std::string& attribName);
|
||||
|
||||
|
||||
void RenderUniformMatrix3fv(const std::string& uniformName, bool transpose, const float* value);
|
||||
void RenderUniformMatrix4fv(const std::string& uniformName, bool transpose, const float* value);
|
||||
void RenderUniform1i(const std::string& uniformName, const int value);
|
||||
|
||||
@@ -167,7 +167,6 @@ namespace ZL {
|
||||
fragmentShader = readTextFile(fragmentShaderFileName);
|
||||
}
|
||||
|
||||
///std::cout << "Shader: "<< vertexShader << std::endl;
|
||||
shaderResourceMap[shaderName] = std::make_shared<ShaderResource>(vertexShader,
|
||||
fragmentShader);
|
||||
}
|
||||
@@ -181,9 +180,27 @@ namespace ZL {
|
||||
throw std::runtime_error("Shader does not exist!");
|
||||
}
|
||||
|
||||
if (shaderStack.size() > 0)
|
||||
{
|
||||
auto& prevShaderAttribList = shaderResourceMap[shaderStack.top()]->attribList;
|
||||
for (auto& attrib : prevShaderAttribList)
|
||||
{
|
||||
glDisableVertexAttribArray(attrib.second);
|
||||
}
|
||||
}
|
||||
|
||||
shaderStack.push(shaderName);
|
||||
|
||||
glUseProgram(shaderResourceMap[shaderName]->getShaderProgram());
|
||||
auto& shaderResource = shaderResourceMap[shaderName];
|
||||
|
||||
glUseProgram(shaderResource->getShaderProgram());
|
||||
|
||||
auto& shaderAttribList = shaderResource->attribList;
|
||||
for (auto& attrib : shaderAttribList)
|
||||
{
|
||||
glEnableVertexAttribArray(attrib.second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -192,12 +209,26 @@ namespace ZL {
|
||||
throw std::runtime_error("Shader stack underflow!");
|
||||
}
|
||||
|
||||
auto& prevShaderAttribList = shaderResourceMap[shaderStack.top()]->attribList;
|
||||
for (auto& attrib : prevShaderAttribList)
|
||||
{
|
||||
glDisableVertexAttribArray(attrib.second);
|
||||
}
|
||||
|
||||
shaderStack.pop();
|
||||
|
||||
if (shaderStack.size() == 0) {
|
||||
glUseProgram(0);
|
||||
} else {
|
||||
glUseProgram(shaderResourceMap[shaderStack.top()]->getShaderProgram());
|
||||
auto& shaderResource = shaderResourceMap[shaderStack.top()];
|
||||
|
||||
glUseProgram(shaderResource->getShaderProgram());
|
||||
|
||||
auto& shaderAttribList = shaderResource->attribList;
|
||||
for (auto& attrib : shaderAttribList)
|
||||
{
|
||||
glEnableVertexAttribArray(attrib.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -380,10 +380,6 @@ void TextRenderer::drawText(const std::string& text, float x, float y, float sca
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, atlasTexture->getTexID());
|
||||
|
||||
|
||||
r->EnableVertexAttribArray("vPosition");
|
||||
r->EnableVertexAttribArray("vTexCoord");
|
||||
|
||||
//for (size_t i = 0; i < text.length(); ++i) {
|
||||
// auto it = glyphs.find(text[i]);
|
||||
// if (it == glyphs.end()) continue;
|
||||
@@ -401,9 +397,6 @@ void TextRenderer::drawText(const std::string& text, float x, float y, float sca
|
||||
// glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
//}
|
||||
r->DrawVertexRenderStruct(cached.mesh);
|
||||
|
||||
r->DisableVertexAttribArray("vPosition");
|
||||
r->DisableVertexAttribArray("vTexCoord");
|
||||
r->shaderManager.PopShader();
|
||||
|
||||
// Сброс бинда текстуры не обязателен, но можно для чистоты
|
||||
|
||||
Reference in new issue
Block a user