123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #pragma once
-
- #include <stdint.h>
- #include <stdexcept>
-
- #include "util.h"
-
- namespace Cygnet {
-
- struct GlCompileError: public std::exception {
- GlCompileError(std::string message): message(std::move(message)) {}
- const char *what() const noexcept override { return message.c_str(); }
- std::string message;
- };
-
- class GlShader {
- public:
- enum class Type {
- VERTEX,
- FRAGMENT,
- };
-
- GlShader(Type type, const char *source);
- ~GlShader();
-
- GLuint id() const { return id_; }
-
- private:
- GLuint id_;
- };
-
- class GlVxShader: public GlShader {
- public:
- explicit GlVxShader(const char *source): GlShader(Type::VERTEX, source) {}
- };
-
- class GlFrShader: public GlShader {
- public:
- explicit GlFrShader(const char *source): GlShader(Type::FRAGMENT, source) {}
- };
-
- class GlProgram {
- public:
- template <typename... T>
- GlProgram(const T &... shaders): GlProgram() { (addShader(shaders), ...); link(); }
- GlProgram();
- ~GlProgram();
-
- void use();
- GLuint id() const { return id_; }
-
- protected:
-
- GLint attribLoc(const char *name);
- GLint uniformLoc(const char *name);
-
- private:
- void addShader(const GlShader &shader);
- void link();
-
- GLuint id_;
- };
-
- class GlTexture {
- public:
- GlTexture();
-
- void bind();
- void upload(GLsizei width, GLsizei height, void *data,
- GLenum format, GLenum type);
- GLuint id() { return id_; }
- int width() { return w_; }
- int height() { return h_; }
-
- private:
- GLuint id_;
- int w_;
- int h_;
- };
-
- }
|