summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-04-08 22:31:12 +0800
committerchai <chaifix@163.com>2019-04-08 22:31:12 +0800
commit4ea4bbfcb03091cb987dc151d41980ec16f3d18d (patch)
treebdbe56d8c570b5f243744fbfc5a6cdd2c4f6dc4f
parente47baca4f23db43ec91fbf64d5d06d7c0dbee495 (diff)
*misc
-rw-r--r--Build/Asura.Editor/Asura.Editor.vcxproj9
-rw-r--r--Build/Asura.Editor/Asura.Editor.vcxproj.filters33
-rw-r--r--bin/win64/01-window.exebin1393152 -> 1456128 bytes
-rw-r--r--bin/win64/SDL2.dllbin2491904 -> 2491904 bytes
-rw-r--r--bin/win64/img.jpgbin13640 -> 59348 bytes
-rw-r--r--bin/win64/shader.pngbin0 -> 28025 bytes
-rw-r--r--build/Asura.Editor/Asura.Editor.vcxproj9
-rw-r--r--build/Asura.Editor/Asura.Editor.vcxproj.filters33
-rw-r--r--build/modules/asura-core/asura-core.vcxproj6
-rw-r--r--build/modules/asura-core/asura-core.vcxproj.filters18
-rw-r--r--build/tools/bindingGen/obj/Debug/bindingGen.csproj.CoreCompileInputs.cache2
-rw-r--r--source/3rd-party/Luax/luax_class.hpp2
-rw-r--r--source/Asura.Editor/controls/radio_button.h23
-rw-r--r--source/Asura.Editor/core/shaders.h2
-rw-r--r--source/Asura.Editor/graphics/draw_info.cpp0
-rw-r--r--source/Asura.Editor/graphics/draw_info.h14
-rw-r--r--source/Asura.Editor/graphics/drawer.cpp16
-rw-r--r--source/Asura.Editor/graphics/drawer.h39
-rw-r--r--source/Asura.Editor/graphics/shader.h18
-rw-r--r--source/Asura.Editor/graphics/shaders/image.shader.h35
-rw-r--r--source/Asura.Editor/graphics/shaders/poly_line.shader.h15
-rw-r--r--source/Asura.Editor/graphics/shaders/poly_shape.shader.h0
-rw-r--r--source/modules/asura-box2d/physics/binding/_body.cpp3
-rw-r--r--source/modules/asura-box2d/physics/binding/_world.cpp4
-rw-r--r--source/modules/asura-box2d/physics/body.h7
-rw-r--r--source/modules/asura-core/graphics/binding/_gl.cpp5
-rw-r--r--source/modules/asura-core/graphics/color.h2
-rw-r--r--source/modules/asura-core/graphics/gl.cpp25
-rw-r--r--source/modules/asura-core/graphics/gl.h29
-rw-r--r--source/modules/asura-core/graphics/gpu_buffer.cpp38
-rw-r--r--source/modules/asura-core/graphics/gpu_buffer.h21
-rw-r--r--source/modules/asura-core/graphics/image.cpp48
-rw-r--r--source/modules/asura-core/graphics/image.h14
-rw-r--r--source/modules/asura-core/graphics/matrix_stack.cpp16
-rw-r--r--source/modules/asura-core/graphics/matrix_stack.h2
-rw-r--r--source/modules/asura-core/graphics/mesh2d.h24
-rw-r--r--source/modules/asura-core/graphics/shader.cpp65
-rw-r--r--source/modules/asura-core/graphics/shader.h65
-rw-r--r--source/modules/asura-core/graphics/texture.cpp2
-rw-r--r--source/modules/asura-core/graphics/texture.h6
-rw-r--r--source/modules/asura-core/image/image_decoder.h4
-rw-r--r--source/modules/asura-core/mesh/am2_handler.cpp36
-rw-r--r--source/modules/asura-core/mesh/am2_handler.h32
-rw-r--r--source/modules/asura-core/mesh/mesh2d_data.h58
-rw-r--r--source/modules/asura-core/mesh/mesh2d_handler.cpp0
-rw-r--r--source/modules/asura-core/mesh/mesh2d_handler.h34
-rw-r--r--source/modules/asura-core/mesh/obj_handler.cpp0
-rw-r--r--source/modules/asura-core/mesh/obj_handler.h0
-rw-r--r--source/modules/asura-utils/math/matrix44.cpp7
-rw-r--r--source/modules/asura-utils/math/matrix44.h2
-rw-r--r--source/modules/asura-utils/math/rect.hpp2
-rw-r--r--source/modules/asura-utils/math/rect.inl9
-rw-r--r--source/modules/asura-utils/math/vector2.hpp2
-rw-r--r--source/modules/asura-utils/type.h2
-rw-r--r--source/tests/win32/01-window/03_sub_menu.cpp209
55 files changed, 924 insertions, 123 deletions
diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj b/Build/Asura.Editor/Asura.Editor.vcxproj
index 9721b76..eda76cf 100644
--- a/Build/Asura.Editor/Asura.Editor.vcxproj
+++ b/Build/Asura.Editor/Asura.Editor.vcxproj
@@ -130,6 +130,8 @@
<ClCompile Include="..\..\source\Asura.Editor\controls\textbox.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\controls\vslider.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\editor.cpp" />
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\drawer.cpp" />
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\layout\horizontal_layout.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\layout\vertical_layout.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\main.cpp" />
@@ -150,10 +152,15 @@
<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\editor.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\drawer.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shader.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\image.shader.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_line.shader.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_shape.shader.h" />
<ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h" />
<ClInclude Include="..\..\source\Asura.Editor\layout\vertical_layout.h" />
<ClInclude Include="..\..\source\Asura.Editor\system\file_watcher.h" />
diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj.filters b/Build/Asura.Editor/Asura.Editor.vcxproj.filters
index 457aa19..add0b7f 100644
--- a/Build/Asura.Editor/Asura.Editor.vcxproj.filters
+++ b/Build/Asura.Editor/Asura.Editor.vcxproj.filters
@@ -16,6 +16,12 @@
<Filter Include="controls\binding">
<UniqueIdentifier>{1e378398-d7f0-4616-a986-b6a86faeaa8c}</UniqueIdentifier>
</Filter>
+ <Filter Include="graphics">
+ <UniqueIdentifier>{4be8ce5c-0921-4341-a976-92d31aa84c8c}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="graphics\shaders">
+ <UniqueIdentifier>{b4c26f9c-9f4e-4332-a6e2-33456b4abecb}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\source\Asura.Editor\layout\horizontal_layout.cpp">
@@ -68,6 +74,12 @@
<ClCompile Include="..\..\source\Asura.Editor\system\window.cpp">
<Filter>system</Filter>
</ClCompile>
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\drawer.cpp">
+ <Filter>graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp">
+ <Filter>graphics</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h">
@@ -122,13 +134,28 @@
<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>
<ClInclude Include="..\..\source\Asura.Editor\system\window.h">
<Filter>system</Filter>
</ClInclude>
<ClInclude Include="..\..\source\Asura.Editor\config.h" />
<ClInclude Include="..\..\source\Asura.Editor\type.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\drawer.h">
+ <Filter>graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\image.shader.h">
+ <Filter>graphics\shaders</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shader.h">
+ <Filter>graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_line.shader.h">
+ <Filter>graphics\shaders</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_shape.shader.h">
+ <Filter>graphics\shaders</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h">
+ <Filter>graphics</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/bin/win64/01-window.exe b/bin/win64/01-window.exe
index cf04168..c3953ff 100644
--- a/bin/win64/01-window.exe
+++ b/bin/win64/01-window.exe
Binary files differ
diff --git a/bin/win64/SDL2.dll b/bin/win64/SDL2.dll
index 272feb0..7279e52 100644
--- a/bin/win64/SDL2.dll
+++ b/bin/win64/SDL2.dll
Binary files differ
diff --git a/bin/win64/img.jpg b/bin/win64/img.jpg
index a50f27a..8987cfe 100644
--- a/bin/win64/img.jpg
+++ b/bin/win64/img.jpg
Binary files differ
diff --git a/bin/win64/shader.png b/bin/win64/shader.png
new file mode 100644
index 0000000..4815bca
--- /dev/null
+++ b/bin/win64/shader.png
Binary files differ
diff --git a/build/Asura.Editor/Asura.Editor.vcxproj b/build/Asura.Editor/Asura.Editor.vcxproj
index 9721b76..eda76cf 100644
--- a/build/Asura.Editor/Asura.Editor.vcxproj
+++ b/build/Asura.Editor/Asura.Editor.vcxproj
@@ -130,6 +130,8 @@
<ClCompile Include="..\..\source\Asura.Editor\controls\textbox.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\controls\vslider.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\editor.cpp" />
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\drawer.cpp" />
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\layout\horizontal_layout.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\layout\vertical_layout.cpp" />
<ClCompile Include="..\..\source\Asura.Editor\main.cpp" />
@@ -150,10 +152,15 @@
<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\editor.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\drawer.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shader.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\image.shader.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_line.shader.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_shape.shader.h" />
<ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h" />
<ClInclude Include="..\..\source\Asura.Editor\layout\vertical_layout.h" />
<ClInclude Include="..\..\source\Asura.Editor\system\file_watcher.h" />
diff --git a/build/Asura.Editor/Asura.Editor.vcxproj.filters b/build/Asura.Editor/Asura.Editor.vcxproj.filters
index 457aa19..add0b7f 100644
--- a/build/Asura.Editor/Asura.Editor.vcxproj.filters
+++ b/build/Asura.Editor/Asura.Editor.vcxproj.filters
@@ -16,6 +16,12 @@
<Filter Include="controls\binding">
<UniqueIdentifier>{1e378398-d7f0-4616-a986-b6a86faeaa8c}</UniqueIdentifier>
</Filter>
+ <Filter Include="graphics">
+ <UniqueIdentifier>{4be8ce5c-0921-4341-a976-92d31aa84c8c}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="graphics\shaders">
+ <UniqueIdentifier>{b4c26f9c-9f4e-4332-a6e2-33456b4abecb}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\source\Asura.Editor\layout\horizontal_layout.cpp">
@@ -68,6 +74,12 @@
<ClCompile Include="..\..\source\Asura.Editor\system\window.cpp">
<Filter>system</Filter>
</ClCompile>
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\drawer.cpp">
+ <Filter>graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp">
+ <Filter>graphics</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h">
@@ -122,13 +134,28 @@
<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>
<ClInclude Include="..\..\source\Asura.Editor\system\window.h">
<Filter>system</Filter>
</ClInclude>
<ClInclude Include="..\..\source\Asura.Editor\config.h" />
<ClInclude Include="..\..\source\Asura.Editor\type.h" />
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\drawer.h">
+ <Filter>graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\image.shader.h">
+ <Filter>graphics\shaders</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shader.h">
+ <Filter>graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_line.shader.h">
+ <Filter>graphics\shaders</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\shaders\poly_shape.shader.h">
+ <Filter>graphics\shaders</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h">
+ <Filter>graphics</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/build/modules/asura-core/asura-core.vcxproj b/build/modules/asura-core/asura-core.vcxproj
index 81492cc..3e59e6e 100644
--- a/build/modules/asura-core/asura-core.vcxproj
+++ b/build/modules/asura-core/asura-core.vcxproj
@@ -163,7 +163,10 @@
<ClCompile Include="..\..\..\source\modules\asura-core\input\equeue.cpp" />
<ClCompile Include="..\..\..\source\modules\asura-core\input\keyboard.cpp" />
<ClCompile Include="..\..\..\source\modules\asura-core\input\mouse.cpp" />
+ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\am2_handler.cpp" />
<ClCompile Include="..\..\..\source\modules\asura-core\mesh\mesh2d_data.cpp" />
+ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\mesh2d_handler.cpp" />
+ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\obj_handler.cpp" />
<ClCompile Include="..\..\..\source\modules\asura-core\profiler\stats.cpp" />
<ClCompile Include="..\..\..\source\modules\asura-core\threading\channel.cpp" />
<ClCompile Include="..\..\..\source\modules\asura-core\threading\thread_ex.cpp" />
@@ -217,7 +220,10 @@
<ClInclude Include="..\..\..\source\modules\asura-core\input\keyboard.h" />
<ClInclude Include="..\..\..\source\modules\asura-core\input\mouse.h" />
<ClInclude Include="..\..\..\source\modules\asura-core\input\event_manager.h" />
+ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\am2_handler.h" />
<ClInclude Include="..\..\..\source\modules\asura-core\mesh\mesh2d_data.h" />
+ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\mesh2d_handler.h" />
+ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\obj_handler.h" />
<ClInclude Include="..\..\..\source\modules\asura-core\profiler\stats.h" />
<ClInclude Include="..\..\..\source\modules\asura-core\threading\channel.h" />
<ClInclude Include="..\..\..\source\modules\asura-core\threading\thread_ex.h" />
diff --git a/build/modules/asura-core/asura-core.vcxproj.filters b/build/modules/asura-core/asura-core.vcxproj.filters
index 86d2113..5365655 100644
--- a/build/modules/asura-core/asura-core.vcxproj.filters
+++ b/build/modules/asura-core/asura-core.vcxproj.filters
@@ -191,6 +191,15 @@
<ClCompile Include="..\..\..\source\modules\asura-core\graphics\gpu_buffer.cpp">
<Filter>graphics</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\mesh2d_handler.cpp">
+ <Filter>mesh</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\am2_handler.cpp">
+ <Filter>mesh</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\obj_handler.cpp">
+ <Filter>mesh</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\source\modules\asura-core\application.h" />
@@ -341,6 +350,15 @@
<ClInclude Include="..\..\..\source\modules\asura-core\graphics\gpu_buffer.h">
<Filter>graphics</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\mesh2d_handler.h">
+ <Filter>mesh</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\am2_handler.h">
+ <Filter>mesh</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\obj_handler.h">
+ <Filter>mesh</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\source\modules\asura-core\font\string.inl">
diff --git a/build/tools/bindingGen/obj/Debug/bindingGen.csproj.CoreCompileInputs.cache b/build/tools/bindingGen/obj/Debug/bindingGen.csproj.CoreCompileInputs.cache
index 93b7e43..c1e0407 100644
--- a/build/tools/bindingGen/obj/Debug/bindingGen.csproj.CoreCompileInputs.cache
+++ b/build/tools/bindingGen/obj/Debug/bindingGen.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-76869cb9eeaafde93fc35e764d87dc7f1f272b2f
+534362588ad2d4462c430a54eb5dee7ab94c0164
diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp
index e6e0696..c39138d 100644
--- a/source/3rd-party/Luax/luax_class.hpp
+++ b/source/3rd-party/Luax/luax_class.hpp
@@ -56,7 +56,7 @@ namespace Luax
#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State* L)
-#define LUAX_DECL_ENUM(e, under_line_index) static void _luax_dec_enum_##e()
+#define LUAX_DECL_ENUM(e, under_line_index)
///
/// ʵֵĺꡣһL
diff --git a/source/Asura.Editor/controls/radio_button.h b/source/Asura.Editor/controls/radio_button.h
index e69de29..a9fc765 100644
--- a/source/Asura.Editor/controls/radio_button.h
+++ b/source/Asura.Editor/controls/radio_button.h
@@ -0,0 +1,23 @@
+#ifndef __ASURA_EDITOR_RADIO_BUTTON_H__
+#define __ASURA_EDITOR_RADIO_BUTTON_H__
+
+namespace AsuraEditor
+{
+ namespace Controls
+ {
+
+ class RadioButton
+ {
+ public:
+
+ RadioButton();
+ ~RadioButton();
+
+
+
+ };
+
+ }
+}
+
+#endif
diff --git a/source/Asura.Editor/core/shaders.h b/source/Asura.Editor/core/shaders.h
index 5f4b406..e567f95 100644
--- a/source/Asura.Editor/core/shaders.h
+++ b/source/Asura.Editor/core/shaders.h
@@ -4,6 +4,8 @@
namespace AsuraEditor
{
+
+
}
#endif \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/draw_info.cpp b/source/Asura.Editor/graphics/draw_info.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/Asura.Editor/graphics/draw_info.cpp
diff --git a/source/Asura.Editor/graphics/draw_info.h b/source/Asura.Editor/graphics/draw_info.h
new file mode 100644
index 0000000..442b92d
--- /dev/null
+++ b/source/Asura.Editor/graphics/draw_info.h
@@ -0,0 +1,14 @@
+#ifndef __ASURA_EDITOR_DRAW_INFO_H__
+#define __ASURA_EDITOR_DRAW_INFO_H__
+
+namespace AsuraEditor
+{
+ namespace Graphics
+ {
+
+
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/drawer.cpp b/source/Asura.Editor/graphics/drawer.cpp
new file mode 100644
index 0000000..f2fca31
--- /dev/null
+++ b/source/Asura.Editor/graphics/drawer.cpp
@@ -0,0 +1,16 @@
+#include "drawer.h"
+
+using namespace AEGraphics;
+
+namespace AsuraEditor
+{
+ namespace Graphics
+ {
+
+ void Drawer::DrawImage(Image* img)
+ {
+
+ }
+
+ }
+} \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/drawer.h b/source/Asura.Editor/graphics/drawer.h
new file mode 100644
index 0000000..a61a7f2
--- /dev/null
+++ b/source/Asura.Editor/graphics/drawer.h
@@ -0,0 +1,39 @@
+#ifndef __ASURA_EDITOR_PAINTER_H__
+#define __ASURA_EDITOR_PAINTER_H__
+
+#include <asura-utils/scripting/portable.hpp>
+#include <asura-utils/singleton.hpp>
+#include <asura-core/graphics/image.h>
+
+namespace AsuraEditor
+{
+ namespace Graphics
+ {
+
+ ///
+ /// AsuraEngineȾֵĻ滭࣬ڻƿؼ֮֡Բֱ沿ֵȾ
+ /// ΪȾframeworkʵ֣и߼ij󣬶ؼȾҪӵpass
+ /// ༭£Ⱦͱ༭ȾԻࡣ
+ ///
+ class Drawer
+ : public AsuraEngine::Singleton<Drawer>
+ , public AEScripting::Portable<Drawer>
+ {
+ public:
+
+ void DrawLine(int x1, int y1, int x2, int y2);
+ void DrawImage(AEGraphics::Image* img, int x, int y, float sx, float sy, float r, int ox, int oy);
+ void DrawTexts();
+ void DrawCircle(int x, int y, float d);
+ void DrawPoint(int x, int y);
+
+ private:
+
+ LUAX_DECL_SINGLETON(Drawer);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/shader.h b/source/Asura.Editor/graphics/shader.h
new file mode 100644
index 0000000..6f5a8cc
--- /dev/null
+++ b/source/Asura.Editor/graphics/shader.h
@@ -0,0 +1,18 @@
+#ifndef __ASURA_EDITOR_SHADER_H__
+#define __ASURA_EDITOR_SHADER_H__
+
+namespace AsuraEditor
+{
+ namespace Graphics
+ {
+
+ struct ShaderProgram
+ {
+ const char* vert;
+ const char* frag;
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/shaders/image.shader.h b/source/Asura.Editor/graphics/shaders/image.shader.h
new file mode 100644
index 0000000..6274f56
--- /dev/null
+++ b/source/Asura.Editor/graphics/shaders/image.shader.h
@@ -0,0 +1,35 @@
+#ifndef __ASURA_EDITOR_SHADER_H__
+#include "../shader.h"
+#endif
+
+//
+static AsuraEditor::Graphics::ShaderProgram image_shader =
+{
+R"(
+in vec2 asura_position;
+in vec2 asura_texcoord0;
+
+uniform mat4 asura_model_matrix;
+uniform mat4 asura_view_matrix;
+uniform mat4 asura_projection_matrix;
+
+void main()
+{
+ gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1);
+ uv = asura_texcoord0;
+}
+
+)",
+
+R"(
+in vec2 uv;
+
+uniform sampler2D img;
+
+void main()
+{
+
+}
+
+)"
+}; \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/shaders/poly_line.shader.h b/source/Asura.Editor/graphics/shaders/poly_line.shader.h
new file mode 100644
index 0000000..763fd45
--- /dev/null
+++ b/source/Asura.Editor/graphics/shaders/poly_line.shader.h
@@ -0,0 +1,15 @@
+
+const char* s = R"(
+in vec2 asura_position;
+in vec2 asura_texcoord0;
+
+uniform mat4 asura_model_matrix;
+uniform mat4 asura_view_matrix;
+uniform mat4 asura_projection_matrix;
+
+void main()
+{
+ gl_Position = asura_model_
+}
+
+)"; \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/shaders/poly_shape.shader.h b/source/Asura.Editor/graphics/shaders/poly_shape.shader.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/Asura.Editor/graphics/shaders/poly_shape.shader.h
diff --git a/source/modules/asura-box2d/physics/binding/_body.cpp b/source/modules/asura-box2d/physics/binding/_body.cpp
index 51cc0ab..0dbd292 100644
--- a/source/modules/asura-box2d/physics/binding/_body.cpp
+++ b/source/modules/asura-box2d/physics/binding/_body.cpp
@@ -35,8 +35,7 @@ namespace AsuraEngine
{ "INVALID", BODY_TYPE_INVALID },
{ "STATIC", BODY_TYPE_STATIC },
{ "DYNAMIC", BODY_TYPE_DYNAMIC },
- { "KINEMATIC", BODY_TYPE_KINEMATIC },
- { "ENUM", BODY_TYPE_MAX_ENUM }
+ { "KINEMATIC", BODY_TYPE_KINEMATIC }
);
}
diff --git a/source/modules/asura-box2d/physics/binding/_world.cpp b/source/modules/asura-box2d/physics/binding/_world.cpp
index 6edd193..1ebcbd1 100644
--- a/source/modules/asura-box2d/physics/binding/_world.cpp
+++ b/source/modules/asura-box2d/physics/binding/_world.cpp
@@ -6,7 +6,7 @@ namespace AsuraEngine
{
namespace Physics
{
-
+ /*
LUAX_REGISTRY(World)
{
@@ -16,6 +16,6 @@ namespace AsuraEngine
{
}
-
+*/
}
}
diff --git a/source/modules/asura-box2d/physics/body.h b/source/modules/asura-box2d/physics/body.h
index deddaaf..ce695ed 100644
--- a/source/modules/asura-box2d/physics/body.h
+++ b/source/modules/asura-box2d/physics/body.h
@@ -18,8 +18,7 @@ namespace AsuraEngine
BODY_TYPE_INVALID,
BODY_TYPE_STATIC,
BODY_TYPE_DYNAMIC,
- BODY_TYPE_KINEMATIC,
- BODY_TYPE_MAX_ENUM
+ BODY_TYPE_KINEMATIC
};
class Body
@@ -27,14 +26,14 @@ namespace AsuraEngine
{
public:
- LUAX_DECL_FACTORY(Body);
-
private:
friend class Joint;
//----------------------------------------------------------------------------//
+ LUAX_DECL_FACTORY(Body);
+
LUAX_DECL_ENUM(BodyType);
LUAX_DECL_METHOD(_GetType);
diff --git a/source/modules/asura-core/graphics/binding/_gl.cpp b/source/modules/asura-core/graphics/binding/_gl.cpp
index 4c0605f..0c3a18f 100644
--- a/source/modules/asura-core/graphics/binding/_gl.cpp
+++ b/source/modules/asura-core/graphics/binding/_gl.cpp
@@ -28,8 +28,9 @@ namespace AsuraEngine
LUAX_POSTPROCESS(OpenGL)
{
LUAX_REGISTER_ENUM(state, "EMatrixMode",
- { "PROJECTION", MATRIX_PROJECTION },
- { "MODELVIEW", MATRIX_MODELVIEW }
+ { "PROJECTION", MATRIX_MODE_PROJECTION },
+ { "MODEL", MATRIX_MODE_MODEL },
+ { "VIEW", MATRIX_MODE_VIEW }
);
}
diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h
index e875846..197921f 100644
--- a/source/modules/asura-core/graphics/color.h
+++ b/source/modules/asura-core/graphics/color.h
@@ -66,4 +66,6 @@ namespace AsuraEngine
}
}
+namespace AEGraphics = AsuraEngine::Graphics;
+
#endif \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index 54fadb7..537d40d 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -4,6 +4,7 @@
#include "gl.h"
#include "shader.h"
+#include "matrix_stack.h"
using namespace AEMath;
@@ -30,6 +31,8 @@ namespace AsuraEngine
{
}
+ static bool inited = false;
+
bool OpenGL::Init(const AEMath::Recti& view)
{
bool loaded = false;
@@ -39,10 +42,17 @@ namespace AsuraEngine
#endif
if (!loaded)
return false;
- state.viewport = view;
+ SetViewport(view);
+
+ inited = true;
return true;
}
+ bool OpenGL::Inited()
+ {
+ return inited;
+ }
+
void OpenGL::WipeError()
{
while (glGetError() != GL_NO_ERROR);
@@ -60,8 +70,8 @@ namespace AsuraEngine
void OpenGL::SetViewport(const Recti v)
{
+ state.viewport = v;
glViewport(v.x, v.y, v.w, v.h);
- state.viewport = v;
}
const Recti& OpenGL::GetViewport()
@@ -71,12 +81,15 @@ namespace AsuraEngine
void OpenGL::UseShader(Shader* shader)
{
- glUseProgram(shader->GetGLProgramHandle());
+ glUseProgram(shader->GetGLProgram());
+ int err = gl.HasError();
state.shader = shader;
+ shader->OnUse();
}
void OpenGL::UnuseShader()
{
+ state.shader->OnUnuse();
state.shader = nullptr;
}
@@ -112,9 +125,9 @@ namespace AsuraEngine
state.matrix[state.matrixMode].Rotate(angle, x, y, z);
}
- void OpenGL::Translate(float x, float y, float z)
+ void OpenGL::Translate(float x, float y)
{
- state.matrix[state.matrixMode].Translate(x, y, z);
+ state.matrix[state.matrixMode].Translate(x, y);
}
void OpenGL::Scale(float x, float y, float z)
@@ -129,7 +142,7 @@ namespace AsuraEngine
AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode)
{
- return state.matrix[state.matrixMode].GetTop();
+ return state.matrix[mode].GetTop();
}
uint OpenGL::GetMatrixDepth()
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index e3c2ffc..82b9821 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -22,8 +22,14 @@ namespace AsuraEngine
enum MatrixMode
{
- MATRIX_PROJECTION = 0,
- MATRIX_MODELVIEW = 1,
+ MATRIX_MODE_PROJECTION = 0,
+ MATRIX_MODE_MODEL = 1,
+ MATRIX_MODE_VIEW = 2,
+ };
+
+ enum GLPrams
+ {
+ GL_PARAM_MAX_TEXTURE_UNIT = 1,
};
///
@@ -40,15 +46,23 @@ namespace AsuraEngine
~OpenGL();
///
+ /// óֵ
+ ///
+ int GetParam(GLPrams param);
+
+ ///
/// ʼOpenGLIJڴOpenGL֮󡣴˺עOpenGLĵַ
///
bool Init(const AEMath::Recti& viewport);
+ bool Inited();
void SetViewport(const AEMath::Recti viewport);
const AEMath::Recti& GetViewport();
void UseShader(Shader* shader);
void UnuseShader();
+
+ void Draw();
///
/// Matrix stackز
@@ -58,9 +72,9 @@ namespace AsuraEngine
void PushMatrix();
void PopMatrix();
void LoadIdentity();
- 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 Rotate(float angle);
+ void Translate(float x, float y);
+ void Scale(float x, float y);
void Ortho(float l, float r, float b, float t, float n, float f);
AEMath::Matrix44& GetMatrix(MatrixMode mode);
uint GetMatrixDepth();
@@ -84,7 +98,7 @@ namespace AsuraEngine
{
Shader* shader; ///< ǰʹõshader
AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[2]; ///< 任
+ MatrixStack matrix[3]; ///< model, view, projection
MatrixMode matrixMode; ///< ǰľ
} state;
@@ -96,7 +110,8 @@ namespace AsuraEngine
//----------------------------------------------------------------------------//
- LUAX_DECL_ENUM(MatrixMode, 0);
+ LUAX_DECL_ENUM(MatrixMode, 1);
+ LUAX_DECL_ENUM(GLPrams, 1);
LUAX_DECL_METHOD(_SetMatrixMode);
LUAX_DECL_METHOD(_GetMatrixMode);
diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp
index c796bb0..6e6aead 100644
--- a/source/modules/asura-core/graphics/gpu_buffer.cpp
+++ b/source/modules/asura-core/graphics/gpu_buffer.cpp
@@ -34,19 +34,6 @@ namespace AsuraEngine
mUsage = GL_STATIC_DRAW;
break;
}
- gl.WipeError();
- glGenBuffers(1, &mBuffer);
- if (mBuffer == 0)
- throw Exception("OpenGL glGenBuffers failed.");
- glBindBuffer(mTarget, mBuffer);
- glBufferData(mTarget, size, NULL, mUsage); // ʼСΪsizeĻ
- if (gl.HasError())
- throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError());
- glBindBuffer(mTarget, 0);
-#if ASURA_DEBUG
- mData = (byte*)malloc(size);
- memset(mData, 0, size);
-#endif
mSize = size;
}
@@ -63,10 +50,33 @@ namespace AsuraEngine
{
if (data == nullptr)
return false;
- glBindBuffer(mTarget, mBuffer);
+ if (mBuffer == 0)
+ {
+ // ʼ
+ gl.WipeError();
+ glGenBuffers(1, &mBuffer);
+ if (mBuffer == 0)
+ throw Exception("OpenGL glGenBuffers failed.");
+ glBindBuffer(mTarget, mBuffer);
+ glBufferData(mTarget, mSize, NULL, mUsage); // ʼСΪsizeĻ
+ if (gl.HasError())
+ {
+ glBindBuffer(mTarget, 0);
+ throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError());
+ }
+#if ASURA_DEBUG
+ mData = (byte*)malloc(size);
+ memset(mData, 0, size);
+#endif
+ }
+ else
+ glBindBuffer(mTarget, mBuffer);
glBufferSubData(mTarget, offset, size, data);
if (gl.HasError())
+ {
+ glBindBuffer(mTarget, 0);
throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gl.GetError());
+ }
glBindBuffer(mTarget, 0);
#if ASURA_DEBUG
// һݣ
diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h
index aba1157..c79ed4b 100644
--- a/source/modules/asura-core/graphics/gpu_buffer.h
+++ b/source/modules/asura-core/graphics/gpu_buffer.h
@@ -1,6 +1,7 @@
#ifndef __ASURA_GPU_BUFFER_H__
#define __ASURA_GPU_BUFFER_H__
+#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/exceptions/exception.h>
#include <asura-utils/type.h>
@@ -27,11 +28,12 @@ namespace AsuraEngine
///
/// GPU壬ֶ㻺֣ÿζڴԴϴݡ
///
- class GPUBuffer
+ class GPUBuffer
+ : AEScripting::Portable<GPUBuffer>
{
public:
- GPUBuffer(BufferType type, BufferUsage usage, size_t size) ASURA_THROW(Exception);
+ GPUBuffer(BufferType type, BufferUsage usage, size_t size);
~GPUBuffer();
///
@@ -47,7 +49,20 @@ namespace AsuraEngine
uint GetBufferSize();
- private:
+ private:
+
+ //----------------------------------------------------------------------------//
+
+ LUAX_DECL_FACTORY(GPUBuffer);
+
+ LUAX_DECL_ENUM(BufferType, 1);
+ LUAX_DECL_ENUM(BufferUsage, 1);
+
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_Fill);
+ LUAX_DECL_METHOD(_GetSize);
+
+ //----------------------------------------------------------------------------//
GLenum mTarget;
GLuint mBuffer;
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index d4c4cdd..cb5b573 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -13,11 +13,16 @@ namespace AsuraEngine
{
Image::Image()
+ : mVBO(nullptr)
+ , mWidth(0)
+ , mHeight(0)
{
}
Image::~Image()
{
+ if (mVBO)
+ delete mVBO;
}
bool Image::Load(ImageData* imgData)
@@ -46,6 +51,24 @@ namespace AsuraEngine
, tf.type
, imgData->pixels
);
+
+ // ʼbuffer
+ if (!mVBO)
+ mVBO = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, 16*sizeof(float)); // positionuv
+
+ if (mWidth != imgData->width || mHeight != imgData->height)
+ {
+ float w = imgData->width,
+ h = imgData->height;
+ float buffer[] = {
+ 0, 0, 0, 0,
+ 0, h, 0, 1,
+ w, h, 1, 1,
+ w, 0, 1, 0
+ };
+ mVBO->Fill(buffer, sizeof(buffer));
+ }
+
mWidth = imgData->width;
mHeight = imgData->height;
imgData->Unlock();
@@ -86,5 +109,30 @@ namespace AsuraEngine
return true;
}
+ uint32 Image::GetWidth()
+ {
+ return mWidth;
+ }
+
+ uint32 Image::GetHeight()
+ {
+ return mHeight;
+ }
+
+ void Image::UpdateBuffer()
+ {
+ if (!mVBO)
+ return;
+ float w = mWidth,
+ h = mHeight;
+ float buffer[] = {
+ 0, 0, 0, 0,
+ 0, h, 0, 1,
+ w, h, 1, 1,
+ w, 0, 1, 0
+ };
+ mVBO->Fill(buffer, sizeof(buffer));
+ }
+
}
} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index d3cca4b..abb8a1a 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -14,6 +14,7 @@
#include "color.h"
#include "color32.h"
#include "render_state.h"
+#include "gpu_buffer.h"
namespace AsuraEngine
{
@@ -43,9 +44,11 @@ namespace AsuraEngine
uint GetWidth();
uint GetHeight();
-
- void Render(const RenderTarget* rt, const RenderState& state) override {};
- void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) override {};
+/*
+ void Render(const RenderTarget* rt, const RenderState& state) {};
+ void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) {};
+*/
+ void UpdateBuffer();
private:
@@ -65,6 +68,11 @@ namespace AsuraEngine
uint32 mWidth, mHeight;
+ ///
+ /// 壬positionUV
+ ///
+ GPUBuffer* mVBO;
+
};
}
diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp
index 72ffb7d..920dded 100644
--- a/source/modules/asura-core/graphics/matrix_stack.cpp
+++ b/source/modules/asura-core/graphics/matrix_stack.cpp
@@ -55,6 +55,22 @@ namespace AsuraEngine
void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far)
{
+ mStack[this->top].Ortho(left, right, bottom, top, near, far);
+ }
+
+ void MatrixStack::Rotate(float angle, float x, float y, float z)
+ {
+ mStack[top].Rotate(angle);
+ }
+
+ void MatrixStack::Translate(float x, float y)
+ {
+ mStack[top].Translate(x, y);
+ }
+
+ void MatrixStack::Scale(float x, float y, float z)
+ {
+ mStack[top].Scale(x, y);
}
}
diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h
index db7248b..c8ab3d6 100644
--- a/source/modules/asura-core/graphics/matrix_stack.h
+++ b/source/modules/asura-core/graphics/matrix_stack.h
@@ -44,7 +44,7 @@ namespace AsuraEngine
/// 任
///
void Rotate(float angle, float x, float y, float z);
- void Translate(float x, float y, float z);
+ void Translate(float x, float y);
void Scale(float x, float y, float z);
///
diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h
index 226b9f6..87f0d4b 100644
--- a/source/modules/asura-core/graphics/mesh2d.h
+++ b/source/modules/asura-core/graphics/mesh2d.h
@@ -1,13 +1,19 @@
#ifndef __ASURA_ENGINE_MESH2D_H__
#define __ASURA_ENGINE_MESH2D_H__
+#include <vector>
+
#include <asura-utils/scripting/portable.hpp>
+#include <asura-utils/math/vector2.hpp>
+
+#include "color.h"
+#include "gpu_buffer.h"
namespace AsuraEngine
{
namespace Graphics
{
-
+
///
/// 2D meshһЩ㶯
///
@@ -16,12 +22,24 @@ namespace AsuraEngine
{
public:
- LUAX_DECL_FACTORY(Mesh2D);
-
Mesh2D();
~Mesh2D();
+ private:
+
+ //----------------------------------------------------------------------------//
+
+ LUAX_DECL_FACTORY(Mesh2D);
+
+ //----------------------------------------------------------------------------//
+
+ ///
+ /// mesh2d dataйvbo ebo
+ ///
+ GPUBuffer* mVBO;
+ GPUBuffer* mEBO;
+
};
}
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index e6779df..662ce5e 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -1,5 +1,6 @@
#include <asura-utils/exceptions/exception.h>
+#include "gl.h"
#include "shader.h"
using namespace std;
@@ -9,6 +10,17 @@ namespace AsuraEngine
namespace Graphics
{
+ ///
+ /// texture unit
+ ///
+ static int _texture_unit = 0;
+
+ const char* Shader::ASLSemantics[] = {
+ "asura_model_matrix", // BUILTIN_UNIFORM_MODEL_MATRIX
+ "asura_view_matrix", // BUILTIN_UNIFORM_VIEW_MATRIX
+ "asura_projection_matrix", // BUILTIN_UNIFORM_PROJECTION_MATRIX
+ };
+
Shader::Shader()
{
}
@@ -85,13 +97,33 @@ namespace AsuraEngine
throw Exception("Link shader program failed:\n%s", warnning.c_str());
}
+ // mvplocation
+ mMVP[MATRIX_MODE_MODEL] = glGetUniformLocation(mProgram, ASLSemantics[BUILTIN_UNIFORM_MODEL_MATRIX]);
+ mMVP[MATRIX_MODE_VIEW] = glGetUniformLocation(mProgram, ASLSemantics[BUILTIN_UNIFORM_VIEW_MATRIX]);
+ mMVP[MATRIX_MODE_PROJECTION] = glGetUniformLocation(mProgram, ASLSemantics[BUILTIN_UNIFORM_PROJECTION_MATRIX]);
+
return true;
}
+ void Shader::OnUse()
+ {
+ _texture_unit = 0;
+ SetBuiltInUniforms();
+ }
+
+ void Shader::OnUnuse()
+ {
+ _texture_unit = 0;
+ }
+
+ int Shader::GetAttributeLocation(const std::string& name)
+ {
+ GLint loc = glGetAttribLocation(mProgram, name.c_str());
+ return loc;
+ }
+
uint Shader::GetUniformLocation(const std::string& uniform)
{
- // This function returns -1 if name does not correspond to an active uniform variable
- // in program or if name starts with the reserved prefix "gl_".
GLint loc = glGetUniformLocation(mProgram, uniform.c_str());
return loc;
}
@@ -102,7 +134,7 @@ namespace AsuraEngine
return loc != -1;
}
- GLuint Shader::GetGLProgramHandle()
+ GLuint Shader::GetGLProgram()
{
return mProgram;
}
@@ -113,10 +145,23 @@ namespace AsuraEngine
glUniform1f(loc, value);
}
- void Shader::SetUniformTexture(uint loc, const Texture& texture)
+ bool Shader::SetUniformTexture(uint loc, const Texture& texture)
{
- if (gl.state.shader == this)
- glUniform1i(loc, texture.GetGLTextureHandle());
+ if (gl.state.shader != this)
+ return false;
+
+ gl.WipeError();
+ glActiveTexture(GL_TEXTURE0 + _texture_unit);
+ if (gl.HasError())
+ return false;
+ GLint tex = texture.GetGLTexture();
+ glBindTexture(GL_TEXTURE_2D, tex);
+ if (gl.HasError())
+ return false;
+ glUniform1i(loc, _texture_unit);
+ if (gl.HasError())
+ return false;
+ ++_texture_unit;
}
void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2)
@@ -143,6 +188,14 @@ namespace AsuraEngine
glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements());
}
+ void Shader::SetBuiltInUniforms()
+ {
+ // model\view\projection matrix
+ SetUniformMatrix44(mMVP[MATRIX_MODE_MODEL], gl.GetMatrix(MATRIX_MODE_MODEL));
+ SetUniformMatrix44(mMVP[MATRIX_MODE_VIEW], gl.GetMatrix(MATRIX_MODE_VIEW));
+ SetUniformMatrix44(mMVP[MATRIX_MODE_PROJECTION], gl.GetMatrix(MATRIX_MODE_PROJECTION));
+ }
+
//void Shader::GetUniform()
//{
// //if(gl.state.shader == this)
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index 9cf9653..12d2f59 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -14,15 +14,25 @@
#include <asura-utils/stringmap.hpp>
#include <asura-utils/manager.hpp>
+#include "gl.h"
#include "color.h"
#include "texture.h"
-#include "gl.h"
+#include "gpu_buffer.h"
namespace AsuraEngine
{
namespace Graphics
{
+ enum BuiltInUniforms
+ {
+ BUILTIN_UNIFORM_MODEL_MATRIX = 0,
+ BUILTIN_UNIFORM_VIEW_MATRIX,
+ BUILTIN_UNIFORM_PROJECTION_MATRIX,
+
+ BUILTIN_UNIFORM_COUNT
+ };
+
///
/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ
/// uniformsuseɫķ༭ÿshaderͨshaderҵuniforms
@@ -40,15 +50,33 @@ namespace AsuraEngine
bool Load(const std::string& vert, const std::string& frag);
- uint GetAttributeLocation(const std::string& name);
+ void OnUse();
+ void OnUnuse();
+
+ ///
+ /// öԣAsuraֻ֧2ά
+ ///
+ int GetAttributeLocation(const std::string& name);
+ void SetAttribute(int loc, void* data, uint offset = 0, uint stride = 0);
+ void SetAttribute(int loc, GPUBuffer* vbo, uint offset = 0, uint stride = 0);
+ ///
+ /// uniform
+ ///
+ bool HasUniform(const std::string& uniform);
+ uint GetUniformLocation(const std::string& uniform);
void SetUniformFloat(uint loc, float value);
- void SetUniformTexture(uint loc, const Texture& texture);
void SetUniformVector2(uint loc, const Math::Vector2f& vec2);
void SetUniformVector3(uint loc, const Math::Vector3f& vec3);
void SetUniformVector4(uint loc, const Math::Vector4f& vec4);
void SetUniformColor(uint loc, const Color& color);
void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44);
+ bool SetUniformTexture(uint loc, const Texture& texture);
+
+ ///
+ /// \uniform
+ ///
+ void SetBuiltInUniforms();
float GetUniformFloat(uint loc);
AEMath::Vector2f GetUniformVector2(uint loc);
@@ -56,22 +84,12 @@ namespace AsuraEngine
AEMath::Vector4f GetUniformVector4s(uint loc);
AEMath::Matrix44 GetUniformMatrix44(uint loc);
- uint GetUniformLocation(const std::string& uniform);
-
- bool HasUniform(const std::string& uniform);
-
- GLuint GetGLProgramHandle();
+ GLuint GetGLProgram();
static uint GetGLTextureUnitCount();
private:
- GLuint mProgram;
- GLuint mVertShader;
- GLuint mFragShader;
-
- private:
-
//----------------------------------------------------------------------------//
LUAX_DECL_FACTORY(Shader);
@@ -95,6 +113,25 @@ namespace AsuraEngine
std::string GetProgramWarnings();
std::string GetShaderWarnings(GLuint shader);
+
+ ///
+ /// Asura shader ַͳһ
+ ///
+ static const char* ASLSemantics[BUILTIN_UNIFORM_COUNT];
+
+ GLuint mProgram;
+ GLuint mVertShader;
+ GLuint mFragShader;
+
+ ///
+ /// Model\View\Projection matrix uniformlocationAsuraҪshader
+ /// 壺
+ /// 1: asura_model_matrix ģ;
+ /// 2: asura_view_matrix ۲߾
+ /// 3: asura_projection_matrix ͶӰ
+ /// frameworkø壬ֵϷͱ༭еġ
+ ///
+ GLint mMVP[3];
};
diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp
index 38a75d7..522ba95 100644
--- a/source/modules/asura-core/graphics/texture.cpp
+++ b/source/modules/asura-core/graphics/texture.cpp
@@ -23,7 +23,7 @@ namespace AsuraEngine
glDeleteTextures(1, &mTex);
}
- GLuint Texture::GetGLTextureHandle() const
+ GLuint Texture::GetGLTexture() const
{
return mTex;
}
diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h
index 4a414b4..333a8c6 100644
--- a/source/modules/asura-core/graphics/texture.h
+++ b/source/modules/asura-core/graphics/texture.h
@@ -66,7 +66,7 @@ namespace AsuraEngine
Texture();
virtual ~Texture();
- GLuint GetGLTextureHandle() const;
+ GLuint GetGLTexture() const;
void SetFilterMode(FilterMode min, FilterMode mag);
void SetWrapMode(WrapMode wrapMode);
@@ -82,12 +82,12 @@ namespace AsuraEngine
///
/// ȾtexturertϣԭϽǣң
///
- virtual void Render(const RenderTarget* rt, const RenderState& state) = 0;
+ //virtual void Render(const RenderTarget* rt, const RenderState& state) = 0;
///
/// ȾtextureһֵrtϣԭϽǣң졣
///
- virtual void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) = 0;
+ //virtual void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) = 0;
protected:
diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/image/image_decoder.h
index 8b82d2b..f752826 100644
--- a/source/modules/asura-core/image/image_decoder.h
+++ b/source/modules/asura-core/image/image_decoder.h
@@ -20,12 +20,12 @@ namespace AsuraEngine
///
/// жڴǷñdecoderѹ
///
- virtual bool CanDecode(AEIO::DataBuffer& buffer) = 0;
+ virtual bool CanDecode(AEIO::DataBuffer& input) = 0;
///
/// һڴ棬һѹImage dataѹʧܷnullptr
///
- virtual void Decode(AEIO::DataBuffer& buffer, ImageData& data) = 0;
+ virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 0;
};
diff --git a/source/modules/asura-core/mesh/am2_handler.cpp b/source/modules/asura-core/mesh/am2_handler.cpp
new file mode 100644
index 0000000..fce7817
--- /dev/null
+++ b/source/modules/asura-core/mesh/am2_handler.cpp
@@ -0,0 +1,36 @@
+#include "am2_handler.h"
+
+namespace AsuraEngine
+{
+ namespace Mesh
+ {
+/*
+Asuramesh2DʽΪ.am2ʽ¡
+ͷ11ֽڱһAsuraMesh2Dļ
+ASURAMESH2D
+v position
+t tangent
+n normal
+[c color]
+[u texcoord0]
+[u texcoord1]
+[u texcoord2]
+[u texcoord3]
+
+f surface
+
+
+ASURAMESH2D
+p0
+v 0, 0
+t -0.2, 0.45
+n -0.3, 0.6
+p1
+
+
+*/
+
+
+
+ }
+}
diff --git a/source/modules/asura-core/mesh/am2_handler.h b/source/modules/asura-core/mesh/am2_handler.h
new file mode 100644
index 0000000..de93be9
--- /dev/null
+++ b/source/modules/asura-core/mesh/am2_handler.h
@@ -0,0 +1,32 @@
+#ifndef __ASURA_MESH2D_AM2_HANDLER_H__
+#define __ASURA_MESH2D_AM2_HANDLER_H__
+
+#include "mesh2d_handler.h"
+
+namespace AsuraEngine
+{
+ namespace Mesh
+ {
+
+ ///
+ /// Asura Mesh Format handler͹Asura.am2ʽmeshļ
+ ///
+ class AM2Handler ASURA_FINAL : public Mesh2DHandler
+ {
+ public:
+
+ AM2Handler();
+ ~AM2Handler();
+
+ bool CanDecode(AEIO::DataBuffer& input) override;
+
+ void Decode(AEIO::DataBuffer& input, Mesh2DData& target) override;
+
+ void Encode(Mesh2DData& input, AEIO::DataBuffer& target) override;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h
index e69de29..ad4b6c8 100644
--- a/source/modules/asura-core/mesh/mesh2d_data.h
+++ b/source/modules/asura-core/mesh/mesh2d_data.h
@@ -0,0 +1,58 @@
+#ifndef __ASURA_MESH2D_DATA_H__
+#define __ASURA_MESH2D_DATA_H__
+
+#include <asura-utils/scripting/portable.hpp>
+#include <asura-utils/math/vector2.hpp>
+#include <asura-utils/io/decoded_data.h>
+
+#include <vector>
+
+#include "../graphics/color.h"
+#include "../graphics/gpu_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace Mesh
+ {
+
+ ///
+ /// Mesh2DĶݣindexʹáAsura 2D mesh֧4UVһϡ
+ ///
+ struct Vertex
+ {
+ AEMath::Vector2f position; ///<
+ AEMath::Vector2f tangent; ///<
+ AEMath::Vector2f normal; ///<
+ AEGraphics::Color color; ///< ɫ
+ AEMath::Vector2f texCoord[4]; ///< UVs
+ };
+
+ ///
+ /// meshĶݺ
+ ///
+ class Mesh2DData
+ : AEIO::DecodedData
+ , AEScripting::Portable<Mesh2DData>
+ {
+ public:
+
+ void Decode(AEIO::DataBuffer& buffer) override;
+
+ private:
+
+ ///
+ /// meshж㡣
+ ///
+ std::vector<Vertex*> mVertices;
+
+ ///
+ /// ebo
+ ///
+ std::vector<float> mIndices;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-core/mesh/mesh2d_handler.cpp b/source/modules/asura-core/mesh/mesh2d_handler.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/modules/asura-core/mesh/mesh2d_handler.cpp
diff --git a/source/modules/asura-core/mesh/mesh2d_handler.h b/source/modules/asura-core/mesh/mesh2d_handler.h
new file mode 100644
index 0000000..05e12f0
--- /dev/null
+++ b/source/modules/asura-core/mesh/mesh2d_handler.h
@@ -0,0 +1,34 @@
+#ifndef __ASURA_MESH2D_HANDLER_H__
+#define __ASURA_MESH2D_HANDLER_H__
+
+#include <asura-utils/io/data_buffer.h>
+#include <asura-utils/type.h>
+
+#include "mesh2d_data.h"
+
+namespace AsuraEngine
+{
+ namespace Mesh
+ {
+
+ ///
+ /// ͱmesh
+ ///
+ ASURA_ABSTRACT class Mesh2DHandler
+ {
+ public:
+ Mesh2DHandler() {};
+ virtual ~Mesh2DHandler() {};
+
+ virtual bool CanDecode(AEIO::DataBuffer& input) = 0;
+
+ virtual void Decode(AEIO::DataBuffer& input, Mesh2DData& target) = 0;
+
+ virtual void Encode(Mesh2DData& input, AEIO::DataBuffer& target) = 0;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-core/mesh/obj_handler.cpp b/source/modules/asura-core/mesh/obj_handler.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/modules/asura-core/mesh/obj_handler.cpp
diff --git a/source/modules/asura-core/mesh/obj_handler.h b/source/modules/asura-core/mesh/obj_handler.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/modules/asura-core/mesh/obj_handler.h
diff --git a/source/modules/asura-utils/math/matrix44.cpp b/source/modules/asura-utils/math/matrix44.cpp
index a1dc933..4472cd8 100644
--- a/source/modules/asura-utils/math/matrix44.cpp
+++ b/source/modules/asura-utils/math/matrix44.cpp
@@ -185,6 +185,13 @@ namespace AsuraEngine
this->operator *=(t);
}
+ void Matrix44::Ortho(float left, float right, float bottom, float top, float near, float far)
+ {
+ Matrix44 t;
+ t.SetOrtho(left, right, bottom, top, near, far);
+ this->operator *=(t);
+ }
+
// | x |
// | y |
// | 0 |
diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h
index 9ff0288..addee98 100644
--- a/source/modules/asura-utils/math/matrix44.h
+++ b/source/modules/asura-utils/math/matrix44.h
@@ -61,6 +61,8 @@ namespace AsuraEngine
///
void Shear(float kx, float ky);
+ void Ortho(float left, float right, float bottom, float top, float near, float far);
+
/////
///// Transforms an array of vertices by this Matrix44. The sources and
///// destination arrays may be the same.
diff --git a/source/modules/asura-utils/math/rect.hpp b/source/modules/asura-utils/math/rect.hpp
index 15981c2..010a5db 100644
--- a/source/modules/asura-utils/math/rect.hpp
+++ b/source/modules/asura-utils/math/rect.hpp
@@ -29,6 +29,8 @@ namespace AsuraEngine
///
static bool Intersect(const Rect<T>& src1, const Rect<T>& src2, Rect<T>& intersection);
+ void Set(T x, T y, T w, T h);
+
T x, y, w, h;
};
diff --git a/source/modules/asura-utils/math/rect.inl b/source/modules/asura-utils/math/rect.inl
index 891a3f8..efafbf9 100644
--- a/source/modules/asura-utils/math/rect.inl
+++ b/source/modules/asura-utils/math/rect.inl
@@ -17,3 +17,12 @@ inline Rect<T>::Rect(T X, T Y, T W, T H)
{
}
+
+template <typename T>
+void Rect<T>::Set(T X, T Y, T W, T H)
+{
+ x = X;
+ y = Y;
+ w = W;
+ h = H;
+} \ No newline at end of file
diff --git a/source/modules/asura-utils/math/vector2.hpp b/source/modules/asura-utils/math/vector2.hpp
index 4baf132..e18bbdf 100644
--- a/source/modules/asura-utils/math/vector2.hpp
+++ b/source/modules/asura-utils/math/vector2.hpp
@@ -67,4 +67,6 @@ namespace AsuraEngine
}
}
+namespace AEMath = AsuraEngine::Math;
+
#endif \ No newline at end of file
diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h
index f760205..c2c6d7c 100644
--- a/source/modules/asura-utils/type.h
+++ b/source/modules/asura-utils/type.h
@@ -71,7 +71,7 @@ namespace AsuraEngine
///
#define ASURA_MOVE
-#define ASURA_DEBUG 1
+#define ASURA_DEBUG 0
//--------------------------------------------------------------------------------//
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp
index 091db6d..6343f06 100644
--- a/source/tests/win32/01-window/03_sub_menu.cpp
+++ b/source/tests/win32/01-window/03_sub_menu.cpp
@@ -4,9 +4,12 @@
#include <asura-utils/io/file_system.h>
#include <asura-utils/io/data_buffer.h>
#include <asura-core/graphics/image.h>
+#include <asura-core/graphics/shader.h>
#include <asura-core/image/image_data.h>
#include <SDL2/SDL.h>
+#include <string>
+using namespace std;
using namespace AEIO;
using namespace AEGraphics;
@@ -22,6 +25,81 @@ void AddMenus(HWND);
HWND wnd;
+AEMath::Recti viewport;
+
+
+/*
+shader в
+* MVP matrix
+* position
+* UV
+* UV_0
+* UV_1
+* UV_2
+* UV_n
+* framework涨壬DZ༭ҪΪ༭ȾͼƬȾ
+* Asura Shader Semantics.
+*/
+string shader_frame = R"(
+//
+in vec2 asura_position;
+in vec4 asura_color;
+// asura_texcoord(n)
+in vec2 asura_texcoord0;
+in vec2 asura_texcoord1;
+in vec2 asura_texcoord2;
+in vec2 asura_texcoord3;
+in vec2 asura_texcoord4;
+
+// uniform
+uniform mat4 asura_projection_matrix;
+uniform mat4 asura_model_matrix;
+uniform mat4 asura_view_matrix;
+
+uniform mat4 asura_draw_color;
+
+uniform int asura_layer; // 0~10000Ȳ
+
+uniform vec2 asura_time; // 뵱ǰʱǰ֡ļ
+
+)";
+
+string vert = R"(
+
+in vec2 vertex;
+in vec2 vertUVs;
+
+uniform mat4 projMatrix;
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+
+out vec2 texCoord;
+
+void main()
+{
+ texCoord = vertUVs;
+ gl_Position = projMatrix * viewMatrix * modelMatrix * vec4(vertex, 1, 1);
+}
+)";
+
+string frag = R"(
+in vec2 texCoord;
+uniform sampler2D img;
+uniform sampler2D img2;
+void main()
+{
+ gl_FragColor = texture2D(img, texCoord);
+}
+)";
+
+Shader* shader;
+GPUBuffer* vb;
+
+struct Vert
+{
+ float x, y; // coord
+ float s, t; // uv
+};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
{
@@ -66,12 +144,82 @@ DataBuffer db(102400);
AEIO::Filesystem* fs;
ImageData* imgdata = new ImageData();
Image* img;
-
+GLint tex;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
switch (msg) {
+ case WM_SIZE:
+ {
+ if (gl.Inited())
+ {
+ RECT rect;
+ GetWindowRect(hwnd, &rect);
+ viewport.Set(0, 0, rect.right - rect.left, rect.bottom - rect.top);
+ gl.SetViewport(viewport);
+ }
+ }
+ case WM_PAINT:
+ if (!gl.Inited())
+ break;
+ glEnable(GL_BLEND);
+ glEnable(GL_DEPTH_TEST);
+ //hdc = GetDC(hwnd);
+ //glc = wglCreateContext(hdc);
+ glClearColor(0.16, 0.16, 0.16, 1);
+ glColor4f(0.219, 0.219, 0.219, 1);
+ //glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
+ glColor4f(1, 1, 1, 1);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ tex = img->GetGLTexture();
+
+ glBindTexture(GL_TEXTURE_2D, tex); //
+
+ 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_LINEAR); //Ŵ˷ʽ
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //С˷ʽ
+
+ {
+ int uvAttribLoc = shader->GetAttributeLocation("vertUVs");
+ int vertAttribLoc = shader->GetAttributeLocation("vertex");
+ int imgLoc = shader->GetUniformLocation("img");
+ int img2Loc = shader->GetUniformLocation("img2");
+ int projmat = shader->GetUniformLocation("projMatrix");
+ int mmat = shader->GetUniformLocation("modelMatrix");
+ int vmat = shader->GetUniformLocation("viewMatrix");
+ int code = gl.GetError();
+ gl.UseShader(shader);
+ shader->SetUniformTexture(imgLoc, *img);
+ shader->SetUniformTexture(img2Loc, *img);
+ gl.SetMatrixMode(MATRIX_MODE_PROJECTION);
+ gl.PushMatrix();
+ gl.LoadIdentity();
+ gl.Ortho(0, viewport.w, viewport.h, 0, -1, 1);
+ shader->SetUniformMatrix44(projmat, gl.GetMatrix(MATRIX_MODE_PROJECTION));
+ gl.PopMatrix();
+ gl.SetMatrixMode(MATRIX_MODE_MODEL);
+ gl.LoadIdentity();
+ gl.Translate(100, 10);
+ shader->SetUniformMatrix44(mmat, gl.GetMatrix(MATRIX_MODE_MODEL));
+ shader->SetUniformMatrix44(vmat, gl.GetMatrix(MATRIX_MODE_VIEW));
+ vb->Bind();
+ glVertexAttribPointer(vertAttribLoc, 2, GL_FLOAT, GL_FALSE, sizeof(Vert), 0);
+ glVertexAttribPointer(uvAttribLoc, 2, GL_FLOAT, GL_FALSE, sizeof(Vert), (const void*)(2 * sizeof(float)));
+ vb->UnBind();
+ glEnableVertexAttribArray(vertAttribLoc);
+ glEnableVertexAttribArray(uvAttribLoc);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ glDisableVertexAttribArray(vertAttribLoc);
+ glDisableVertexAttribArray(uvAttribLoc);
+ gl.UnuseShader();
+ }
+ glFlush();
+ BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps);
+ UpdateWindow(hwnd);
+ break;
case WM_CREATE:
AddMenus(hwnd);
@@ -96,13 +244,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
file = new File("root/img.jpg");
file->Open(File::FILE_MODE_READ);
file->ReadAll(&db);
-
+
wglMakeCurrent(hdc, glc);
- if (!gladLoadGL())
- {
+ RECT rect;
+ GetWindowRect(hwnd, &rect);
+ viewport.Set(0, 0, rect.right - rect.left, rect.bottom - rect.top);
+ if (!gl.Init(viewport))
return 0;
- }
imgdata->Decode(db);
img = new Image();
@@ -116,6 +265,22 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
img->Load(imgdata, {50, 100});
imgdata->Release();
+ // shader
+ shader = new Shader();
+ shader->Load(vert, frag);
+ {
+ int w = img->GetWidth();
+ int h = img->GetHeight();
+ Vert v[] = {
+ { 0, 0, 0, 0 },
+ { 0, h, 0, 1 },
+ { w, 0, 1, 0 },
+ { w, h, 1, 1 },
+ };
+ vb = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, sizeof(v));
+ vb->Fill(v, sizeof(v));
+ };
+
break;
case WM_COMMAND:
@@ -139,40 +304,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
PostQuitMessage(0);
break;
- case WM_PAINT:
-
- //hdc = GetDC(hwnd);
- //glc = wglCreateContext(hdc);
- glClearColor(0.16, 0.16, 0.16, 1);
- glColor4f(0.219, 0.219, 0.219, 1);
- //glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
- glColor4f( 1, 1, 1, 1);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- GLint tex = img->GetGLTextureHandle();
-
- 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, 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();
-
- glFlush();
- BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps);
- break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);