diff options
Diffstat (limited to 'source/modules/asura-core/graphics')
-rw-r--r-- | source/modules/asura-core/graphics/binding/_image.cpp | 51 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/binding/_texture.cpp | 86 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/binding/_window.cpp | 103 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/canvas.cpp | 4 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/canvas.h | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/color32.cpp | 16 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/color32.h | 7 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/image.cpp | 5 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/image.h | 10 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader.cpp | 2 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader.h | 27 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/shader_source.h | 30 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/texture.cpp | 8 | ||||
-rw-r--r-- | source/modules/asura-core/graphics/texture.h | 25 |
14 files changed, 217 insertions, 159 deletions
diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 1d43067..cc9a669 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -9,6 +9,8 @@ namespace AsuraEngine LUAX_REGISTRY(Image) { + LUAX_INHERIT(state, Texture); + LUAX_REGISTER_METHODS(state, { "New", _New }, { "Refresh", _Refresh }, @@ -22,55 +24,68 @@ namespace AsuraEngine LUAX_POSTPROCESS(Image) { - } - // Image.New() + // image = Image.New() LUAX_IMPL_METHOD(Image, _New) { LUAX_STATE(L); - - return 0; + Image* img = new Image(); + img->PushLuaxUserdata(state); + return 1; } - // image:Refresh() + // successed = image:Refresh(imgData) LUAX_IMPL_METHOD(Image, _Refresh) { LUAX_PREPARE(L, Image); - - return 0; + ImageData* imgData = state.CheckUserdata<ImageData>(2); + bool successed = self->Refresh(imgData); + if (successed) + self->SetLuaxMemberRef(state, self->mImageDataRef, 2); + state.Push(successed); + return 1; } - // image:GetWidth() + // width = image:GetWidth() LUAX_IMPL_METHOD(Image, _GetWidth) { LUAX_PREPARE(L, Image); - - return 0; + state.Push(self->GetWidth()); + return 1; } - // image:GetHeight() + // height = image:GetHeight() LUAX_IMPL_METHOD(Image, _GetHeight) { LUAX_PREPARE(L, Image); - - return 0; + state.Push(self->GetHeight()); + return 1; } - // image:GetSize() + // width, height = image:GetSize() LUAX_IMPL_METHOD(Image, _GetSize) { LUAX_PREPARE(L, Image); - - return 0; + int width = self->GetWidth(); + int height = self->GetHeight(); + state.Push(width); + state.Push(height); + return 2; } - // image:GetPixel() + // color32 = image:GetPixel(x, y) LUAX_IMPL_METHOD(Image, _GetPixel) { LUAX_PREPARE(L, Image); - return 0; + uint x, y; + x = state.CheckValue<uint>(2); + y = state.CheckValue<uint>(3); + Color32* c32 = new Color32(); + c32->Set(self->GetPixel(x, y)); + c32->PushLuaxUserdata(state); + return 1; } // image:Render() diff --git a/source/modules/asura-core/graphics/binding/_texture.cpp b/source/modules/asura-core/graphics/binding/_texture.cpp new file mode 100644 index 0000000..489d362 --- /dev/null +++ b/source/modules/asura-core/graphics/binding/_texture.cpp @@ -0,0 +1,86 @@ +#include "../texture.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Texture) + { + LUAX_REGISTER_METHODS(state, + { "SetFilterMode", _SetFilterMode }, + { "SetWrapMode", _SetWrapMode }, + { "GetFilterMode", _GetFilterMode }, + { "GetWrapMode", _GetWrapMode }, + { "IsGenMipmap", _IsGenMipmap } + ); + } + + LUAX_POSTPROCESS(Texture) + { + LUAX_REGISTER_ENUM(state, "EColorFormat", + { "UNKNOWN", COLOR_FORMAT_UNKNOWN }, + { "RGBA8", COLOR_FORMAT_RGBA8 }, + { "RGBA32F", COLOR_FORMAT_RGBA32F } + ); + LUAX_REGISTER_ENUM(state, "EFilterMode", + { "NEAREST", FILTER_MODE_NEAREST }, + { "LINEAR", FILTER_MODE_LINEAR } + ); + LUAX_REGISTER_ENUM(state, "EWrapMode", + { "REPEAT", WRAP_MODE_REPEAT }, + { "MIRROR", WRAP_MODE_MIRROR }, + { "CLAMPTOEDGE", WRAP_MODE_CLAMPTOEDGE }, + { "CLAMPTOBORDER", WRAP_MODE_CLAMPTOBORDER } + ); + + } + + // texture:SetFilterMode(minFilter, magFilter) + LUAX_IMPL_METHOD(Texture, _SetFilterMode) + { + LUAX_PREPARE(L, Texture); + FilterMode min = (FilterMode)state.CheckValue<int>(2); + FilterMode mag = (FilterMode)state.CheckValue<int>(3); + self->SetFilterMode(min, mag); + return 0; + } + + // texture:SetWrapMode(wrap_mode) + LUAX_IMPL_METHOD(Texture, _SetWrapMode) + { + LUAX_PREPARE(L, Texture); + WrapMode wrap_mode = (WrapMode)state.CheckValue<int>(2); + self->SetWrapMode(wrap_mode); + return 0; + } + + // min, mag = texture:GetFilterMode() + LUAX_IMPL_METHOD(Texture, _GetFilterMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->mMinFilter); + state.Push((int)self->mMagFilter); + return 2; + } + + // wrapmode= texture:GetWrapMode() + LUAX_IMPL_METHOD(Texture, _GetWrapMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->mWrapMode); + return 1; + } + + // texture:IsGenMipmap() + LUAX_IMPL_METHOD(Texture, _IsGenMipmap) + { + LUAX_PREPARE(L, Texture); + state.Push(self->IsGenMipmap()); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_window.cpp b/source/modules/asura-core/graphics/binding/_window.cpp deleted file mode 100644 index fc74d6c..0000000 --- a/source/modules/asura-core/graphics/binding/_window.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "../window.h" - -using namespace std; - -namespace AsuraEngine -{ - namespace Graphics - { - - LUAX_REGISTRY(Window) - { - LUAX_REGISTER_METHODS(state, - { "Show", _Show }, - { "Hide", _Hide }, - { "SetResolution", _SetResolution }, - { "SetFullScreen", _SetFullScreen }, - { "SetTitle", _SetTitle }, - { "SetWindowStyle", _SetWindowStyle }, - { "Clear", _Clear }, - { "Draw", _Draw }, - { "SwapRenderBuffer", _SwapRenderBuffer } - ); - } - - LUAX_POSTPROCESS(Window) - { - - } - - // window:Show() - LUAX_IMPL_METHOD(Window, _Show) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:Hide() - LUAX_IMPL_METHOD(Window, _Hide) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:SetResolution() - LUAX_IMPL_METHOD(Window, _SetResolution) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:SetFullScreen() - LUAX_IMPL_METHOD(Window, _SetFullScreen) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:SetTitle() - LUAX_IMPL_METHOD(Window, _SetTitle) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:SetWindowStyle() - LUAX_IMPL_METHOD(Window, _SetWindowStyle) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:Clear() - LUAX_IMPL_METHOD(Window, _Clear) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:Draw() - LUAX_IMPL_METHOD(Window, _Draw) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - // window:SwapRenderBuffer() - LUAX_IMPL_METHOD(Window, _SwapRenderBuffer) - { - LUAX_PREPARE(L, Window); - - return 0; - } - - } -} diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index e54ba1f..8b556d9 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -14,7 +14,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, mTexHandle, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0); glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); } @@ -22,7 +22,7 @@ namespace AsuraEngine { GLint current_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); - glBindTexture(GL_TEXTURE_2D, mTexHandle); + glBindTexture(GL_TEXTURE_2D, mTex); 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 d1412da..f0b71e2 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -62,7 +62,7 @@ namespace AsuraEngine //----------------------------------------------------------------------------// - LUAX_DECL_FACTORY(SimCanvas); + LUAX_DECL_FACTORY(Canvas); LUAX_DECL_METHOD(_SetSize); LUAX_DECL_METHOD(_Bind); diff --git a/source/modules/asura-core/graphics/color32.cpp b/source/modules/asura-core/graphics/color32.cpp index 0ebc77c..28260d5 100644 --- a/source/modules/asura-core/graphics/color32.cpp +++ b/source/modules/asura-core/graphics/color32.cpp @@ -6,6 +6,14 @@ namespace AsuraEngine namespace Graphics { +#if ASURA_LITTLE_ENDIAN + // СˣֽڵAlphaڸߵַ + const uint32 Color32::RMASK = 0x000000ff; + const uint32 Color32::GMASK = 0x0000ff00; + const uint32 Color32::BMASK = 0x00ff0000; + const uint32 Color32::AMASK = 0xff000000; +#endif + Color32::Color32() { r = g = b = a = 0; @@ -35,5 +43,13 @@ namespace AsuraEngine this->a = a; } + void Color32::Set(const Color32& c32) + { + r = c32.r; + g = c32.g; + b = c32.b; + a = c32.a; + } + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/color32.h b/source/modules/asura-core/graphics/color32.h index 2b13d1a..5b10931 100644 --- a/source/modules/asura-core/graphics/color32.h +++ b/source/modules/asura-core/graphics/color32.h @@ -22,6 +22,11 @@ namespace AsuraEngine LUAX_DECL_FACTORY(Color32); + static const uint32 RMASK; + static const uint32 GMASK; + static const uint32 BMASK; + static const uint32 AMASK; + Color32(); ~Color32(); @@ -32,6 +37,8 @@ namespace AsuraEngine Color32(byte r, byte g, byte b, byte a); + void Set(const Color32& c32); + byte r, g, b, a; LUAX_DECL_METHOD(_ToColor); diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index e0528eb..bdd8c3d 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -26,16 +26,13 @@ namespace AsuraEngine ImageData* imgData = static_cast<ImageData*>(data); ASSERT(imgData); - glBindTexture(GL_TEXTURE_2D, mTexHandle); + glBindTexture(GL_TEXTURE_2D, mTex); imgData->Lock(); - int width = imgData->width; int height = imgData->height; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData->pixels); mImageData = imgData; - imgData->Unlock(); glBindTexture(GL_TEXTURE_2D, 0); diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 377e002..06108ed 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -33,7 +33,7 @@ namespace AsuraEngine { public: - LUAX_DECL_FACTORY(SimImage); + LUAX_DECL_FACTORY(Image); Image(); @@ -46,11 +46,9 @@ namespace AsuraEngine bool Refresh(AEIO::DecodedData* decodeData) override; bool Refresh(AEIO::DecodedData* decodeData, const AEMath::Recti& rect); - - uint GetWidth(); - uint GetHeight(); - Math::Vector2u GetSize(); - Color32 GetPixel(uint x, uint y); + uint GetWidth(); + uint GetHeight(); + Color32 GetPixel(uint x, uint y); void Render(const RenderTarget* rt, const RenderState& state) override; diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 1a85866..c0c6f75 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -27,7 +27,7 @@ namespace AsuraEngine GLuint Shader::GetGLProgramHandle() { - return mProgramHandle; + return mProgram; } void Shader::Use() diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index 8c21ab2..df0fcca 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -13,6 +13,7 @@ #include <asura-utils/stringmap.hpp> #include <asura-utils/manager.hpp> +#include "shader_source.h" #include "color.h" #include "texture.h" #include "gl.h" @@ -23,8 +24,9 @@ namespace AsuraEngine { /// - /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ - /// ÿshaderͨshaderҵuniforms¶frameworkmaterialá + /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ + /// uniformsuseɫķ༭ÿshaderͨshaderҵuniforms + /// ¶frameworkmaterialá /// class Shader ASURA_FINAL : public Scripting::Portable<Shader> @@ -32,15 +34,18 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(Shader); + Shader(); ~Shader(); /// - /// ӴshaderʱȼǷϴλuniforms location mapʹglAttachShader±ɫ - /// ɫ + /// ӴshaderʱȼǷϴλuniforms location mapʹ + /// glAttachShader±ɫɫ /// - bool Load(const std::string& vertexShader, const std::string& fragmentShader); + //bool Load(const std::string& vertexShader, const std::string& fragmentShader); + bool Refresh(AEIO::DecodedData* decodeData) override; /// /// shaderΪ @@ -92,13 +97,13 @@ namespace AsuraEngine /// /// OpenGL shader program handle. /// - GLuint mProgramHandle; + GLuint mProgram; - //------------------------------------------------------------------------------// + Luax::LuaxMemberRef mCodeRef; - public: + private: - LUAX_DECL_FACTORY(SimShader); + //----------------------------------------------------------------------------// LUAX_DECL_METHOD(_New); LUAX_DECL_METHOD(_Use); @@ -114,9 +119,7 @@ namespace AsuraEngine LUAX_DECL_METHOD(_SetUniformVector4); LUAX_DECL_METHOD(_SetUniformColor); - private: - - Luax::LuaxMemberRef mCodeLuaRef; + //----------------------------------------------------------------------------// }; diff --git a/source/modules/asura-core/graphics/shader_source.h b/source/modules/asura-core/graphics/shader_source.h new file mode 100644 index 0000000..b3e815c --- /dev/null +++ b/source/modules/asura-core/graphics/shader_source.h @@ -0,0 +1,30 @@ +#ifndef __ASURA_SHADER_SOURCE_H__ +#define __ASURA_SHADER_SOURCE_H__ + +#include <string> + +#include <asura-utils/io/decoded_data.h> + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// Asura EngineʹõshaderԴ룬GLSL + /// + class ShaderSouce : public AEIO::DecodedData + { + public: + void Decode(AEIO::DataBuffer& buffer) override; + + private: + std::string mVert; + std::string mFrag; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index 0897702..c260ce9 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -6,20 +6,20 @@ namespace AsuraEngine { Texture::Texture() - : mTexHandle(0) + : mTex(0) { // GL texture - glGenTextures(1, &mTexHandle); + glGenTextures(1, &mTex); } Texture::~Texture() { - glDeleteTextures(1, &mTexHandle); + glDeleteTextures(1, &mTex); } GLuint Texture::GetGLTextureHandle() const { - return mTexHandle; + return mTex; } } diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index a76e1d4..02d3407 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -22,7 +22,6 @@ namespace AsuraEngine WRAP_MODE_MIRROR, WRAP_MODE_CLAMPTOEDGE, WRAP_MODE_CLAMPTOBORDER, - //WRAP_MODE_PERAXIS, // UVвͬ4ֵ }; enum FilterMode @@ -47,11 +46,11 @@ namespace AsuraEngine /// ϲԵѿϵΪEditorҲϽΪԭ㣬Ϊ /// 㡣 /// - ASURA_ABSTRACT class Texture + ASURA_ABSTRACT class Texture : virtual public AEScripting::NativeAccessor { public: - LUAX_DECL_ABSTRACT_FACTORY(); + LUAX_DECL_ABSTRACT_FACTORY(Texture); Texture(); virtual ~Texture(); @@ -67,7 +66,7 @@ namespace AsuraEngine /// /// UVfilterΪ /// - void IsGenMipmap(); + bool IsGenMipmap(); /// /// ȾtexturertϣԭϽǣң @@ -81,11 +80,21 @@ namespace AsuraEngine protected: - LUAX_DECL_ENUM(ColorFormat); - LUAX_DECL_ENUM(FilterMode); - LUAX_DECL_ENUM(WrapMode); + //----------------------------------------------------------------------------// - GLuint mTexHandle; + LUAX_DECL_ENUM(ColorFormat, 1); + LUAX_DECL_ENUM(FilterMode, 1); + LUAX_DECL_ENUM(WrapMode, 1); + + LUAX_DECL_METHOD(_SetFilterMode); + LUAX_DECL_METHOD(_SetWrapMode); + LUAX_DECL_METHOD(_GetFilterMode); + LUAX_DECL_METHOD(_GetWrapMode); + LUAX_DECL_METHOD(_IsGenMipmap); + + //----------------------------------------------------------------------------// + + GLuint mTex; FilterMode mMinFilter; FilterMode mMagFilter; |