diff options
author | chai <chaifix@163.com> | 2019-04-02 21:45:33 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-02 21:45:33 +0800 |
commit | af7bdaa10ee71a319dc55c3c7556fa43a95c9dc9 (patch) | |
tree | 58611985001b78c5a76b78ae146fdb07dde31c1d | |
parent | 250e30d73f09e9da2b5a81d0fbae63744ae12a73 (diff) |
*misc
46 files changed, 1132 insertions, 251 deletions
diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj b/Build/Asura.Editor/Asura.Editor.vcxproj index c582aac..82a4133 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj +++ b/Build/Asura.Editor/Asura.Editor.vcxproj @@ -149,6 +149,7 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\textbox.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\vslider.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\widget.h" /> + <ClInclude Include="..\..\source\Asura.Editor\core\shaders.h" /> <ClInclude Include="..\..\source\Asura.Editor\core\slot.h" /> <ClInclude Include="..\..\source\Asura.Editor\core\signal.h" /> <ClInclude Include="..\..\source\Asura.Editor\dui_module.h" /> diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj.filters b/Build/Asura.Editor/Asura.Editor.vcxproj.filters index a87c4cb..8bb459d 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/Build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -121,5 +121,8 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\menu_item.h"> <Filter>controls</Filter> </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\core\shaders.h"> + <Filter>core</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Build/Asura.sln b/Build/Asura.sln index 9513df5..02856f6 100644 --- a/Build/Asura.sln +++ b/Build/Asura.sln @@ -107,6 +107,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "win32", "win32", "{6096DD65 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "01-window", "tests\win32\01-window\01-window.vcxproj", "{B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asura-log", "modules\asura-log\asura-log.vcxproj", "{11619483-427E-490F-9E82-4FED3591E93F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -589,6 +591,16 @@ Global {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}.Release|x64.Build.0 = Release|x64 {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}.Release|x86.ActiveCfg = Release|Win32 {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}.Release|x86.Build.0 = Release|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x64.ActiveCfg = Debug|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x64.Build.0 = Debug|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x86.ActiveCfg = Debug|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x86.Build.0 = Debug|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|Any CPU.ActiveCfg = Release|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x64.ActiveCfg = Release|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x64.Build.0 = Release|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x86.ActiveCfg = Release|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -636,6 +648,7 @@ Global {72119950-3542-41AD-97EB-DC4856FC16AA} = {E068D138-C824-4365-B5A3-27C65E8FD0B5} {6096DD65-FE67-4D0F-BEF4-4D81A1554A3A} = {E068D138-C824-4365-B5A3-27C65E8FD0B5} {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA} = {6096DD65-FE67-4D0F-BEF4-4D81A1554A3A} + {11619483-427E-490F-9E82-4FED3591E93F} = {CD115016-E377-4AC1-8595-DB2836CEFE7E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {331032D8-F7CC-43E3-A03B-67108767F96B} diff --git a/bin/win64/01-window.exe b/bin/win64/01-window.exe Binary files differindex 71ec490..dd108a0 100644 --- a/bin/win64/01-window.exe +++ b/bin/win64/01-window.exe diff --git a/bin/win64/SDL2.dll b/bin/win64/SDL2.dll Binary files differindex a88528d..3d3c59e 100644 --- a/bin/win64/SDL2.dll +++ b/bin/win64/SDL2.dll diff --git a/build/Asura.Editor/Asura.Editor.vcxproj b/build/Asura.Editor/Asura.Editor.vcxproj index c582aac..82a4133 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj +++ b/build/Asura.Editor/Asura.Editor.vcxproj @@ -149,6 +149,7 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\textbox.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\vslider.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\widget.h" /> + <ClInclude Include="..\..\source\Asura.Editor\core\shaders.h" /> <ClInclude Include="..\..\source\Asura.Editor\core\slot.h" /> <ClInclude Include="..\..\source\Asura.Editor\core\signal.h" /> <ClInclude Include="..\..\source\Asura.Editor\dui_module.h" /> diff --git a/build/Asura.Editor/Asura.Editor.vcxproj.filters b/build/Asura.Editor/Asura.Editor.vcxproj.filters index a87c4cb..8bb459d 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -121,5 +121,8 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\menu_item.h"> <Filter>controls</Filter> </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\core\shaders.h"> + <Filter>core</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/build/Asura.sln b/build/Asura.sln index 9513df5..02856f6 100644 --- a/build/Asura.sln +++ b/build/Asura.sln @@ -107,6 +107,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "win32", "win32", "{6096DD65 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "01-window", "tests\win32\01-window\01-window.vcxproj", "{B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asura-log", "modules\asura-log\asura-log.vcxproj", "{11619483-427E-490F-9E82-4FED3591E93F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -589,6 +591,16 @@ Global {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}.Release|x64.Build.0 = Release|x64 {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}.Release|x86.ActiveCfg = Release|Win32 {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}.Release|x86.Build.0 = Release|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x64.ActiveCfg = Debug|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x64.Build.0 = Debug|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x86.ActiveCfg = Debug|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Debug|x86.Build.0 = Debug|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|Any CPU.ActiveCfg = Release|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x64.ActiveCfg = Release|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x64.Build.0 = Release|x64 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x86.ActiveCfg = Release|Win32 + {11619483-427E-490F-9E82-4FED3591E93F}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -636,6 +648,7 @@ Global {72119950-3542-41AD-97EB-DC4856FC16AA} = {E068D138-C824-4365-B5A3-27C65E8FD0B5} {6096DD65-FE67-4D0F-BEF4-4D81A1554A3A} = {E068D138-C824-4365-B5A3-27C65E8FD0B5} {B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA} = {6096DD65-FE67-4D0F-BEF4-4D81A1554A3A} + {11619483-427E-490F-9E82-4FED3591E93F} = {CD115016-E377-4AC1-8595-DB2836CEFE7E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {331032D8-F7CC-43E3-A03B-67108767F96B} diff --git a/build/modules/asura-core/asura-core.vcxproj b/build/modules/asura-core/asura-core.vcxproj index e9b1c06..604e04d 100644 --- a/build/modules/asura-core/asura-core.vcxproj +++ b/build/modules/asura-core/asura-core.vcxproj @@ -141,6 +141,7 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\gif.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\gl.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\matrix_stack.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\mesh2d.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\quad.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\render_target.cpp" /> @@ -187,6 +188,7 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\gif.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\gl.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\graphics\matrix_stack.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\mesh2d.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\quad.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\render_state.h" /> diff --git a/build/modules/asura-core/asura-core.vcxproj.filters b/build/modules/asura-core/asura-core.vcxproj.filters index 0482ee1..b1d0c9b 100644 --- a/build/modules/asura-core/asura-core.vcxproj.filters +++ b/build/modules/asura-core/asura-core.vcxproj.filters @@ -182,6 +182,9 @@ <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_decode_task.cpp"> <Filter>image\binding</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\matrix_stack.cpp"> + <Filter>graphics</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\source\modules\asura-core\application.h" /> @@ -329,6 +332,9 @@ <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_sdl.h"> <Filter>window</Filter> </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\graphics\matrix_stack.h"> + <Filter>graphics</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\..\source\modules\asura-core\font\string.inl"> diff --git a/build/modules/asura-log/asura-log.vcxproj b/build/modules/asura-log/asura-log.vcxproj new file mode 100644 index 0000000..51e0383 --- /dev/null +++ b/build/modules/asura-log/asura-log.vcxproj @@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>15.0</VCProjectVersion> + <ProjectGuid>{11619483-427E-490F-9E82-4FED3591E93F}</ProjectGuid> + <RootNamespace>asuralog</RootNamespace> + <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup /> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <SDLCheck>true</SDLCheck> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <SDLCheck>true</SDLCheck> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/build/modules/asura-log/asura-log.vcxproj.filters b/build/modules/asura-log/asura-log.vcxproj.filters new file mode 100644 index 0000000..3c6f4fd --- /dev/null +++ b/build/modules/asura-log/asura-log.vcxproj.filters @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="源文件"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="头文件"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> + </Filter> + <Filter Include="资源文件"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/build/modules/asura-log/asura-log.vcxproj.user b/build/modules/asura-log/asura-log.vcxproj.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/build/modules/asura-log/asura-log.vcxproj.user @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup /> +</Project>
\ No newline at end of file diff --git a/source/Asura.Editor/controls/binding/_button.cpp b/source/Asura.Editor/controls/binding/_button.cpp index fbae64f..9e6a6bb 100644 --- a/source/Asura.Editor/controls/binding/_button.cpp +++ b/source/Asura.Editor/controls/binding/_button.cpp @@ -1,60 +1,74 @@ #include "../button.h" +using namespace std; using namespace Luax; -namespace AsuraEditor +namespace AsuraEditor { - - LUAX_REGISTRY(Button) + namespace Controls { + + LUAX_REGISTRY(Button) + { + LUAX_REGISTER_METHODS(state, + { "Connect", _Connect }, + { "Disconnect", _Disconnect }, + { "SetImage", _SetImage } + ); + } - // Button.EStatus.xxx - LUAX_REGISTER_ENUM(state, "EStatus", - { "NORMAL", BUTTON_STATUS_NORMAL }, - { "PUSHED", BUTTON_STATUS_PUSHED }, - { "HOVER", BUTTON_STATUS_HOVER }, - { "DISABLED", BUTTON_STATUS_DISABLED }, - { "FOCUSED", BUTTON_STATUS_FOCUSED } - ); - - // Button.EMsg.xxx - LUAX_REGISTER_ENUM(state, "EMessage", - { "CLICK", BUTTON_MSG_CLICK }, - { "HOVER", BUTTON_MSG_HOVER }, - { "FOCUS", BUTTON_MSG_KILLFOCUS } - ); + LUAX_POSTPROCESS(Button) + { + LUAX_REGISTER_ENUM(state, "EButtonStatus", + { "NORMAL", BUTTON_STATUS_NORMAL }, + { "0", 0 }, + { "PUSHED", BUTTON_STATUS_PUSHED }, + { "1", 1 }, + { "HOVER", BUTTON_STATUS_HOVER }, + { "2", 2 }, + { "DISABLED", BUTTON_STATUS_DISABLED }, + { "3", 3 }, + { "FOCUSED", BUTTON_STATUS_FOCUSED }, + { "4", 4 }, + { "STATUS_COUNT", _BUTTON_STATUS_COUNT }, + { "5", 5 } + ); + LUAX_REGISTER_ENUM(state, "EButtonMessage", + { "CLICK", BUTTON_MSG_CLICK }, + { "0", 0 }, + { "HOVER", BUTTON_MSG_HOVER }, + { "1", 1 }, + { "KILLFOCUS", BUTTON_MSG_KILLFOCUS }, + { "2", 2 }, + { "MSG_COUNT", _BUTTON_MSG_COUNT }, + { "3", 3 } + ); - } + } - LUAX_POSTPROCESS(Button) - { + // button:Connect() + LUAX_IMPL_METHOD(Button, _Connect) + { + LUAX_PREPARE(L, Button); - } + return 0; + } - // button:Connect(msg, callback) - LUAX_IMPL_METHOD(Button, _Connect) - { - LUAX_STATE(L); + // button:Disconnect() + LUAX_IMPL_METHOD(Button, _Disconnect) + { + LUAX_PREPARE(L, Button); - Button* self = state.GetUserdata<Button>(1); - int msg = state.CheckValue<int>(2); - if (!lua_isfunction(L, 3)) - return state.ErrorType(3, "callback"); + return 0; + } - LuaxMemberRef ref; - self->SetLuaxMemberRef(state, ref, 3); - if (ref) + // button:SetImage() + LUAX_IMPL_METHOD(Button, _SetImage) { - self->mCallbacksRef.push_back(ref); - Slot slot = Slot(state, (*self), ref.refID); - self->Connect(msg, slot); - } - } + LUAX_PREPARE(L, Button); - // button:SetImage(image) - LUAX_IMPL_METHOD(Button, _SetImage) - { + return 0; + } } - -}
\ No newline at end of file +} diff --git a/source/Asura.Editor/controls/button.cpp b/source/Asura.Editor/controls/button.cpp index 97de284..9910df4 100644 --- a/source/Asura.Editor/controls/button.cpp +++ b/source/Asura.Editor/controls/button.cpp @@ -3,8 +3,4 @@ namespace AsuraEditor { - Button::Button() - { - } - }
\ No newline at end of file diff --git a/source/Asura.Editor/controls/button.h b/source/Asura.Editor/controls/button.h index 3f07c1c..656d7d8 100644 --- a/source/Asura.Editor/controls/button.h +++ b/source/Asura.Editor/controls/button.h @@ -11,69 +11,72 @@ namespace AsuraEditor { - - enum ButtonStatus - { - BUTTON_STATUS_NORMAL = 0, - BUTTON_STATUS_PUSHED = 1, - BUTTON_STATUS_HOVER = 2, - BUTTON_STATUS_DISABLED = 3, - BUTTON_STATUS_FOCUSED = 4, - _BUTTON_STATUS_COUNT = 5, - }; - - enum ButtonMessage - { - BUTTON_MSG_CLICK = 0, - BUTTON_MSG_HOVER = 1, - BUTTON_MSG_KILLFOCUS = 2, - _BUTTON_MSG_COUNT = 3, - }; - - class Button - : public Widget - , public AEScripting::Portable<Button> + namespace Controls { - public: - LUAX_DECL_FACTORY(Button); + enum ButtonStatus + { + BUTTON_STATUS_NORMAL = 0, + BUTTON_STATUS_PUSHED = 1, + BUTTON_STATUS_HOVER = 2, + BUTTON_STATUS_DISABLED = 3, + BUTTON_STATUS_FOCUSED = 4, + _BUTTON_STATUS_COUNT = 5, + }; + + enum ButtonMessage + { + BUTTON_MSG_CLICK = 0, + BUTTON_MSG_HOVER = 1, + BUTTON_MSG_KILLFOCUS = 2, + _BUTTON_MSG_COUNT = 3, + }; + + class Button + : public Widget + , public AEScripting::Portable<Button> + { + public: + + LUAX_DECL_FACTORY(Button); - Button(); - ~Button(); + Button(); + ~Button(); - void OnEvent(AEInput::Event& e) override; - void OnPaint() override; + void OnEvent(AEInput::Event& e) override; + void OnPaint() override; - void Connect(int msg, Slot callback); - void Disconnect(int msg); - void DisconnectAll(int msg); - void DisconnectAllMsg(); + void Connect(int msg, Slot callback); + void Disconnect(int msg); + void DisconnectAll(int msg); + void DisconnectAllMsg(); - int GetStatus(); - void SetImage(int status, AEGraphics::Image* image); + int GetStatus(); + void SetImage(int status, AEGraphics::Image* image); - private: + private: - //------------------------------------------------------------------------------// + //------------------------------------------------------------------------------// - LUAX_DECL_ENUM(ButtonStatus); - LUAX_DECL_ENUM(ButtonMessage); + LUAX_DECL_ENUM(ButtonStatus, 1); + LUAX_DECL_ENUM(ButtonMessage, 1); - LUAX_DECL_METHOD(_Connect); - LUAX_DECL_METHOD(_Disconnect); - LUAX_DECL_METHOD(_SetImage); + LUAX_DECL_METHOD(_Connect); + LUAX_DECL_METHOD(_Disconnect); + LUAX_DECL_METHOD(_SetImage); - //------------------------------------------------------------------------------// + //------------------------------------------------------------------------------// - int mStatus; // ǰ״̬ - Signal mSignals[_BUTTON_MSG_COUNT]; // 3Ϣsignal - AEGraphics::Image* mImage[_BUTTON_STATUS_COUNT]; // 5״̬ͼ + int mStatus; // ǰ״̬ + Signal mSignals[_BUTTON_MSG_COUNT]; // 3Ϣsignal + AEGraphics::Image* mImage[_BUTTON_STATUS_COUNT]; // 5״̬ͼ - Luax::LuaxMemberRef mImageRef[_BUTTON_STATUS_COUNT];// ͼ - std::vector<Luax::LuaxMemberRef> mCallbacksRef; // ص + Luax::LuaxMemberRef mImageRef[_BUTTON_STATUS_COUNT];// ͼ + std::vector<Luax::LuaxMemberRef> mCallbacksRef; // ص - }; + }; + } } #endif
\ No newline at end of file diff --git a/source/Asura.Editor/core/shaders.h b/source/Asura.Editor/core/shaders.h new file mode 100644 index 0000000..5f4b406 --- /dev/null +++ b/source/Asura.Editor/core/shaders.h @@ -0,0 +1,9 @@ +#ifndef __ASURA_EDITOR_SHADERS_H__ +#define __ASURA_EDITOR_SHADERS_H__ + +namespace AsuraEditor +{ + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 407ada7..913bf5c 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -13,11 +13,10 @@ namespace AsuraEngine LUAX_REGISTER_METHODS(state, { "New", _New }, - { "Refresh", _Refresh }, + { "Renew", _Renew }, { "GetWidth", _GetWidth }, { "GetHeight", _GetHeight }, { "GetSize", _GetSize }, - { "GetPixel", _GetPixel }, { "Render", _Render } ); } @@ -35,15 +34,12 @@ namespace AsuraEngine return 1; } - // successed = image:Refresh(imgData) - LUAX_IMPL_METHOD(Image, _Refresh) + // successed = image:Renew(imgData) + LUAX_IMPL_METHOD(Image, _Renew) { LUAX_PREPARE(L, Image); ImageData* imgData = state.CheckUserdata<ImageData>(2); - bool successed = self->Refresh(imgData); - if (successed) - self->SetLuaxMemberRef(state, self->mImageDataRef, 2); - state.Push(successed); + state.Push(self->Renew(imgData)); return 1; } @@ -74,20 +70,6 @@ namespace AsuraEngine return 2; } - // color32 = image:GetPixel(x, y) - LUAX_IMPL_METHOD(Image, _GetPixel) - { - LUAX_PREPARE(L, Image); - - 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() LUAX_IMPL_METHOD(Image, _Render) { diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index 89be45c..0543461 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -8,21 +8,41 @@ namespace AsuraEngine Canvas::Canvas() : mWidth(0) , mHeight(0) + , mFBO(0) { - glGenFramebuffers(1, &mFBO); - 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); - glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + // Fix: ôСʼʱframebufferԴ + //glGenFramebuffers(1, &mFBO); + //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); + //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); } void Canvas::SetSize(uint w, uint h) { + if (mFBO == 0) + { + glGenFramebuffers(1, &mFBO); + if (mFBO == 0) + throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); + // + if (mTex == 0) + { + glGenTextures(1, &mTex); + if (mTex == 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); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } GLint current_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); glBindTexture(GL_TEXTURE_2D, mTex); - + 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 f0b71e2..6af81d7 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -4,6 +4,7 @@ #include <asura-utils/scripting/portable.hpp> #include <asura-utils/math/rect.hpp> #include <asura-utils/math/vector2.hpp> +#include <asura-utils/exceptions/exception.h> #include "gl.h" #include "texture.h" @@ -32,7 +33,7 @@ namespace AsuraEngine /// /// render textureĴС /// - void SetSize(uint w, uint h); + void SetSize(uint w, uint h) asura_throw(Exception); void Clear(const Color& col = Color::Black) override; diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp index 9ffe010..e199a41 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -1,7 +1,9 @@ #include <asura-utils/type.h> #include "../core_config.h" + #include "gl.h" +#include "shader.h" using namespace AEMath; @@ -10,15 +12,16 @@ namespace AsuraEngine namespace Graphics { - bool OpenGL::instantiated = false; + static bool _instantiated = false; // OpenGL gl; OpenGL::OpenGL() { - ASSERT(!instantiated); - instantiated = true; + // Ҫڶʵ + ASSERT(!_instantiated); + _instantiated = true; } OpenGL::~OpenGL() @@ -38,7 +41,16 @@ namespace AsuraEngine return state.viewport; } + void OpenGL::UseShader(Shader* shader) + { + glUseProgram(shader->GetGLProgramHandle()); + state.shader = shader; + } + void OpenGL::UnuseShader() + { + state.shader = nullptr; + } } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index 4d21a5a..9ca1f44 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -1,21 +1,28 @@ #ifndef __ASURA_ENGINE_OPENGL_H__ #define __ASURA_ENGINE_OPENGL_H__ -#include <asura-utils/math/rect.hpp> +#include <stack> #include <glad/glad.h> +#include <asura-utils/math/rect.hpp> +#include <asura-utils/math/matrix44.h> + +#include "matrix_stack.h" + namespace AsuraEngine { namespace Graphics { class Profiler; + class Shader; /// - /// һЩopengl״̬١ڱ༭രڻ£һڶӦһhwndһhdcԼ - /// opengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳Ⱦhdc - /// openglglcglм¼ľһ̵߳һڵһopenglĵ״̬ + /// OpenGLģһЩopengl״̬١ڱ༭രڻ£һڶӦһhwnd + /// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳ + /// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL + /// ĵ״̬ /// class OpenGL { @@ -26,23 +33,28 @@ namespace AsuraEngine void SetViewport(const AEMath::Recti viewport); AEMath::Recti GetViewport(); - private: - - friend class Profiler; + void UseShader(Shader* shader); + void UnuseShader(); - /// - /// opengl /// - static bool instantiated; - - /// - /// ¼opengl״̬ + /// OpenGL3.0Ժû任ӿڡshaderȲﱣһЩOpenGL״̬ע + /// ƺȫ̵ģҲ˵Asuraֶ֧߳ȾOpenGLĵĴʹһ + /// İһHDC\ϣڴض̴߳ģOpenGLҲһ + /// ض̡߳ͬһ̵߳IJͬHDC\ڿԹͬһOpenGLġΪ + /// дtextuer\shaderhandle /// struct { - AEMath::Recti viewport; + Shader* shader; ///< ǰʹõshader + AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 + MatrixStack projectionMatrix; ///< ͶӰ + MatrixStack modelViewMatrix; ///< 任 } state; + private: + + friend class Profiler; + }; /// diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index 2b274c2..530ea97 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -1,3 +1,5 @@ +#include <asura-utils/exceptions/exception.h> + #include "../core_config.h" #include "image.h" @@ -18,12 +20,19 @@ namespace AsuraEngine { } - bool Image::Refresh(DecodedData* data) + bool Image::Renew(DecodedData* data) { - ASSERT(data); - + if (!data) return false; ImageData* imgData = static_cast<ImageData*>(data); - ASSERT(imgData); + if (!imgData) return false; + + // ûԴһ + if (mTex == 0) + { + glGenTextures(1, &mTex); + if (mTex == 0) + throw Exception("OpenGL glGenTextures failed."); + } glBindTexture(GL_TEXTURE_2D, mTex); imgData->Lock(); @@ -40,8 +49,43 @@ namespace AsuraEngine , tf.type , imgData->pixels ); - mImageData = imgData; + mWidth = imgData->width; + mHeight = imgData->height; + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; + } + + bool Image::Renew(AEIO::DecodedData* data, const AEMath::Vector2i& pos) + { + if (!data) return false; + ImageData* imgData = static_cast<ImageData*>(data); + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, mTex); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexSubImage2D( + GL_TEXTURE_2D + , 0 + , pos.x + , pos.y + , imgData->width + , imgData->height + , tf.externalformat + , tf.type + , imgData->pixels + ); imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); glBindTexture(GL_TEXTURE_2D, 0); return true; diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 7795c08..d60bd24 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -44,12 +44,11 @@ namespace AsuraEngine /// ͼύGPUϢ¹imageʹglTexImage2D /// ύimageݡ /// - bool Refresh(AEIO::DecodedData* decodeData) override; - bool Refresh(AEIO::DecodedData* decodeData, const AEMath::Recti& rect); + bool Renew(AEIO::DecodedData* decodeData) override; + bool Renew(AEIO::DecodedData* decodeData, const AEMath::Vector2i& pos); - uint GetWidth(); - uint GetHeight(); - Color32 GetPixel(uint x, uint y); + uint GetWidth(); + uint GetHeight(); void Render(const RenderTarget* rt, const RenderState& state) override {}; void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override {}; @@ -59,7 +58,7 @@ namespace AsuraEngine //----------------------------------------------------------------------------// LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Refresh); + LUAX_DECL_METHOD(_Renew); LUAX_DECL_METHOD(_GetWidth); LUAX_DECL_METHOD(_GetHeight); LUAX_DECL_METHOD(_GetSize); @@ -68,11 +67,7 @@ namespace AsuraEngine //----------------------------------------------------------------------------// - /// - /// һͼƬһݵá - /// - ImageData* mImageData; - Luax::LuaxMemberRef mImageDataRef; + uint32 mWidth, mHeight; }; diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp new file mode 100644 index 0000000..72ffb7d --- /dev/null +++ b/source/modules/asura-core/graphics/matrix_stack.cpp @@ -0,0 +1,61 @@ +#include "matrix_stack.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + MatrixStack::MatrixStack() + : top(0) + { + // ջʼջô˱֤ջԶǿգȡֵ + mStack[top].SetIdentity(); + } + + MatrixStack::~MatrixStack() + { + } + + void MatrixStack::LoadIdentity() + { + mStack[top].SetIdentity(); + } + + bool MatrixStack::Push() + { + if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) + return false; + ++top; + mStack[top] = mStack[top - 1]; + return true; + } + + bool MatrixStack::Pop() + { + if (top == 0) + return false; + --top; + return true; + } + + AEMath::Matrix44& MatrixStack::GetTop() + { + return mStack[top]; + } + + uint MatrixStack::GetTopIndex() + { + return top; + } + + uint MatrixStack::GetCapacity() + { + return ASURA_MAX_MATRIX_STACK_DEPTH; + } + + void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) + { + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h new file mode 100644 index 0000000..1923b30 --- /dev/null +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -0,0 +1,82 @@ +#ifndef __ASURA_MATRIX_STACK_H__ +#define __ASURA_MATRIX_STACK_H__ + +#include <asura-utils/type.h> +#include <asura-utils/math/matrix44.h> + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// ջľȡ + /// +#define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB + + /// + /// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1] + /// ֵһϵtransform + /// + /// TODO: template<uint _capacity> MatrixStack + /// + class MatrixStack + { + public: + + MatrixStack(); + ~MatrixStack(); + + /// + /// ջԪصIJֻͨºʵ + /// + void LoadIdentity(); + bool Push(); + bool Pop(); + + AEMath::Matrix44& GetTop(); + void GetTop(asura_out AEMath::Matrix44& mat44); + + void LoadMatrix(const AEMath::Matrix44& mat44); + void MultMatrix(const AEMath::Matrix44& mat44); + + /// + /// 任 + /// + void Rotate(float angle, float x, float y, float z); + void Translate(float x, float y, float z); + void Scale(float x, float y, float z); + + /// + /// ͶӰ任 + /// + void Ortho(float left, float right, float bottom, float top, float near, float far); + //void Perspective(float fov, float aspect, float near, float far); + //void Frustum(float left, float right, float top, float bottom, float near, float far); + //void LookAt(float x, float y, float z, float cx, float cy, float cz, float ux, float uy, float uz); + + /// + /// ջΧ0~ASURA_MAX_MATRIX_STACK_DEPTH-1 + /// + uint GetTopIndex(); + + /// + /// ջASURA_MAX_MATRIX_STACK_DEPTH + /// + uint GetCapacity(); + + private: + + AEMath::Matrix44 mStack[ASURA_MAX_MATRIX_STACK_DEPTH]; + + /// + /// ջ0~ASURA_MAX_MATRIX_STACK_DEPTH-1 + /// + uint8 top; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index f33fd1a..a4738cd 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -1,4 +1,9 @@ -#include "Shader.h" +#include <asura-utils/exceptions/exception.h> + +#include "shader_source.h" +#include "shader.h" + +using namespace std; namespace AsuraEngine { @@ -7,17 +12,76 @@ namespace AsuraEngine Shader::Shader() { - + mProgram = glCreateProgram(); + if (mProgram == 0) + throw Exception("Cannot create OpenGL shader program."); + + mVertShader = glCreateShader(GL_VERTEX_SHADER); + if (mVertShader == 0) + { + glDeleteProgram(mProgram); + throw Exception("Cannot create OpenGL vertex shader."); + } + + mFragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (mFragShader == 0) + { + glDeleteProgram(mProgram); + glDeleteShader(mVertShader); + throw Exception("Cannot create OpenGL fragment shader."); + } } Shader::~Shader() { - + glDeleteShader(mVertShader); + glDeleteShader(mFragShader); + glDeleteProgram(mProgram); } - bool Shader::Refresh(AEIO::DecodedData* db) + bool Shader::Renew(AEIO::DecodedData* db) { - return false; + if (!db) return false; + ShaderSouce* shaderSource = static_cast<ShaderSouce*>(db); + if (!shaderSource) return false; + + GLenum err = GL_NO_ERROR; + const GLchar* source; + GLint success; + string warnning = ""; + + // Compile vertex shader. + source = shaderSource->mVert.c_str(); + glShaderSource(mVertShader, 1, &source, NULL); + glCompileShader(mVertShader); + glGetShaderiv(mVertShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetShaderWarnings(mVertShader); + throw Exception("Compile vertex shader failed:\n%s", warnning.c_str()); + } + + // Compile fragment shader. + source = shaderSource->mFrag.c_str(); + glShaderSource(mFragShader, 1, &source, NULL); + glCompileShader(mFragShader); + glGetShaderiv(mFragShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetShaderWarnings(mFragShader); + throw Exception("Compile fragment shader failed:\n%s", warnning.c_str()); + } + + // Link program. + glAttachShader(mProgram, mVertShader); + glAttachShader(mProgram, mFragShader); + glLinkProgram(mProgram); + glGetProgramiv(mProgram, GL_LINK_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetProgramWarnings(); + throw Exception("Link shader program failed:\n%s", warnning.c_str()); + } } uint Shader::GetUniformLocation(const std::string& uniform) @@ -32,37 +96,45 @@ namespace AsuraEngine void Shader::Use() { - + if (mProgram != 0) + { + gl.UseShader(this); + } } void Shader::Unuse() { - + gl.UnuseShader(); } void Shader::SetUniformFloat(uint loc, float value) { - + if(gl.state.shader == this) + glUniform1f(loc, value); } void Shader::SetUniformTexture(uint loc, const Texture& texture) { - + if (gl.state.shader == this) + glUniform1i(loc, texture.GetGLTextureHandle()); } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) { - + if (gl.state.shader == this) + glUniform2f(loc, vec2.x, vec2.y); } void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) { - + if (gl.state.shader == this) + glUniform3f(loc, vec3.x, vec3.y, vec3.z); } void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) { - + if (gl.state.shader == this) + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } uint Shader::GetGLTextureUnitCount() @@ -72,5 +144,45 @@ namespace AsuraEngine return (uint)maxTextureUnits; } + std::string Shader::GetProgramWarnings() + { + GLint strsize, nullpos; + glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &strsize); + + if (strsize == 0) + return ""; + + char *tempstr = new char[strsize]; + + memset(tempstr, '\0', strsize); + glGetProgramInfoLog(mProgram, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; + + std::string warnings(tempstr); + delete[] tempstr; + + return warnings; + } + + std::string Shader::GetShaderWarnings(GLuint shader) + { + GLint strsize, nullpos; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); + + if (strsize == 0) + return ""; + + char *tempstr = new char[strsize]; + + memset(tempstr, '\0', strsize); + glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; + + std::string warnings(tempstr); + delete[] tempstr; + + return warnings; + } + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index ae24548..9077599 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -4,6 +4,7 @@ #include <map> #include <string> +#include <asura-utils/exceptions/exception.h> #include <asura-utils/scripting/portable.hpp> #include <asura-utils/io/renewable.h> #include <asura-utils/math/vector2.hpp> @@ -36,7 +37,7 @@ namespace AsuraEngine LUAX_DECL_FACTORY(Shader); - Shader(); + Shader() asura_throw(Exception); ~Shader(); @@ -44,8 +45,7 @@ namespace AsuraEngine /// ӴshaderʱȼǷϴλuniforms location mapʹ /// glAttachShader±ɫɫ /// - //bool Load(const std::string& vertexShader, const std::string& fragmentShader); - bool Refresh(AEIO::DecodedData* decodeData) override; + bool Renew(AEIO::DecodedData* decodeData) override; /// /// shaderΪ @@ -98,6 +98,8 @@ namespace AsuraEngine /// OpenGL shader program handle. /// GLuint mProgram; + GLuint mVertShader; + GLuint mFragShader; Luax::LuaxMemberRef mCodeRef; @@ -109,6 +111,7 @@ namespace AsuraEngine LUAX_DECL_METHOD(_Use); LUAX_DECL_METHOD(_Unuse); LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Renew); LUAX_DECL_METHOD(_HasUniform); LUAX_DECL_METHOD(_GetUniformLocation); LUAX_DECL_METHOD(_SetBuiltInUniforms); @@ -121,6 +124,9 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); + }; } diff --git a/source/modules/asura-core/graphics/shader_source.h b/source/modules/asura-core/graphics/shader_source.h index b3e815c..eedbe53 100644 --- a/source/modules/asura-core/graphics/shader_source.h +++ b/source/modules/asura-core/graphics/shader_source.h @@ -10,15 +10,24 @@ namespace AsuraEngine namespace Graphics { + class Shader; + /// /// Asura EngineʹõshaderԴ룬GLSL /// class ShaderSouce : public AEIO::DecodedData { public: - void Decode(AEIO::DataBuffer& buffer) override; + + void Decode(AEIO::DataBuffer& vert, AEIO::DataBuffer& frag); + void Load(const std::string& vert, const std::string& frag); private: + + friend class Shader; + + void Decode(AEIO::DataBuffer& buffer) override; + std::string mVert; std::string mFrag; diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index 4db6ad3..38a75d7 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -1,3 +1,5 @@ +#include <asura-utils/exceptions/exception.h> + #include "Texture.h" namespace AsuraEngine @@ -8,13 +10,17 @@ namespace AsuraEngine Texture::Texture() : mTex(0) { - // GL texture - glGenTextures(1, &mTex); + // Fix: ҪʱԴ + //glGenTextures(1, &mTex); + //if(mTex == 0) + // throw Exception("Cannot create texture."); } Texture::~Texture() { - glDeleteTextures(1, &mTex); + // ͷԴ + if(mTex != 0) + glDeleteTextures(1, &mTex); } GLuint Texture::GetGLTextureHandle() const @@ -37,6 +43,8 @@ namespace AsuraEngine t.externalformat = GL_RGBA; t.type = GL_FLOAT; break; + default: + ASSERT(false); // cant reach here } return t; } diff --git a/source/modules/asura-utils/exceptions/exception.cpp b/source/modules/asura-utils/exceptions/exception.cpp index dbb36ca..5240c49 100644 --- a/source/modules/asura-utils/exceptions/exception.cpp +++ b/source/modules/asura-utils/exceptions/exception.cpp @@ -20,17 +20,10 @@ namespace AsuraEngine size_out = vsnprintf(buffer, size_buffer, fmt, args); va_end(args); - // see http://perfec.to/vsnprintf/pasprintf.c - // if size_out ... - // == -1 --> output was truncated - // == size_buffer --> output was truncated - // == size_buffer-1 --> ambiguous, /may/ have been truncated - // > size_buffer --> output was truncated, and size_out - // bytes would have been written if (size_out == size_buffer || size_out == -1 || size_out == size_buffer - 1) size_buffer *= 2; else if (size_out > size_buffer) - size_buffer = size_out + 2; // to avoid the ambiguous case + size_buffer = size_out + 2; else break; diff --git a/source/modules/asura-utils/exceptions/exception.h b/source/modules/asura-utils/exceptions/exception.h index 57c9ed6..9873a38 100644 --- a/source/modules/asura-utils/exceptions/exception.h +++ b/source/modules/asura-utils/exceptions/exception.h @@ -7,27 +7,13 @@ namespace AsuraEngine { - /** - * A convenient vararg-enabled exception class. - **/ class Exception : public std::exception { public: - /** - * Creates a new Exception according to printf-rules. - * - * See: http://www.cplusplus.com/reference/clibrary/cstdio/printf/ - * - * @param fmt The format string (see printf). - **/ Exception(const char *fmt, ...); virtual ~Exception() throw(); - /** - * Returns a string containing reason for the exception. - * @return A description of the exception. - **/ inline virtual const char *what() const throw() { return message.c_str(); diff --git a/source/modules/asura-utils/io/binding/_file.cpp b/source/modules/asura-utils/io/binding/_file.cpp index c44bc90..2de7882 100644 --- a/source/modules/asura-utils/io/binding/_file.cpp +++ b/source/modules/asura-utils/io/binding/_file.cpp @@ -186,7 +186,7 @@ namespace AsuraEngine LUAX_PREPARE(L, File); size_t size = 0; - BufferMode mode = self->GetBuffer(ASURA_OUT size); + BufferMode mode = self->GetBuffer(asura_out size); state.Push((int)size); state.Push((int)mode); return 2; diff --git a/source/modules/asura-utils/io/binding/_file_system.cpp b/source/modules/asura-utils/io/binding/_file_system.cpp index 3843451..2efc4f6 100644 --- a/source/modules/asura-utils/io/binding/_file_system.cpp +++ b/source/modules/asura-utils/io/binding/_file_system.cpp @@ -113,7 +113,7 @@ namespace AsuraEngine cc8* path = state.CheckValue<cc8*>(1); std::string mp; - if (fs->GetMountPoint(path, ASURA_OUT mp)) + if (fs->GetMountPoint(path, asura_out mp)) state.Push(mp); else state.PushNil(); @@ -246,7 +246,7 @@ namespace AsuraEngine cc8* path = state.CheckValue<cc8*>(1); std::vector<std::string> items; - if(fs->GetDirectoryItems(path, ASURA_OUT items)) + if(fs->GetDirectoryItems(path, asura_out items)) { lua_newtable(L); // item list for (int i = 0; i < items.size(); ++i) diff --git a/source/modules/asura-utils/io/file.cpp b/source/modules/asura-utils/io/file.cpp index 9e89c85..690f405 100644 --- a/source/modules/asura-utils/io/file.cpp +++ b/source/modules/asura-utils/io/file.cpp @@ -118,7 +118,7 @@ namespace AsuraEngine return PHYSFS_fileLength(mFileHandle); } - size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length) + size_t File::Read(asura_out DataBuffer* dst, size_t length) { ASSERT(dst); @@ -140,7 +140,7 @@ namespace AsuraEngine return size; } - size_t File::ReadAll(ASURA_OUT DataBuffer* dst) + size_t File::ReadAll(asura_out DataBuffer* dst) { ASSERT(dst); @@ -192,7 +192,7 @@ namespace AsuraEngine return mFileHandle != nullptr && PHYSFS_seek(mFileHandle, pos) != 0; } - bool File::Write(ASURA_REF DataBuffer* src) + bool File::Write(asura_ref DataBuffer* src) { if (!mFileHandle || (mMode != FILE_MODE_APPEND && mMode != FILE_MODE_WRITE)) throw Exception("File is not opened for writing."); @@ -264,7 +264,7 @@ namespace AsuraEngine return true; } - File::BufferMode File::GetBuffer(ASURA_OUT size_t& size) + File::BufferMode File::GetBuffer(asura_out size_t& size) { size = mBufferSize; return mBufferMode; diff --git a/source/modules/asura-utils/io/file.h b/source/modules/asura-utils/io/file.h index 56077e0..9af8919 100644 --- a/source/modules/asura-utils/io/file.h +++ b/source/modules/asura-utils/io/file.h @@ -57,9 +57,9 @@ namespace AsuraEngine /// /// ȡdata bufferض /// - size_t Read(ASURA_OUT DataBuffer* dst, size_t length); - size_t ReadAll(ASURA_OUT DataBuffer* dst); - size_t ReadAsync(ASURA_OUT DataBuffer* dst); + size_t Read(asura_out DataBuffer* dst, size_t length); + size_t ReadAll(asura_out DataBuffer* dst); + size_t ReadAsync(asura_out DataBuffer* dst); /// /// Ƿļβ @@ -69,12 +69,12 @@ namespace AsuraEngine /// /// data bufferед룬Ƿɹ /// - bool Write(ASURA_REF DataBuffer* src); + bool Write(asura_ref DataBuffer* src); /// /// 첽дļдļtaskthreadĶС /// - bool WriteAsync(ASURA_REF DataBuffer* src, AEThreading::Thread* thread); + bool WriteAsync(asura_ref DataBuffer* src, AEThreading::Thread* thread); /// /// ˻壬ǿջдļ @@ -99,7 +99,7 @@ namespace AsuraEngine /// /// ȡСģʽ /// - BufferMode GetBuffer(ASURA_OUT size_t& size); + BufferMode GetBuffer(asura_out size_t& size); const std::string& GetFileName(); const std::string& GetName(); diff --git a/source/modules/asura-utils/io/file_data.h b/source/modules/asura-utils/io/file_data.h index cd69477..f5a6085 100644 --- a/source/modules/asura-utils/io/file_data.h +++ b/source/modules/asura-utils/io/file_data.h @@ -49,7 +49,7 @@ namespace AsuraEngine /// /// Data bufferfiledataʱ٣luaüΪ0ʱluaGC١mDataʱһԱá /// - ASURA_REF DataBuffer* mData; + asura_ref DataBuffer* mData; Luax::LuaxMemberRef mDataRef; std::string mFileName; ///< չļ diff --git a/source/modules/asura-utils/io/file_system.cpp b/source/modules/asura-utils/io/file_system.cpp index 20f3cb2..30e7861 100644 --- a/source/modules/asura-utils/io/file_system.cpp +++ b/source/modules/asura-utils/io/file_system.cpp @@ -83,7 +83,7 @@ namespace AsuraEngine } } - bool Filesystem::GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint) + bool Filesystem::GetMountPoint(const std::string& locpath, asura_out std::string& mountpoint) { if (!mInited) return false; @@ -125,7 +125,7 @@ namespace AsuraEngine return true; } - bool Filesystem::Write(const std::string& name, ASURA_REF DataBuffer* buffer) + bool Filesystem::Write(const std::string& name, asura_ref DataBuffer* buffer) { File file(name); file.Open(File::FILE_MODE_WRITE); @@ -133,7 +133,7 @@ namespace AsuraEngine throw Exception("Data could not be written."); } - bool Filesystem::Append(const std::string& name, ASURA_REF DataBuffer* buffer) + bool Filesystem::Append(const std::string& name, asura_ref DataBuffer* buffer) { File file(name); file.Open(File::FILE_MODE_APPEND); @@ -170,7 +170,7 @@ namespace AsuraEngine return true; } - bool Filesystem::GetFileInfo(const std::string& filepath, ASURA_OUT FileInfo* info) + bool Filesystem::GetFileInfo(const std::string& filepath, asura_out FileInfo* info) { if (!mInited) return false; diff --git a/source/modules/asura-utils/io/file_system.h b/source/modules/asura-utils/io/file_system.h index 849cbb6..3a33504 100644 --- a/source/modules/asura-utils/io/file_system.h +++ b/source/modules/asura-utils/io/file_system.h @@ -59,20 +59,20 @@ namespace AsuraEngine bool Unmount(const std::string& locpath); bool Unmount(DataBuffer* db); - bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint); + bool GetMountPoint(const std::string& locpath, asura_out std::string& mountpoint); void SetWriteDirectory(const std::string locpath); std::string GetWriteDirectory(); File* NewFile(const std::string& name); bool NewDirectory(const std::string& path); - bool Write(const std::string& path, ASURA_REF DataBuffer* buffer); - bool Append(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Write(const std::string& path, asura_ref DataBuffer* buffer); + bool Append(const std::string& path, asura_ref DataBuffer* buffer); bool Remove(const std::string& path); FileData* Read(const std::string& path); - bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); + bool GetFileInfo(const std::string& path, asura_out FileInfo* info); - bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& items) { return false; }; + bool GetDirectoryItems(const std::string& path, asura_out std::vector<std::string>& items) { return false; }; private: diff --git a/source/modules/asura-utils/io/io_task.h b/source/modules/asura-utils/io/io_task.h index 8f04142..09c8798 100644 --- a/source/modules/asura-utils/io/io_task.h +++ b/source/modules/asura-utils/io/io_task.h @@ -46,7 +46,7 @@ namespace AsuraEngine std::string mPath; IOTaskType mType; - ASURA_REF DataBuffer* mBuffer; + asura_ref DataBuffer* mBuffer; Luax::LuaxMemberRef mBufferRef; }; diff --git a/source/modules/asura-utils/io/renewable.h b/source/modules/asura-utils/io/renewable.h index 282106d..a624c2c 100644 --- a/source/modules/asura-utils/io/renewable.h +++ b/source/modules/asura-utils/io/renewable.h @@ -21,12 +21,12 @@ namespace AsuraEngine virtual ~Renewable() {}; /// - /// ̳RenewableҪṩһRefresh + /// ̳RenewableҪṩһRenew /// - /// Effective C++09.Ӧýֹڹ캯еvirtualRefresh - /// ӹ캯г룬ҪֶRefresh + /// Effective C++09.Ӧýֹڹ캯еvirtualRenew + /// ӹ캯г룬ҪֶRenew /// - virtual bool Refresh(AEIO::DecodedData* decode_data) = 0; + virtual bool Renew(AEIO::DecodedData* decode_data) = 0; }; diff --git a/source/modules/asura-utils/math/matrix44.cpp b/source/modules/asura-utils/math/matrix44.cpp index e69de29..10c9ece 100644 --- a/source/modules/asura-utils/math/matrix44.cpp +++ b/source/modules/asura-utils/math/matrix44.cpp @@ -0,0 +1,203 @@ +#include "matrix44.h" + +#include <cstring> // memcpy +#include <cmath> + +namespace AsuraEngine +{ + namespace Math + { + + const Matrix44 Matrix44::Identity; + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix44::Matrix44() + { + SetIdentity(); + } + + Matrix44::Matrix44(const Matrix44& m) + { + memcpy(&e, &m.e, 16 * sizeof(float)); + } + + Matrix44::~Matrix44() + { + } + + void Matrix44::operator = (const Matrix44& m) + { + memcpy(&e, &m.e, 16 * sizeof(float)); + } + + void Matrix44::SetOrtho(float l, float r, float b, float t, float n, float f) + { + SetIdentity(); + float w = r - l; + float h = t - b; + float z = f - n; + e[0] = 2 / w; + e[5] = 2 / h; + e[10] = -2 / z; + e[12] = -(r + l) / w; + e[13] = -(t + b) / h; + e[14] = -(f + n) / z; + e[15] = 1; + } + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix44 Matrix44::operator * (const Matrix44 & m) const + { + Matrix44 t; + + t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]); + t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]); + t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]); + t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]); + + t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]); + t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]); + t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]); + t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]); + + t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]); + t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]); + t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]); + t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]); + + t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]); + t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]); + t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]); + t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]); + + return t; + } + + void Matrix44::operator *= (const Matrix44 & m) + { + Matrix44 t = (*this) * m; + memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16); + } + + const float * Matrix44::GetElements() const + { + return e; + } + + void Matrix44::SetIdentity() + { + memset(e, 0, sizeof(float) * 16); + e[0] = e[5] = e[10] = e[15] = 1; + } + + void Matrix44::SetTranslation(float x, float y) + { + SetIdentity(); + e[12] = x; + e[13] = y; + } + + void Matrix44::SetRotation(float rad) + { + SetIdentity(); + float c = cos(rad), s = sin(rad); + e[0] = c; e[4] = -s; + e[1] = s; e[5] = c; + } + + void Matrix44::SetScale(float sx, float sy) + { + SetIdentity(); + e[0] = sx; + e[5] = sy; + } + + void Matrix44::SetShear(float kx, float ky) + { + SetIdentity(); + e[1] = ky; + e[4] = kx; + } + + void Matrix44::SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy) + { + memset(e, 0, sizeof(float) * 16); // zero out matrix + float c = cos(angle), s = sin(angle); + // matrix multiplication carried out on paper: + // |1 x| |c -s | |sx | |1 -ox| + // | 1 y| |s c | | sy | | 1 -oy| + // | 1 | | 1 | | 1 | | 1 | + // | 1| | 1| | 1| | 1 | + // move rotate scale origin + e[10] = e[15] = 1.0f; + e[0] = c * sx; // = a + e[1] = s * sx; // = b + e[4] = -s * sy; // = c + e[5] = c * sy; // = d + e[12] = x - ox * e[0] - oy * e[4]; + e[13] = y - ox * e[1] - oy * e[5]; + } + + void Matrix44::Translate(float x, float y) + { + Matrix44 t; + t.SetTranslation(x, y); + this->operator *=(t); + } + + void Matrix44::Rotate(float rad) + { + Matrix44 t; + t.SetRotation(rad); + this->operator *=(t); + } + + void Matrix44::Scale(float sx, float sy) + { + Matrix44 t; + t.SetScale(sx, sy); + this->operator *=(t); + } + + void Matrix44::Shear(float kx, float ky) + { + Matrix44 t; + t.SetShear(kx, ky); + this->operator *=(t); + } + + // | x | + // | y | + // | 0 | + // | 1 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + //void Matrix44::transform(Graphics::Vertex* dst, const Graphics::Vertex* src, int size) const + //{ + // for (int i = 0; i<size; ++i) + // { + // // Store in temp variables in case src = dst + // float x = (e[0] * src[i].xy.x()) + (e[4] * src[i].xy.y()) + (0) + (e[12]); + // float y = (e[1] * src[i].xy.x()) + (e[5] * src[i].xy.y()) + (0) + (e[13]); + + // dst[i].xy.Set(x, y); + // } + //} + + } // namespace Math +} // namespace JinEngine
\ No newline at end of file diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h index 4ab3c0b..c0cea92 100644 --- a/source/modules/asura-utils/math/matrix44.h +++ b/source/modules/asura-utils/math/matrix44.h @@ -1,24 +1,160 @@ -#ifndef __ASURA_ENGINE_MATRIX44_H__ -#define __ASURA_ENGINE_MATRIX44_H__ +#ifndef __ASURA_MATRIX_H__ +#define __ASURA_MATRIX_H__ namespace AsuraEngine { namespace Math { + /// + /// ҪתõOpenGLglm::mat4 + /// https://blog.csdn.net/candycat1992/article/details/8830894 /// - /// 4x4 - /// + class Matrix44 { public: + static const Matrix44 Identity; + + /// + /// Creates a new identity matrix. + /// + Matrix44(); + + /// + /// Copy constructor. + /// + Matrix44(const Matrix44& m); + + /// + /// Destructor. + /// + ~Matrix44(); + + void operator = (const Matrix44& m); + + void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); + + /// + /// Multiplies this Matrix44 with another Matrix44, changing neither. + /// @param m The Matrix44 to multiply with this Matrix44. + /// @return The combined matrix. + /// + Matrix44 operator * (const Matrix44 & m) const; + + /// + /// Multiplies a Matrix44 into this Matrix44. + /// @param m The Matrix44 to combine into this Matrix44. + /// + void operator *= (const Matrix44 & m); + + /// + /// Gets a pointer to the 16 array elements. + /// @return The array elements. + /// + const float* GetElements() const; + + /// + /// ReSets this Matrix44 to the identity matrix. + /// + void SetIdentity(); + + /// + /// ReSets this Matrix44 to a translation. + /// @param x Translation along x-axis. + /// @param y Translation along y-axis. + /// + void SetTranslation(float x, float y); + + /// + /// ReSets this Matrix44 to a rotation. + /// @param r The angle in radians. + /// + void SetRotation(float r); + + /// + /// ReSets this Matrix44 to a scale transformation. + /// @param sx Scale factor along the x-axis. + /// @param sy Scale factor along the y-axis. + /// + void SetScale(float sx, float sy); + + /// + /// ReSets this Matrix44 to a shear transformation. + /// @param kx Shear along x-axis. + /// @param ky Shear along y-axis. + /// + void SetShear(float kx, float ky); + + /// + /// Creates a transformation with a certain position, orientation, scale + /// and offSet. Perfect for Drawables -- what a coincidence! + /// + /// @param x The translation along the x-axis. + /// @param y The translation along the y-axis. + /// @param angle The rotation (rad) around the center with offSet (ox,oy). + /// @param sx Scale along x-axis. + /// @param sy Scale along y-axis. + /// @param ox The offSet for rotation along the x-axis. + /// @param oy The offSet for rotation along the y-axis. + /// @param kx Shear along x-axis + /// @param ky Shear along y-axis + /// + void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); + + /// + /// Multiplies this Matrix44 with a translation. + /// @param x Translation along x-axis. + /// @param y Translation along y-axis. + /// + void Translate(float x, float y); + + /// + /// Multiplies this Matrix44 with a rotation. + /// @param r Angle in radians. + /// + void Rotate(float r); + + /// + /// Multiplies this Matrix44 with a scale transformation. + /// @param sx Scale factor along the x-axis. + /// @param sy Scale factor along the y-axis. + /// + void Scale(float sx, float sy); + + /// + /// Multiplies this Matrix44 with a shear transformation. + /// @param kx Shear along the x-axis. + /// @param ky Shear along the y-axis. + /// + void Shear(float kx, float ky); + + ///// + ///// Transforms an array of vertices by this Matrix44. The sources and + ///// destination arrays may be the same. + ///// + ///// @param dst Storage for the transformed vertices. + ///// @param src The source vertices. + ///// @param size The number of vertices. + ///// + //void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const; + private: - + + /// + /// | e0 e4 e8 e12 | + /// | e1 e5 e9 e13 | + /// | e2 e6 e10 e14 | + /// | e3 e7 e11 e15 | + /// + float e[16]; }; - } -} + } +} + +namespace AEMath = AsuraEngine::Math; -#endif
\ No newline at end of file +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/math/rect.hpp b/source/modules/asura-utils/math/rect.hpp index 282b606..15981c2 100644 --- a/source/modules/asura-utils/math/rect.hpp +++ b/source/modules/asura-utils/math/rect.hpp @@ -12,7 +12,7 @@ namespace AsuraEngine public: Rect(); Rect(T x, T y, T w, T h); - ~Rect(); + ~Rect() {}; /// /// x,yǷrectڡ diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h index bd09bc4..7f80bfa 100644 --- a/source/modules/asura-utils/type.h +++ b/source/modules/asura-utils/type.h @@ -67,11 +67,6 @@ namespace AsuraEngine #endif /// - /// ò - /// -#define ASURA_OUT -#define ASURA_REF - /// /// ƶָȨ /// #define ASURA_MOVE @@ -82,6 +77,14 @@ namespace AsuraEngine #define ASURA_LITTLE_ENDIAN 1 + //--------------------------------------------------------------------------------// + // չؼ + +#define asura_throw(ex) throw(ex) // ʾ׳쳣 + +#define asura_out +#define asura_ref + } // namespace AsuraEngine #endif // __ASURA_CONFIG_H__
\ No newline at end of file diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index bd3f7b6..58386ac 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -50,6 +50,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLin } HDC hdc; HGLRC glc; +HGLRC glc2; static PAINTSTRUCT ps; HBRUSH hBrush; HBRUSH hOldBrush; @@ -58,6 +59,7 @@ HPEN hOldPen; PIXELFORMATDESCRIPTOR pfd; int pf; File* file; +File* file2; DataBuffer db(102400); AEIO::Filesystem* fs; ImageData* imgdata = new ImageData(); @@ -89,7 +91,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, // ͼƬ fs = AEIO::Filesystem::Get(); fs->Mount(".", "root"); - file = new File("root/img.png"); + file = new File("root/img.jpg"); file->Open(File::FILE_MODE_READ); file->ReadAll(&db); @@ -102,7 +104,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, imgdata->Decode(db); img = new Image(); - img->Refresh(imgdata); + img->Renew(imgdata); + + wglMakeCurrent(hdc, glc); + + file2 = new File("root/img.png"); + file2->Open(File::FILE_MODE_READ); + file2->ReadAll(&db); + imgdata->Decode(db); + img->Renew(imgdata, {50, 100}); + delete imgdata; break; @@ -142,21 +153,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, glBindTexture(GL_TEXTURE_2D, tex); // glEnable(GL_TEXTURE_2D); //2Dӳ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //Sͼ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //Tͼ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //Ŵ˷ʽ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //С˷ʽ - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); - glVertex3f(-1.0f, -1.0f, 0.0f); - glTexCoord2f(1.0f, 0.0f); - glVertex3f(0.5f, -0.5f, 0.0f); - glTexCoord2f(1.0f, 1.0f); - glVertex3f(1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); + glVertex3f(-0.5f, -0.5f, 0.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(0.5f, -0.5f, 0.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(0.5f, 0.5f, 0.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.0f); glEnd(); |