67 lines
1.1 KiB
C++
67 lines
1.1 KiB
C++
//
|
|
// Created by lukas on 05.02.22.
|
|
//
|
|
|
|
#ifndef OPENGLTEST_RENDERBASE_H
|
|
#define OPENGLTEST_RENDERBASE_H
|
|
|
|
|
|
#include <iostream>
|
|
#include "../gl/Renderer.h"
|
|
#include "../gl/Shader.h"
|
|
|
|
template<class T>
|
|
class RenderBase {
|
|
private:
|
|
static RenderBase *instance;
|
|
public:
|
|
virtual VertexArray *setVertexArray() = 0;
|
|
|
|
virtual Shader setShader() = 0;
|
|
|
|
virtual IndexBuffer *setIndexBuffer() = 0;
|
|
|
|
static RenderBase *getInstance() {
|
|
if (instance == nullptr) {
|
|
instance = new T();
|
|
instance->init();
|
|
}
|
|
return instance;
|
|
|
|
}
|
|
|
|
public:
|
|
Renderer r;
|
|
VertexArray *va;
|
|
IndexBuffer *ib;
|
|
Shader s;
|
|
|
|
public:
|
|
RenderBase() {};
|
|
|
|
void render() {
|
|
r.render(*va, *ib, s);
|
|
}
|
|
|
|
void init() {
|
|
s = setShader();
|
|
va = setVertexArray();
|
|
ib = setIndexBuffer();
|
|
}
|
|
|
|
void deinit() {}
|
|
|
|
unsigned getMVPhandle() {
|
|
return s.getUniformHandle("MVP");
|
|
}
|
|
|
|
unsigned getUniformhandle(std::string name) {
|
|
return s.getUniformHandle(std::move(name));
|
|
}
|
|
};
|
|
|
|
template<class T>
|
|
RenderBase<T> *RenderBase<T>::instance = nullptr;
|
|
|
|
#endif //OPENGLTEST_RENDERBASE_H
|