Refactoring
This commit is contained in:
parent
7ccda081b0
commit
928600acd4
12
src/Game.cpp
12
src/Game.cpp
@ -227,11 +227,6 @@ namespace ZL
|
|||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
menuManager.uiManager.draw(renderer);
|
menuManager.uiManager.draw(renderer);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
@ -272,16 +267,12 @@ namespace ZL
|
|||||||
void Game::drawLoading()
|
void Game::drawLoading()
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
//float width = Environment::projectionWidth;
|
//float width = Environment::projectionWidth;
|
||||||
//float height = Environment::projectionHeight;
|
//float height = Environment::projectionHeight;
|
||||||
@ -299,9 +290,6 @@ namespace ZL
|
|||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -420,15 +420,13 @@ namespace ZL
|
|||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
static const std::string envShaderName = "env_sky";
|
static const std::string envShaderName = "env_sky";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
static const std::string skyPercentUniformName = "skyPercent";
|
static const std::string skyPercentUniformName = "skyPercent";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(envShaderName);
|
renderer.shaderManager.PushShader(envShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.RenderUniform1f(skyPercentUniformName, skyPercent);
|
renderer.RenderUniform1f(skyPercentUniformName, skyPercent);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
@ -476,8 +474,6 @@ namespace ZL
|
|||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
@ -486,14 +482,10 @@ namespace ZL
|
|||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
static const std::string envShaderName = "env";
|
static const std::string envShaderName = "env";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
@ -521,8 +513,6 @@ namespace ZL
|
|||||||
|
|
||||||
renderer.shaderManager.PushShader("default");
|
renderer.shaderManager.PushShader("default");
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
@ -539,8 +529,6 @@ namespace ZL
|
|||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
//projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
//projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||||
@ -568,9 +556,6 @@ namespace ZL
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
@ -579,15 +564,10 @@ namespace ZL
|
|||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
static const std::string envShaderName = "env";
|
static const std::string envShaderName = "env";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
@ -612,9 +592,6 @@ namespace ZL
|
|||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
}
|
}
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
@ -622,8 +599,6 @@ namespace ZL
|
|||||||
void Space::drawScene() {
|
void Space::drawScene() {
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
static const std::string envShaderName = "env";
|
static const std::string envShaderName = "env";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||||
@ -669,16 +644,11 @@ namespace ZL
|
|||||||
|
|
||||||
void Space::drawRemoteShips() {
|
void Space::drawRemoteShips() {
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
@ -741,8 +711,6 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
@ -996,17 +964,11 @@ namespace ZL
|
|||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
|
|
||||||
renderer.EnableVertexAttribArray("vPosition");
|
|
||||||
renderer.EnableVertexAttribArray("vColor");
|
|
||||||
|
|
||||||
Eigen::Vector4f uColor(crosshairCfg.color.x(), crosshairCfg.color.y(), crosshairCfg.color.z(), crosshairCfg.alpha);
|
Eigen::Vector4f uColor(crosshairCfg.color.x(), crosshairCfg.color.y(), crosshairCfg.color.z(), crosshairCfg.alpha);
|
||||||
renderer.RenderUniform4fv("uColor", uColor.data());
|
renderer.RenderUniform4fv("uColor", uColor.data());
|
||||||
|
|
||||||
renderer.DrawVertexRenderStruct(crosshairMesh);
|
renderer.DrawVertexRenderStruct(crosshairMesh);
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray("vPosition");
|
|
||||||
renderer.DisableVertexAttribArray("vColor");
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
@ -1335,7 +1297,6 @@ namespace ZL
|
|||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
|
|
||||||
renderer.EnableVertexAttribArray("vPosition");
|
|
||||||
renderer.RenderUniform4fv("uColor", enemyColor.data());
|
renderer.RenderUniform4fv("uColor", enemyColor.data());
|
||||||
|
|
||||||
// рамки
|
// рамки
|
||||||
@ -1358,7 +1319,6 @@ namespace ZL
|
|||||||
drawLeadRing2D(lx, ly);
|
drawLeadRing2D(lx, ly);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray("vPosition");
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
@ -1444,7 +1404,6 @@ namespace ZL
|
|||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
|
|
||||||
renderer.EnableVertexAttribArray("vPosition");
|
|
||||||
renderer.RenderUniform4fv("uColor", enemyColor.data());
|
renderer.RenderUniform4fv("uColor", enemyColor.data());
|
||||||
|
|
||||||
// стрелка
|
// стрелка
|
||||||
@ -1462,7 +1421,6 @@ namespace ZL
|
|||||||
drawLeadRing2D(lx, ly);
|
drawLeadRing2D(lx, ly);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray("vPosition");
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|||||||
@ -195,14 +195,10 @@ namespace ZL {
|
|||||||
sparkQuad.data.TexCoordData = drawTexCoords;
|
sparkQuad.data.TexCoordData = drawTexCoords;
|
||||||
sparkQuad.RefreshVBO();
|
sparkQuad.RefreshVBO();
|
||||||
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(shaderProgramName);
|
renderer.shaderManager.PushShader(shaderProgramName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
//float aspectRatio = static_cast<float>(screenWidth) / static_cast<float>(screenHeight);
|
//float aspectRatio = static_cast<float>(screenWidth) / static_cast<float>(screenHeight);
|
||||||
//renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5, aspectRatio, Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
//renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5, aspectRatio, Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
@ -222,9 +218,6 @@ namespace ZL {
|
|||||||
//renderer.PopProjectionMatrix();
|
//renderer.PopProjectionMatrix();
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,8 +61,6 @@ namespace ZL {
|
|||||||
}
|
}
|
||||||
if (!(*tex)) return;
|
if (!(*tex)) return;
|
||||||
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
@ -70,14 +68,8 @@ namespace ZL {
|
|||||||
renderer.ScaleMatrix({ animScaleX, animScaleY, 1.0f });
|
renderer.ScaleMatrix({ animScaleX, animScaleY, 1.0f });
|
||||||
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, (*tex)->getTexID());
|
glBindTexture(GL_TEXTURE_2D, (*tex)->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(mesh);
|
renderer.DrawVertexRenderStruct(mesh);
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,14 +140,9 @@ namespace ZL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UiSlider::draw(Renderer& renderer) const {
|
void UiSlider::draw(Renderer& renderer) const {
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
if (texTrack) {
|
if (texTrack) {
|
||||||
glBindTexture(GL_TEXTURE_2D, texTrack->getTexID());
|
glBindTexture(GL_TEXTURE_2D, texTrack->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(trackMesh);
|
renderer.DrawVertexRenderStruct(trackMesh);
|
||||||
@ -164,9 +151,6 @@ namespace ZL {
|
|||||||
glBindTexture(GL_TEXTURE_2D, texKnob->getTexID());
|
glBindTexture(GL_TEXTURE_2D, texKnob->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(knobMesh);
|
renderer.DrawVertexRenderStruct(knobMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiStaticImage::buildMesh() {
|
void UiStaticImage::buildMesh() {
|
||||||
@ -202,19 +186,11 @@ namespace ZL {
|
|||||||
void UiStaticImage::draw(Renderer& renderer) const {
|
void UiStaticImage::draw(Renderer& renderer) const {
|
||||||
if (!texture) return;
|
if (!texture) return;
|
||||||
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, texture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(mesh);
|
renderer.DrawVertexRenderStruct(mesh);
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiTextField::draw(Renderer& renderer) const {
|
void UiTextField::draw(Renderer& renderer) const {
|
||||||
|
|||||||
@ -186,15 +186,11 @@ namespace ZL {
|
|||||||
|
|
||||||
|
|
||||||
static const std::string defaultShaderName2 = "planetBake";
|
static const std::string defaultShaderName2 = "planetBake";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName2);
|
renderer.shaderManager.PushShader(defaultShaderName2);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
Triangle tr = planetData.getLodLevel().triangles[0];
|
Triangle tr = planetData.getLodLevel().triangles[0];
|
||||||
|
|
||||||
@ -260,8 +256,6 @@ namespace ZL {
|
|||||||
glDisable(GL_CULL_FACE); // Не забываем выключить, чтобы не сломать остальной рендер
|
glDisable(GL_CULL_FACE); // Не забываем выключить, чтобы не сломать остальной рендер
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
@ -300,21 +294,10 @@ namespace ZL {
|
|||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "planetLand";
|
static const std::string defaultShaderName = "planetLand";
|
||||||
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vColorName = "vColor";
|
|
||||||
static const std::string vNormalName = "vNormal";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
|
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vColorName);
|
|
||||||
renderer.EnableVertexAttribArray(vNormalName);
|
|
||||||
renderer.EnableVertexAttribArray("vTangent");
|
|
||||||
renderer.EnableVertexAttribArray("vBinormal");
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
auto zRange = planetData.calculateZRange(dist);
|
auto zRange = planetData.calculateZRange(dist);
|
||||||
@ -376,12 +359,6 @@ namespace ZL {
|
|||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.DisableVertexAttribArray(vNormalName);
|
|
||||||
renderer.DisableVertexAttribArray("vTangent");
|
|
||||||
renderer.DisableVertexAttribArray("vBinormal");
|
|
||||||
renderer.DisableVertexAttribArray(vColorName);
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
@ -391,19 +368,10 @@ namespace ZL {
|
|||||||
void PlanetObject::drawStones(Renderer& renderer)
|
void PlanetObject::drawStones(Renderer& renderer)
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName2 = "planetStone";
|
static const std::string defaultShaderName2 = "planetStone";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vColorName = "vColor";
|
|
||||||
static const std::string vNormalName = "vNormal";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName2);
|
renderer.shaderManager.PushShader(defaultShaderName2);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vColorName);
|
|
||||||
renderer.EnableVertexAttribArray(vNormalName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
auto zRange = planetData.calculateZRange(dist);
|
auto zRange = planetData.calculateZRange(dist);
|
||||||
@ -468,10 +436,6 @@ namespace ZL {
|
|||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.DisableVertexAttribArray(vNormalName);
|
|
||||||
renderer.DisableVertexAttribArray(vColorName);
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
@ -480,16 +444,10 @@ namespace ZL {
|
|||||||
|
|
||||||
void PlanetObject::drawAtmosphere(Renderer& renderer) {
|
void PlanetObject::drawAtmosphere(Renderer& renderer) {
|
||||||
static const std::string defaultShaderName = "defaultAtmosphere";
|
static const std::string defaultShaderName = "defaultAtmosphere";
|
||||||
//static const std::string defaultShaderName = "defaultColor";
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vNormalName = "vNormal";
|
|
||||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vNormalName);
|
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
auto zRange = planetData.calculateZRange(dist);
|
auto zRange = planetData.calculateZRange(dist);
|
||||||
float currentZNear = zRange.first;
|
float currentZNear = zRange.first;
|
||||||
@ -571,9 +529,6 @@ namespace ZL {
|
|||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vNormalName);
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
@ -582,19 +537,10 @@ namespace ZL {
|
|||||||
void PlanetObject::drawCamp(Renderer& renderer)
|
void PlanetObject::drawCamp(Renderer& renderer)
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName2 = "default";
|
static const std::string defaultShaderName2 = "default";
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vColorName = "vColor";
|
|
||||||
static const std::string vNormalName = "vNormal";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName2);
|
renderer.shaderManager.PushShader(defaultShaderName2);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vColorName);
|
|
||||||
renderer.EnableVertexAttribArray(vNormalName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
auto zRange = planetData.calculateZRange(dist);
|
auto zRange = planetData.calculateZRange(dist);
|
||||||
@ -655,10 +601,6 @@ namespace ZL {
|
|||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
renderer.DisableVertexAttribArray(vNormalName);
|
|
||||||
renderer.DisableVertexAttribArray(vColorName);
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
|
|||||||
@ -50,17 +50,14 @@ namespace ZL {
|
|||||||
|
|
||||||
Matrix4f r;
|
Matrix4f r;
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
r.data()[0] = 2.f / width;
|
r.data()[0] = 2.f / width;
|
||||||
r.data()[5] = 2.f / height;
|
r.data()[5] = 2.f / height;
|
||||||
r.data()[10] = -1.f / depthRange;
|
r.data()[10] = -1.f / depthRange;
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
r.data()[1] = r.data()[2] = r.data()[3] = 0;
|
r.data()[1] = r.data()[2] = r.data()[3] = 0;
|
||||||
r.data()[4] = r.data()[6] = r.data()[7] = 0;
|
r.data()[4] = r.data()[6] = r.data()[7] = 0;
|
||||||
r.data()[8] = r.data()[9] = r.data()[11] = 0;
|
r.data()[8] = r.data()[9] = r.data()[11] = 0;
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
||||||
r.data()[12] = -(xmax + xmin) / width;
|
r.data()[12] = -(xmax + xmin) / width;
|
||||||
r.data()[13] = -(ymax + ymin) / height;
|
r.data()[13] = -(ymax + ymin) / height;
|
||||||
r.data()[14] = zNear / depthRange;
|
r.data()[14] = zNear / depthRange;
|
||||||
@ -703,19 +700,7 @@ namespace ZL {
|
|||||||
Matrix4f m = Matrix4f::Identity();
|
Matrix4f m = Matrix4f::Identity();
|
||||||
|
|
||||||
m.block<3, 3>(0, 0) = m3;
|
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;
|
m = ModelviewMatrixStack.top() * m;
|
||||||
|
|
||||||
if (ModelviewMatrixStack.size() == 0)
|
if (ModelviewMatrixStack.size() == 0)
|
||||||
@ -733,17 +718,7 @@ namespace ZL {
|
|||||||
void Renderer::RotateMatrix(const Matrix3f& m3)
|
void Renderer::RotateMatrix(const Matrix3f& m3)
|
||||||
{
|
{
|
||||||
Matrix4f m = Matrix4f::Identity();
|
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.block<3, 3>(0, 0) = m3;
|
||||||
|
|
||||||
m = ModelviewMatrixStack.top() * m;
|
m = ModelviewMatrixStack.top() * m;
|
||||||
@ -782,22 +757,6 @@ namespace ZL {
|
|||||||
SetMatrix();
|
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)
|
void Renderer::RenderUniformMatrix3fv(const std::string& uniformName, bool transpose, const float* value)
|
||||||
{
|
{
|
||||||
auto shader = shaderManager.GetCurrentShader();
|
auto shader = shaderManager.GetCurrentShader();
|
||||||
@ -902,56 +861,56 @@ namespace ZL {
|
|||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.normalVBO->getBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.normalVBO->getBuffer());
|
||||||
VertexAttribPointer3fv(vNormal, 0, NULL);
|
VertexAttribPointer3fv(vNormal, 0, NULL);
|
||||||
EnableVertexAttribArray(vNormal);
|
//EnableVertexAttribArray(vNormal);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisableVertexAttribArray(vNormal);
|
//DisableVertexAttribArray(vNormal);
|
||||||
}
|
}
|
||||||
if (VertexRenderStruct.data.TangentData.size() > 0)
|
if (VertexRenderStruct.data.TangentData.size() > 0)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.tangentVBO->getBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.tangentVBO->getBuffer());
|
||||||
VertexAttribPointer3fv(vTangent, 0, NULL);
|
VertexAttribPointer3fv(vTangent, 0, NULL);
|
||||||
EnableVertexAttribArray(vTangent);
|
//EnableVertexAttribArray(vTangent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisableVertexAttribArray(vTangent);
|
//DisableVertexAttribArray(vTangent);
|
||||||
}
|
}
|
||||||
if (VertexRenderStruct.data.BinormalData.size() > 0)
|
if (VertexRenderStruct.data.BinormalData.size() > 0)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.binormalVBO->getBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.binormalVBO->getBuffer());
|
||||||
VertexAttribPointer3fv(vBinormal, 0, NULL);
|
VertexAttribPointer3fv(vBinormal, 0, NULL);
|
||||||
EnableVertexAttribArray(vBinormal);
|
//EnableVertexAttribArray(vBinormal);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisableVertexAttribArray(vBinormal);
|
//DisableVertexAttribArray(vBinormal);
|
||||||
}
|
}
|
||||||
if (VertexRenderStruct.data.ColorData.size() > 0)
|
if (VertexRenderStruct.data.ColorData.size() > 0)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.colorVBO->getBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.colorVBO->getBuffer());
|
||||||
VertexAttribPointer3fv(vColor, 0, NULL);
|
VertexAttribPointer3fv(vColor, 0, NULL);
|
||||||
EnableVertexAttribArray(vColor);
|
//EnableVertexAttribArray(vColor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisableVertexAttribArray(vColor);
|
//DisableVertexAttribArray(vColor);
|
||||||
}
|
}
|
||||||
if (VertexRenderStruct.data.TexCoordData.size() > 0)
|
if (VertexRenderStruct.data.TexCoordData.size() > 0)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.texCoordVBO->getBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.texCoordVBO->getBuffer());
|
||||||
VertexAttribPointer2fv(vTexCoord, 0, NULL);
|
VertexAttribPointer2fv(vTexCoord, 0, NULL);
|
||||||
EnableVertexAttribArray(vTexCoord);
|
//EnableVertexAttribArray(vTexCoord);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisableVertexAttribArray(vTexCoord);
|
//DisableVertexAttribArray(vTexCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.positionVBO->getBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.positionVBO->getBuffer());
|
||||||
VertexAttribPointer3fv(vPosition, 0, NULL);
|
VertexAttribPointer3fv(vPosition, 0, NULL);
|
||||||
EnableVertexAttribArray(vPosition);
|
//EnableVertexAttribArray(vPosition);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(VertexRenderStruct.data.PositionData.size()));
|
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(VertexRenderStruct.data.PositionData.size()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,13 +127,6 @@ namespace ZL {
|
|||||||
|
|
||||||
void SetMatrix();
|
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 RenderUniformMatrix3fv(const std::string& uniformName, bool transpose, const float* value);
|
||||||
void RenderUniformMatrix4fv(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);
|
void RenderUniform1i(const std::string& uniformName, const int value);
|
||||||
|
|||||||
@ -167,7 +167,6 @@ namespace ZL {
|
|||||||
fragmentShader = readTextFile(fragmentShaderFileName);
|
fragmentShader = readTextFile(fragmentShaderFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
///std::cout << "Shader: "<< vertexShader << std::endl;
|
|
||||||
shaderResourceMap[shaderName] = std::make_shared<ShaderResource>(vertexShader,
|
shaderResourceMap[shaderName] = std::make_shared<ShaderResource>(vertexShader,
|
||||||
fragmentShader);
|
fragmentShader);
|
||||||
}
|
}
|
||||||
@ -181,9 +180,27 @@ namespace ZL {
|
|||||||
throw std::runtime_error("Shader does not exist!");
|
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);
|
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!");
|
throw std::runtime_error("Shader stack underflow!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& prevShaderAttribList = shaderResourceMap[shaderStack.top()]->attribList;
|
||||||
|
for (auto& attrib : prevShaderAttribList)
|
||||||
|
{
|
||||||
|
glDisableVertexAttribArray(attrib.second);
|
||||||
|
}
|
||||||
|
|
||||||
shaderStack.pop();
|
shaderStack.pop();
|
||||||
|
|
||||||
if (shaderStack.size() == 0) {
|
if (shaderStack.size() == 0) {
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
} else {
|
} 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);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, atlasTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, atlasTexture->getTexID());
|
||||||
|
|
||||||
|
|
||||||
r->EnableVertexAttribArray("vPosition");
|
|
||||||
r->EnableVertexAttribArray("vTexCoord");
|
|
||||||
|
|
||||||
//for (size_t i = 0; i < text.length(); ++i) {
|
//for (size_t i = 0; i < text.length(); ++i) {
|
||||||
// auto it = glyphs.find(text[i]);
|
// auto it = glyphs.find(text[i]);
|
||||||
// if (it == glyphs.end()) continue;
|
// 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);
|
// glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
//}
|
//}
|
||||||
r->DrawVertexRenderStruct(cached.mesh);
|
r->DrawVertexRenderStruct(cached.mesh);
|
||||||
|
|
||||||
r->DisableVertexAttribArray("vPosition");
|
|
||||||
r->DisableVertexAttribArray("vTexCoord");
|
|
||||||
r->shaderManager.PopShader();
|
r->shaderManager.PopShader();
|
||||||
|
|
||||||
// Сброс бинда текстуры не обязателен, но можно для чистоты
|
// Сброс бинда текстуры не обязателен, но можно для чистоты
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user