aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/opengl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/opengl.h')
-rw-r--r--src/libjin/graphics/opengl.h270
1 files changed, 270 insertions, 0 deletions
diff --git a/src/libjin/graphics/opengl.h b/src/libjin/graphics/opengl.h
new file mode 100644
index 0000000..e97ebb6
--- /dev/null
+++ b/src/libjin/graphics/opengl.h
@@ -0,0 +1,270 @@
+#ifndef __JE_OPENGL_H__
+#define __JE_OPENGL_H__
+
+#include <vector>
+
+#include "../math/matrix.h"
+#include "../math/transform.h"
+
+//#include "GLee/GLee.h"
+#include "glad/glad.h"
+
+#include "color.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ // Wrap OpenGL API.
+
+ namespace Shaders { class Shader; };
+ namespace Fonts { class Font; };
+
+ class Texture;
+
+ class Canvas;
+
+ class OpenGL
+ {
+ public:
+ ///
+ /// Blend mode.
+ /// https://www.andersriggelsen.dk/glblendfunc.php
+ ///
+ enum class BlendMode
+ {
+ ALPHA = 1,
+ ADDITIVE = 2,
+ PREMULTIPLIEDALPHA = 3,
+ };
+
+ struct Stats
+ {
+ int drawCalls;
+ //int drawCallsBatched;
+ int canvasSwitches;
+ int shaderSwitches;
+ int fontSwitches;
+ int textures;
+ int canvases;
+ int fonts;
+ //int64 textureMemory;
+ };
+
+ static Canvas* const SCREEN;
+
+ OpenGL();
+ ~OpenGL();
+
+ bool loadGL();
+
+ void init();
+
+ void enable(GLenum cap);
+
+ void disable(GLenum cap);
+
+ void setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
+
+ void pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255);
+
+ void popColor();
+
+ void flushError();
+
+ GLuint genTexture();
+
+ void deleteTexture(GLuint texture);
+
+ void bindTexture2D(GLuint texture = 0);
+
+ void setTexParameter(GLenum pname, GLint param);
+
+ void texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels = NULL);
+
+ void texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+
+ void activeTextureUnit(unsigned int unit = 0);
+
+ void drawArrays(GLenum mode, GLint first, GLsizei count);
+
+ void drawBuffer(GLenum mode);
+
+ void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
+
+ void enableClientState(GLenum arr);
+
+ void disableClientState(GLenum arr);
+
+ GLuint genFrameBuffer();
+
+ void bindFrameBuffer(GLuint fbo);
+
+ void ortho(int w, float radio);
+
+ void orthox(int w, int h);
+
+ void setColor(Channel r, Channel g, Channel b, Channel a);
+
+ void setColor(Color c);
+
+ Color getColor();
+
+ void clearMatrix();
+
+ void pushMatrix();
+
+ void translate(float x, float y);
+
+ void scale(float sx, float sy);
+
+ void rotate(float r);
+
+ void popMatrix();
+
+ ///
+ ///
+ ///
+ Math::Matrix getModelViewMatrix(const Math::Transform& tansform);
+
+ ///
+ /// Get model view matrix.
+ ///
+ Math::Matrix getModelViewMatrix(float x, float y, float sx, float sy, float r, float ox, float oy);
+
+ ///
+ /// Get model view matrix.
+ ///
+ Math::Matrix getModelViewMatrix();
+
+ ///
+ /// Set orthogonal matrix.
+ ///
+ void setProjectionMatrix(float l, float r, float b, float t, float n, float f);
+
+ ///
+ /// Get orthogonal matrix.
+ ///
+ const Math::Matrix& getProjectionMatrix();
+
+ ///
+ ///
+ ///
+ void useShader(Shaders::Shader* shader);
+
+ ///
+ ///
+ ///
+ void unuseShader();
+
+ ///
+ ///
+ ///
+ Shaders::Shader* getShader();
+
+ ///
+ ///
+ ///
+ void setFont(Fonts::Font* font);
+
+ ///
+ ///
+ ///
+ void unsetFont();
+
+ ///
+ ///
+ ///
+ Fonts::Font* getFont();
+
+ ///
+ ///
+ ///
+ void bindCanvas(Canvas* canvas);
+
+ ///
+ ///
+ ///
+ void unbindCanvas();
+
+ ///
+ ///
+ ///
+ Canvas* getCanvas();
+
+ ///
+ ///
+ ///
+ void setBlendMode(BlendMode mode);
+
+ ///
+ ///
+ ///
+ BlendMode getBlendMode();
+
+ ///
+ ///
+ ///
+ void resetStats();
+
+ ///
+ ///
+ ///
+ Stats& getStats();
+
+ private:
+
+ ///
+ ///
+ ///
+ std::vector<Math::Matrix> mModelViewMatrices;
+
+ ///
+ ///
+ ///
+ Math::Matrix mModelViewMatrix;
+
+ ///
+ ///
+ ///
+ Math::Matrix mProjectionMatrix;
+
+ ///
+ ///
+ ///
+ BlendMode mBlendMode;
+
+ ///
+ ///
+ ///
+ Color mColor;
+
+ ///
+ ///
+ ///
+ Canvas* mCanvas;
+
+ ///
+ ///
+ ///
+ Shaders::Shader* mShader;
+
+ ///
+ ///
+ ///
+ Fonts::Font* mFont;
+
+ ///
+ ///
+ ///
+ Stats mStats;
+
+ };
+
+ // Singleton.
+ extern OpenGL gl;
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // __JE_OPENGL_H__ \ No newline at end of file