Я пытаюсь написать небольшую библиотеку openGL.
В основном у меня есть шаблонный класс Uniform<T>
и класс Shader
с GetUniform<T>(const char* name)
, который должен возвращать экземпляр класса Uniform
с типом T
, также я не хочу делать это со специализацией, потому что код один и тот же независимо от типа.
Унифицированный код класса:
template<typename T>
class Uniform {
private:
unsigned int _Location;
public:
inline Uniform(unsigned int location) : _Location(location) {}
}
Первый getUniform<T>
реализация:
template<typename T>
inline Uniform<T> getUniform(const char* name) const {
unsigned int location = glGetUniformLocation(_ID, name);
return Uniform<T>(location);
}
Fails with error:
error C2988: unrecognizable template declaration/definition
Второй getUniform<T>
реализация:
template<typename T>
inline auto getUniform(const char* name) const {
unsigned int location = glGetUniformLocation(_ID, name);
return Uniform<T>(location);
}
Fails with error:
error C3861: 'Uniform': identifier not found
(почти) Полный код:
Shader.h
#pragma once
#include "Utils.h"
#include "Uniform.h"
class Shader {
private:
unsigned int _ID;
GLenum parseShaderDef(std::string line, bool first = false) {
//STUFF
}
void compileShader(unsigned int id) {
//STUFF
}
public:
inline Shader(const char* shaderFile) {
//STUFF
}
inline ~Shader() {
//TODO
}
template<typename T>
inline Uniform<T> getUniform(const char* name) const {
unsigned int location = glGetUniformLocation(_ID, name);
return Uniform<T>(location);
}
inline void Bind() const {
glUseProgram(_ID);
}
inline unsigned int getID() const {
return _ID;
}
static inline void Unbind() {
glUseProgram(0);
}
};
Uniform.h
#pragma once
#include "Utils.h"
#include "Shader.h"
template<typename T>
class Uniform {
private:
unsigned int _Location;
public:
inline Uniform(unsigned int location) : _Location(location) {}
void operator=(T value) {};
};
template<>
void Uniform<bool>::operator=(bool value) {
glUniform1i(_Location, value);
}
// All the other specializations
Кроме того, в основной файл включены толькоiform.h
Utils.h - это pch