Browse Source

De-Singleton ShaderLoader

master
Geert Custers 5 years ago
parent
commit
bcd3b07b43
  1. 5
      src/graphics/components/DocumentComponent.cpp
  2. 5
      src/graphics/components/InputComponent.cpp
  3. 5
      src/graphics/components/MultiComponent.cpp
  4. 4
      src/graphics/opengl/ShaderLoader.cpp
  5. 16
      src/graphics/opengl/ShaderLoader.h
  6. 5
      src/graphics/opengl/Window.cpp
  7. 2
      src/graphics/opengl/Window.h

5
src/graphics/components/DocumentComponent.cpp

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
#include <ctime>
#include "../opengl/Shader.h"
#include "../opengl/ShaderLoader.h"
void deleteComponent(std::shared_ptr<Component> &component);
void deleteNode(std::shared_ptr<Node> node);
@ -277,13 +276,13 @@ void DocumentComponent::render() { @@ -277,13 +276,13 @@ void DocumentComponent::render() {
//if (transformMatrixDirty) {
//const std::clock_t begin = clock();
Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
Shader *fontShader = window->shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
GLint transformLocation = fontShader->uniform("transform");
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, transformMatrix);
//const std::clock_t end = clock();
//std::cout << "Updated font matrix in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = window->shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
GLint transformLocation2 = textureShader->uniform("transform");
glUniformMatrix4fv(transformLocation2, 1, GL_FALSE, transformMatrix);

5
src/graphics/components/InputComponent.cpp

@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
#include "../../scheduler.h"
#include "../opengl/Shader.h"
#include "../opengl/ShaderLoader.h"
extern TextRasterizerCache *rasterizerCache;
extern std::unique_ptr<Scheduler> scheduler;
@ -162,7 +161,7 @@ void InputComponent::render() { @@ -162,7 +161,7 @@ void InputComponent::render() {
// can actuall delete vertices here
if (userInputText) {
// make sure we're using win's transformMatrix
Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
Shader *fontShader = window->shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
fontShader->bind();
if (!boundToPage) {
@ -180,7 +179,7 @@ void InputComponent::render() { @@ -180,7 +179,7 @@ void InputComponent::render() {
}
//std::cout << "rendering some text" << std::endl;
userInputText->render();
Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = window->shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
textureShader->bind();
}

5
src/graphics/components/MultiComponent.cpp

@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
#include "InputComponent.h"
#include "../opengl/Shader.h"
#include "../opengl/ShaderLoader.h"
MultiComponent::MultiComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) {
@ -218,13 +217,13 @@ void MultiComponent::resize(const int passedWindowWidth, const int passedWindowH @@ -218,13 +217,13 @@ void MultiComponent::resize(const int passedWindowWidth, const int passedWindowH
void MultiComponent::render() {
//std::cout << "MultiComponent::render" << std::endl;
Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
Shader *fontShader = window->shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
fontShader->bind();
renderDocumentComponents(rootComponent);
fontShader->release();
Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = window->shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
textureShader->bind();
renderBoxComponents(rootComponent);

4
src/graphics/opengl/ShaderLoader.cpp

@ -9,9 +9,7 @@ @@ -9,9 +9,7 @@
#include "../../environment/Environment.h"
#include "../../environment/Path.h"
static constexpr GLint maxLogSize = 1024 * 1024 * 2; //2 MiB
ShaderLoader::ShaderCache ShaderLoader::shaderCache;
constexpr GLint maxLogSize = 1024 * 1024 * 2; //2 MiB
GLuint ShaderLoader::loadShader(const std::string &shaderName, Shader::Type type) {
GLenum glType = getGlShaderType(type);

16
src/graphics/opengl/ShaderLoader.h

@ -12,23 +12,23 @@ public: @@ -12,23 +12,23 @@ public:
using ShaderCache = std::map<std::string, Shader*>;
// Get a shader from the shader cache and load it from disk it isn't there
static Shader *getShader(VertexShader vertexShader, FragmentShader fragmentShader);
Shader *getShader(VertexShader vertexShader, FragmentShader fragmentShader);
// Load a shader from disk and return the its handle
static GLuint loadShader(const std::string &shader, Shader::Type shaderType);
GLuint loadShader(const std::string &shader, Shader::Type shaderType);
static GLuint createProgram(const std::string &shader1Name, Shader::Type shader1Type,
GLuint createProgram(const std::string &shader1Name, Shader::Type shader1Type,
const std::string &shader2Name, Shader::Type shader2Type);
private:
static ShaderCache shaderCache;
ShaderCache shaderCache;
static int checkProgram(GLuint program, GLenum programName,
int checkProgram(GLuint program, GLenum programName,
const std::string &shaderName);
static int checkShader(GLuint shader, const std::string &shaderName, Shader::Type shaderType);
int checkShader(GLuint shader, const std::string &shaderName, Shader::Type shaderType);
static constexpr GLenum getGlShaderType(const Shader::Type type);
constexpr GLenum getGlShaderType(const Shader::Type type);
static constexpr const char *getProgramStatusString(GLenum pname);
constexpr const char *getProgramStatusString(GLenum pname);
};
#endif

5
src/graphics/opengl/Window.cpp

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
#include "../components/TabbedComponent.h"
#include "../components/InputComponent.h"
#include "../opengl/Shader.h"
#include "../opengl/ShaderLoader.h"
#include <cmath>
#include <ctime>
@ -700,7 +699,7 @@ void Window::render() { @@ -700,7 +699,7 @@ void Window::render() {
std::cout << "window::render - box render start - not ok: " << glErr << std::endl;
}
Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
textureShader->bind();
glErr=glGetError();
@ -722,7 +721,7 @@ void Window::render() { @@ -722,7 +721,7 @@ void Window::render() {
renderComponentType("input", rootComponent);
// it's quick but done on scroll
Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
Shader *fontShader = shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
fontShader->bind();
// reset both, since components can change this

2
src/graphics/opengl/Window.h

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include "../components/ComponentBuilder.h"
#include "../components/Component.h"
#include "ShaderLoader.h"
#include "../../html/Node.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
@ -68,6 +69,7 @@ public: @@ -68,6 +69,7 @@ public:
GLFWcursor* cursorArrow;
GLFWcursor* cursorIbeam;
URL currentURL;
ShaderLoader shaderLoader;
};
bool setWindowContent(URL const& url);

Loading…
Cancel
Save