aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/je_gl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/je_gl.cpp')
-rw-r--r--src/libjin/graphics/je_gl.cpp52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp
index 72ebb45..a6abd34 100644
--- a/src/libjin/graphics/je_gl.cpp
+++ b/src/libjin/graphics/je_gl.cpp
@@ -3,10 +3,13 @@
#include "je_color.h"
#include "je_canvas.h"
#include "je_texture.h"
+#include "je_window.h"
#include "shaders/je_shader.h"
#include "fonts/je_font.h"
using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
@@ -15,6 +18,8 @@ namespace JinEngine
OpenGL gl;
+ const Canvas* const OpenGL::DEFAULT_CANVAS = new Canvas(0);
+
OpenGL::OpenGL()
: mBlendMode(BlendMode::NONE)
{
@@ -79,11 +84,6 @@ namespace JinEngine
glBindTexture(GL_TEXTURE_2D, texture);
}
- GLuint OpenGL::curTexture()
- {
- return mTexture;
- }
-
void OpenGL::deleteTexture(GLuint texture)
{
glDeleteTextures(1, &texture);
@@ -292,7 +292,8 @@ namespace JinEngine
{
if (shader)
{
- shader->use();
+ glUseProgram(shader->getGLProgramID());
+ shader->setDefaultUniform();
mShader = shader;
}
}
@@ -301,7 +302,7 @@ namespace JinEngine
{
if (mShader)
{
- mShader->unuse();
+ glUseProgram(0);
mShader = nullptr;
}
}
@@ -315,18 +316,43 @@ namespace JinEngine
{
if (canvas)
{
- Canvas::bind(canvas);
+ GLuint fbo = canvas->getGLFrameBuffer();
+ gl.bindFrameBuffer(fbo);
+ int w = canvas->getWidth();
+ int h = canvas->getHeight();
+ glViewport(0, 0, w, h);
+ gl.setProjectionMatrix(0, w, 0, h, -1, 1);
+
mCanvas = canvas;
}
}
+ /**
+ * bind to default screen render buffer.
+ * do some coordinates transform work
+ * https://blog.csdn.net/liji_digital/article/details/79370841
+ * https://blog.csdn.net/lyx2007825/article/details/8792475
+ */
void OpenGL::unbindCanvas()
{
- if (mCanvas)
- {
- mCanvas->unbind();
- mCanvas = nullptr;
- }
+ // Default bind to default canvas.
+ if (getCanvas() == DEFAULT_CANVAS)
+ return;
+ // Get window size as viewport.
+ Window* wnd = Window::get();
+ int w = wnd->getW();
+ int h = wnd->getH();
+ GLuint fbo = DEFAULT_CANVAS->getGLFrameBuffer();
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glViewport(0, 0, w, h);
+ gl.setProjectionMatrix(0, w, h, 0, -1, 1);
+
+ mCanvas = nullptr;
+ }
+
+ Canvas* OpenGL::getCanvas()
+ {
+ return mCanvas;
}
void OpenGL::setFont(Fonts::Font* font)