diff options
Diffstat (limited to 'source/modules/asura-core/graphics/canvas.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/canvas.cpp | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index e922a51..60c8f87 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -1,50 +1,49 @@ #include "Canvas.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Canvas::Canvas() + : m_Width(0) + , m_Height(0) + , m_FBO(0) { - namespace Graphics - { + // Fix: ôСʼʱframebufferԴ + //glGenFramebuffers(1, &m_FBO); + //GLint current_fbo; + //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); +} - Canvas::Canvas() - : m_Width(0) - , m_Height(0) - , m_FBO(0) +void Canvas::SetSize(uint w, uint h) +{ + if (m_FBO == 0) + { + glGenFramebuffers(1, &m_FBO); + if (m_FBO == 0) + throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); + // + if (m_TexID == 0) { - // Fix: ôСʼʱframebufferԴ - //glGenFramebuffers(1, &m_FBO); - //GLint current_fbo; - //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); - //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); - //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures cannot generate texture."); } + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } + GLint current_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + glBindTexture(GL_TEXTURE_2D, m_TexID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, current_tex); +} - void Canvas::SetSize(uint w, uint h) - { - if (m_FBO == 0) - { - glGenFramebuffers(1, &m_FBO); - if (m_FBO == 0) - throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); - // - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures cannot generate texture."); - } - GLint current_fbo; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); - glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); - } - GLint current_tex; - glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); - glBindTexture(GL_TEXTURE_2D, m_TexID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, current_tex); - } +namespace_end - } -}
\ No newline at end of file +namespace_end
\ No newline at end of file |