aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Canvas.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/libjin/Graphics/Canvas.cpp
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/libjin/Graphics/Canvas.cpp')
-rw-r--r--src/libjin/Graphics/Canvas.cpp135
1 files changed, 0 insertions, 135 deletions
diff --git a/src/libjin/Graphics/Canvas.cpp b/src/libjin/Graphics/Canvas.cpp
deleted file mode 100644
index f5bd09f..0000000
--- a/src/libjin/Graphics/Canvas.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-#include "../modules.h"
-#if JIN_MODULES_RENDER
-
-#include "../utils/macros.h"
-#include "canvas.h"
-#include "window.h"
-
-namespace jin
-{
-namespace graphics
-{
-
- shared Canvas* Canvas::createCanvas(int w, int h)
- {
- return new Canvas(w, h);
- }
-
- Canvas::Canvas(int w, int h)
- : Drawable(w, h)
- {
- init();
- }
-
- Canvas::~Canvas()
- {
- }
-
- shared GLint Canvas::cur = -1;
-
- bool Canvas::init()
- {
- setVertices(
- new float [DRAWABLE_V_SIZE] {
- 0, 0,
- 0, (float)height,
- (float)width, (float)height,
- (float)width, 0,
- },
- new float [DRAWABLE_V_SIZE] {
- 0, 1,
- 0, 0,
- 1, 0,
- 1, 1
- }
- );
-
- GLint current_fbo;
- glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
-
- // generate a new render buffer object
- glGenFramebuffers(1, &fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
-
- // generate texture save target
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
-
- GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-
- // unbind framebuffer
- glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
-
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
- return false;
- return true;
- }
-
- bool Canvas::hasbind(GLint fbo)
- {
- return cur == fbo;
- }
-
- /**
- * bind to canvas
- */
- void Canvas::bind()
- {
- if (hasbind(fbo)) return;
-
- cur = fbo;
-
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- glViewport(0, 0, width, height);
- glOrtho(0, width, height, 0, -1, 1);
-
- // Switch back to modelview matrix
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- }
-
- /**
- * bind to default screen render buffer.
- */
- shared void Canvas::unbind()
- {
- if (hasbind(0)) return;
-
- cur = 0;
-
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- Window* wnd = Window::get();
- int ww = wnd->getW(),
- wh = wnd->getH();
-
- glViewport(0, 0, ww, wh);
-
- // load back to normal
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- // set viewport matrix
- glOrtho(0, ww, wh, 0, -1, 1);
-
- // switch to model matrix
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- }
-
-} // render
-} // jin
-
-#endif // JIN_MODULES_RENDER \ No newline at end of file