diff options
author | chai <chaifix@163.com> | 2018-10-16 23:09:18 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-16 23:09:18 +0800 |
commit | 5534828032730762f8c1e4daf924b466fffb8be0 (patch) | |
tree | 1ae83fc877e4a2d136f6dd120260edd147b13e95 /src/libjin/Graphics/Canvas.cpp | |
parent | 0fc4b3ad5f2ac8d5c0588f61c0cbed4349ee1430 (diff) |
*格式化代码
Diffstat (limited to 'src/libjin/Graphics/Canvas.cpp')
-rw-r--r-- | src/libjin/Graphics/Canvas.cpp | 180 |
1 files changed, 90 insertions, 90 deletions
diff --git a/src/libjin/Graphics/Canvas.cpp b/src/libjin/Graphics/Canvas.cpp index d34731a..6db06c6 100644 --- a/src/libjin/Graphics/Canvas.cpp +++ b/src/libjin/Graphics/Canvas.cpp @@ -7,96 +7,96 @@ namespace jin { -namespace graphics -{ - - /*class member*/ const Canvas* Canvas::current = nullptr; - /*class member*/ const Canvas* const Canvas::DEFAULT_CANVAS = new Canvas(0); - - /*class member*/ Canvas* Canvas::createCanvas(int w, int h) - { - return new Canvas(w, h); - } - - Canvas::Canvas(GLuint n) - : fbo(n) - { - } - - Canvas::Canvas(int w, int h) - : Drawable(w, h) - { - GLint current_fbo; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - - /* generate a new render buffer object */ - fbo = gl.genFrameBuffer(); - gl.bindFrameBuffer(fbo); - - /* generate texture save target */ - texture = gl.genTexture(); - gl.bindTexture(texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - gl.bindTexture(0); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - - /* unbind framebuffer */ - gl.bindFrameBuffer(current_fbo); - } - - Canvas::~Canvas() - { - } - - /*class member*/ bool Canvas::isBinded(const Canvas* cvs) - { - return current == cvs; - } - - /** - * bind to canvas - */ - /*class member*/ void Canvas::bind(Canvas* canvas) - { - if (isBinded(canvas)) return; - current = canvas; - gl.bindFrameBuffer(canvas->fbo); - int w = canvas->size.w; - int h = canvas->size.h; - /* set view port to canvas */ - glViewport(0, 0, w, h); - gl.ProjectionMatrix.setOrtho(0, w, 0, h, -1, 1); - } - - /** - * 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 - */ - /*class member*/ void Canvas::unbind() - { - if (isBinded(DEFAULT_CANVAS)) return; - current = DEFAULT_CANVAS; - /* get window size as viewport */ - Window* wnd = Window::get(); - int w = wnd->getW(); - int h = wnd->getH(); - - glBindFramebuffer(GL_FRAMEBUFFER, DEFAULT_CANVAS->fbo); - - /* set viewport on screen */ - glViewport(0, 0, w, h); - - gl.ProjectionMatrix.setOrtho(0, w, h, 0, -1, 1); - - } - -} // render + namespace graphics + { + + /*class member*/ const Canvas* Canvas::current = nullptr; + /*class member*/ const Canvas* const Canvas::DEFAULT_CANVAS = new Canvas(0); + + /*class member*/ Canvas* Canvas::createCanvas(int w, int h) + { + return new Canvas(w, h); + } + + Canvas::Canvas(GLuint n) + : fbo(n) + { + } + + Canvas::Canvas(int w, int h) + : Drawable(w, h) + { + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + + /* generate a new render buffer object */ + fbo = gl.genFrameBuffer(); + gl.bindFrameBuffer(fbo); + + /* generate texture save target */ + texture = gl.genTexture(); + gl.bindTexture(texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + gl.bindTexture(0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + /* unbind framebuffer */ + gl.bindFrameBuffer(current_fbo); + } + + Canvas::~Canvas() + { + } + + /*class member*/ bool Canvas::isBinded(const Canvas* cvs) + { + return current == cvs; + } + + /** + * bind to canvas + */ + /*class member*/ void Canvas::bind(Canvas* canvas) + { + if (isBinded(canvas)) return; + current = canvas; + gl.bindFrameBuffer(canvas->fbo); + int w = canvas->size.w; + int h = canvas->size.h; + /* set view port to canvas */ + glViewport(0, 0, w, h); + gl.ProjectionMatrix.setOrtho(0, w, 0, h, -1, 1); + } + + /** + * 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 + */ + /*class member*/ void Canvas::unbind() + { + if (isBinded(DEFAULT_CANVAS)) return; + current = DEFAULT_CANVAS; + /* get window size as viewport */ + Window* wnd = Window::get(); + int w = wnd->getW(); + int h = wnd->getH(); + + glBindFramebuffer(GL_FRAMEBUFFER, DEFAULT_CANVAS->fbo); + + /* set viewport on screen */ + glViewport(0, 0, w, h); + + gl.ProjectionMatrix.setOrtho(0, w, h, 0, -1, 1); + + } + + } // render } // jin #endif // LIBJIN_MODULES_RENDER
\ No newline at end of file |