From ecd7883521cbde02f4f1a6b23a7b3b601c32dbef Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 29 Jul 2019 09:06:09 +0800 Subject: *misc --- source/modules/asura-core/graphics/canvas.cpp | 12 ++++++------ source/modules/asura-core/graphics/canvas.h | 2 +- source/modules/asura-core/graphics/image.cpp | 10 +++++----- source/modules/asura-core/graphics/texture.cpp | 14 +++++--------- source/modules/asura-core/graphics/texture.h | 19 +++++-------------- source/modules/asura-core/graphics/vertex_buffer.h | 3 +-- 6 files changed, 23 insertions(+), 37 deletions(-) (limited to 'source/modules/asura-core/graphics') diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index 0543461..0a17085 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -15,7 +15,7 @@ namespace AsuraEngine //GLint current_fbo; //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); //glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0); + //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexID, 0); //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); } @@ -27,21 +27,21 @@ namespace AsuraEngine if (mFBO == 0) throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); // 申请纹理 - if (mTex == 0) + if (mTexID == 0) { - glGenTextures(1, &mTex); - if (mTex == 0) + glGenTextures(1, &mTexID); + if (mTexID == 0) throw Exception("OpenGL glGenTextures cannot generate texture."); } GLint current_fbo; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexID, 0); glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); } GLint current_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); - glBindTexture(GL_TEXTURE_2D, mTex); + glBindTexture(GL_TEXTURE_2D, mTexID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, current_tex); } diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 03326df..e2e713c 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -49,7 +49,7 @@ namespace AsuraEngine GLuint mFBO; - GLuint mTex; + GLuint mTexID; uint mWidth, mHeight; diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index ef01730..1d74d27 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -28,14 +28,14 @@ namespace AsuraEngine { if (!imgData) return false; - if (mTex == 0) + if (mTexID == 0) { - glGenTextures(1, &mTex); - if (mTex == 0) + glGenTextures(1, &mTexID); + if (mTexID == 0) throw Exception("OpenGL glGenTextures failed."); } - glBindTexture(GL_TEXTURE_2D, mTex); + glBindTexture(GL_TEXTURE_2D, mTexID); imgData->Lock(); int width = imgData->width; int height = imgData->height; @@ -66,7 +66,7 @@ namespace AsuraEngine { if (!imgData) return false; - glBindTexture(GL_TEXTURE_2D, mTex); + glBindTexture(GL_TEXTURE_2D, mTexID); imgData->Lock(); int width = imgData->width; int height = imgData->height; diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index 3438334..240a5f8 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -8,24 +8,20 @@ namespace AsuraEngine { Texture::Texture() - : mTex(0) + : mTexID(0) { - // Fix: 等需要的时候再申请纹理资源 - //glGenTextures(1, &mTex); - //if(mTex == 0) - // throw Exception("Cannot create texture."); } Texture::~Texture() { // 释放纹理资源 - if(mTex != 0) - glDeleteTextures(1, &mTex); + if(mTexID != 0) + glDeleteTextures(1, &mTexID); } GLuint Texture::GetGLTexture() const { - return mTex; + return mTexID; } TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) @@ -44,7 +40,7 @@ namespace AsuraEngine t.type = GL_FLOAT; break; default: - ASSERT(false); // cant reach here + ASSERT(false); } return t; } diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 7cfddec..e16990c 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -16,6 +16,7 @@ namespace AsuraEngine class RenderTarget; + /// UV采样方式 enum WrapMode { WRAP_MODE_REPEAT, @@ -24,38 +25,32 @@ namespace AsuraEngine WRAP_MODE_CLAMPTOBORDER, }; + /// 滤波模式 enum FilterMode { FILTER_MODE_NEAREST, FILTER_MODE_LINEAR, }; - /// /// 图像数据的颜色格式 - /// enum ColorFormat { COLOR_FORMAT_UNKNOWN, - COLOR_FORMAT_RGBA8, ///< RGBA都是8bits int COLOR_FORMAT_RGBA32F, ///< RGBA都是32bits float }; - /// /// 纹理格式,GPU内部和CPU外部格式 - /// struct TextureFormat { GLenum internalformat; ///< GPU内部格式 - GLenum externalformat; ///< CPU外部格式 GLenum type; ///< 外部格式每个channel数值类型 }; /// - /// 2D纹理抽象类,在2d mesh和render target中被使用。Texture的渲染原点在左上角,游戏里 - /// 面的上层会以笛卡尔坐标系为标准。在Editor里面界面和组件也是以左上角为原点,这样是为了 - /// 方便。 + /// 2D纹理抽象类,在2d mesh和render target中被使用。Texture的渲染原点在左上角,游戏里面的上层会以笛卡尔 + /// 坐标系为标准。在Editor里面界面和组件也是以左上角为原点,这样是为了方便。 /// ASURA_ABSTRACT class Texture : public AEScripting::Object { @@ -74,19 +69,15 @@ namespace AsuraEngine void GetFilterMode(); void GetWrapMode(); - /// /// 如果设置U或V方向filter为 - /// bool IsGenMipmap(); protected: - /// /// 转换color format为texture format。 - /// TextureFormat ConvertColorFormat(const ColorFormat& colorformat); - GLuint mTex; + GLuint mTexID; FilterMode mMinFilter; FilterMode mMagFilter; WrapMode mWrapMode; diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h index 83ca4d1..c16c6d2 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -11,8 +11,7 @@ namespace AsuraEngine { /// - /// 向framework提供了创建显存缓冲的功能,可以直接设置缓冲,绝大多数功能都可以通过此类 - /// 直接设置顶点数据。 + /// 向framework提供了创建显存缓冲的功能,可以直接设置缓冲,绝大多数功能都可以通过此类直接设置顶点数据。 /// class VertexBuffer ASURA_FINAL : public AEScripting::Portable -- cgit v1.1-26-g67d0