Use geometry shader for widgets.
This commit is contained in:
@@ -41,6 +41,7 @@ Controller::Controller() : m_gameWindow(std::unique_ptr<Window>(new Window))
|
||||
|
||||
for (auto &prototype : shaderProgramPrototypes) {
|
||||
m_shaderPrograms.push_back(new ShaderProgram(prototype));
|
||||
std::cout << "Loaded ShaderProgram \"" << prototype.name << "\"" << std::endl;
|
||||
}
|
||||
|
||||
m_postProcessFrameBuffer = new FrameBuffer(m_gameWindow->getWindowWidth(), m_gameWindow->getWindowHeight(),
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
#include "JsonParser.h"
|
||||
#include "Entity.h"
|
||||
#include "Light.h"
|
||||
#include "Model.h"
|
||||
#include "Screen.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Texture.h"
|
||||
#include "Widget.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -103,7 +96,6 @@ std::vector<ShaderProgram::Prototype> JsonParser::getShaderProgramPrototypes()
|
||||
shaderProgram_geometryPath};
|
||||
|
||||
prototypes.push_back(prototype);
|
||||
// std::cout << "Loaded ShaderProgram \"" << shaderProgram_name << "\"" << std::endl;
|
||||
}
|
||||
|
||||
return prototypes;
|
||||
|
||||
@@ -128,6 +128,12 @@ void ShaderProgram::setUniform(const std::string &name, float value) const
|
||||
glUniform1f(location, value);
|
||||
}
|
||||
|
||||
void ShaderProgram::setUniform(const std::string &name, glm::vec2 vector) const
|
||||
{
|
||||
GLint location = retrieveUniformLocation(name);
|
||||
glUniform2f(location, vector.x, vector.y);
|
||||
}
|
||||
|
||||
void ShaderProgram::setUniform(const std::string &name, glm::vec3 vector) const
|
||||
{
|
||||
GLint location = retrieveUniformLocation(name);
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
void setUniform(const std::string &name, bool value) const;
|
||||
void setUniform(const std::string &name, int value) const;
|
||||
void setUniform(const std::string &name, float value) const;
|
||||
void setUniform(const std::string &name, glm::vec2 vector) const;
|
||||
void setUniform(const std::string &name, glm::vec3 vector) const;
|
||||
void setUniform(const std::string &name, glm::mat3 matrix) const;
|
||||
void setUniform(const std::string &name, glm::mat4 matrix) const;
|
||||
|
||||
@@ -12,35 +12,12 @@ Widget::Widget(Prototype prototype, Texture *texture)
|
||||
m_callbackId(prototype.callBackId)
|
||||
{
|
||||
m_widgetTextures.push_back(texture);
|
||||
|
||||
double widgetVerticesData[12] = {
|
||||
2 * (m_position.x + m_dimensions.x) - 1.0f,
|
||||
2 * (m_position.y) - 1.0f,
|
||||
0.0f, // Bottom right
|
||||
2 * (m_position.x) - 1.0f,
|
||||
2 * (m_position.y + m_dimensions.y) - 1.0f,
|
||||
0.0f, // Top left
|
||||
2 * (m_position.x) - 1.0f,
|
||||
2 * (m_position.y) - 1.0f,
|
||||
0.0f, // Bottom left
|
||||
2 * (m_position.x + m_dimensions.x) - 1.0f,
|
||||
2 * (m_position.y + m_dimensions.y) - 1.0f,
|
||||
0.0f // Top right
|
||||
};
|
||||
|
||||
unsigned int widgetIndicesData[6] = {0, 1, 2, 0, 3, 1};
|
||||
|
||||
float widgetTextureCoordinates[8] = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
|
||||
|
||||
m_widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates);
|
||||
m_widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6);
|
||||
m_widgetMesh = new Mesh(m_widgetVertices, m_widgetIndices, m_widgetTextures);
|
||||
m_widgetMesh->initializeOnGPU();
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete m_widgetMesh;
|
||||
for (auto &texture : m_widgetTextures)
|
||||
delete texture;
|
||||
}
|
||||
|
||||
std::string Widget::getUniqueName()
|
||||
@@ -56,7 +33,28 @@ uint16_t Widget::getCallbackId()
|
||||
void Widget::draw(ShaderProgram *shaderProgram)
|
||||
{
|
||||
shaderProgram->bind();
|
||||
m_widgetMesh->draw(shaderProgram);
|
||||
shaderProgram->setUniform("u_widgetData.position", m_position);
|
||||
shaderProgram->setUniform("u_widgetData.dimensions", m_dimensions);
|
||||
|
||||
GLint wireframe;
|
||||
glGetIntegerv(GL_POLYGON_MODE, &wireframe);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_widgetTextures[0]->getTextureId());
|
||||
|
||||
GLint location = glGetUniformLocation(shaderProgram->getShaderProgramId(), "u_texture");
|
||||
glUniform1i(location, 0);
|
||||
|
||||
// A VAO is necessary although no data is stored in it
|
||||
GLuint temp_vao;
|
||||
glGenVertexArrays(1, &temp_vao);
|
||||
glBindVertexArray(temp_vao);
|
||||
glDrawArrays(GL_POINTS, 0, 3);
|
||||
glBindVertexArray(0);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, wireframe);
|
||||
|
||||
shaderProgram->unbind();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +43,5 @@ private:
|
||||
|
||||
uint16_t m_callbackId;
|
||||
|
||||
std::vector<Vertex> m_widgetVertices;
|
||||
std::vector<uint32_t> m_widgetIndices;
|
||||
std::vector<Texture *> m_widgetTextures;
|
||||
|
||||
Mesh *m_widgetMesh;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user