diff options
author | chai <chaifix@163.com> | 2019-04-10 09:03:57 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-10 09:03:57 +0800 |
commit | b5b43bac50ad58949e70bcd1a34b1e6c4765fd51 (patch) | |
tree | 32e8655bf48ca059d818501c8d95fc92ae97b318 | |
parent | 200f710983fd54b23437cb78d5a03c90b5a47523 (diff) |
*misc
38 files changed, 647 insertions, 235 deletions
diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj b/Build/Asura.Editor/Asura.Editor.vcxproj index eda76cf..49a3039 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj +++ b/Build/Asura.Editor/Asura.Editor.vcxproj @@ -130,8 +130,10 @@ <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\brush.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\graphics\drawer.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp" /> + <ClCompile Include="..\..\source\Asura.Editor\graphics\pen.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" /> @@ -155,8 +157,10 @@ <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\brush.h" /> <ClInclude Include="..\..\source\Asura.Editor\graphics\drawer.h" /> <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h" /> + <ClInclude Include="..\..\source\Asura.Editor\graphics\pen.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" /> diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj.filters b/Build/Asura.Editor/Asura.Editor.vcxproj.filters index add0b7f..1c296af 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/Build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -80,6 +80,12 @@ <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp"> <Filter>graphics</Filter> </ClCompile> + <ClCompile Include="..\..\source\Asura.Editor\graphics\brush.cpp"> + <Filter>graphics</Filter> + </ClCompile> + <ClCompile Include="..\..\source\Asura.Editor\graphics\pen.cpp"> + <Filter>graphics</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h"> @@ -157,5 +163,11 @@ <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h"> <Filter>graphics</Filter> </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\graphics\brush.h"> + <Filter>graphics</Filter> + </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\graphics\pen.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 Binary files differindex c3953ff..74a7d01 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 7279e52..906d9a3 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 eda76cf..49a3039 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj +++ b/build/Asura.Editor/Asura.Editor.vcxproj @@ -130,8 +130,10 @@ <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\brush.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\graphics\drawer.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp" /> + <ClCompile Include="..\..\source\Asura.Editor\graphics\pen.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" /> @@ -155,8 +157,10 @@ <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\brush.h" /> <ClInclude Include="..\..\source\Asura.Editor\graphics\drawer.h" /> <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h" /> + <ClInclude Include="..\..\source\Asura.Editor\graphics\pen.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" /> diff --git a/build/Asura.Editor/Asura.Editor.vcxproj.filters b/build/Asura.Editor/Asura.Editor.vcxproj.filters index add0b7f..1c296af 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -80,6 +80,12 @@ <ClCompile Include="..\..\source\Asura.Editor\graphics\draw_info.cpp"> <Filter>graphics</Filter> </ClCompile> + <ClCompile Include="..\..\source\Asura.Editor\graphics\brush.cpp"> + <Filter>graphics</Filter> + </ClCompile> + <ClCompile Include="..\..\source\Asura.Editor\graphics\pen.cpp"> + <Filter>graphics</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h"> @@ -157,5 +163,11 @@ <ClInclude Include="..\..\source\Asura.Editor\graphics\draw_info.h"> <Filter>graphics</Filter> </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\graphics\brush.h"> + <Filter>graphics</Filter> + </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\graphics\pen.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 3e59e6e..e4382ac 100644 --- a/build/modules/asura-core/asura-core.vcxproj +++ b/build/modules/asura-core/asura-core.vcxproj @@ -131,6 +131,7 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_color.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_color32.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_gl.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_gpu_buffer.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_mesh2d.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_shader.cpp" /> @@ -142,6 +143,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\index_buffer.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" /> @@ -151,6 +153,7 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\sprite_batch.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\texture.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\gpu_buffer.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\vertex_buffer.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_data.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_decode_task.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\image\image_data.cpp" /> @@ -193,6 +196,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\index_buffer.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" /> @@ -203,6 +207,7 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\sprite_batch.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\texture.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\gpu_buffer.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\graphics\vertex_buffer.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\image\image_data.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\image\image_decoder.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\image\image_decode_task.h" /> diff --git a/build/modules/asura-core/asura-core.vcxproj.filters b/build/modules/asura-core/asura-core.vcxproj.filters index 5365655..5c58933 100644 --- a/build/modules/asura-core/asura-core.vcxproj.filters +++ b/build/modules/asura-core/asura-core.vcxproj.filters @@ -200,6 +200,15 @@ <ClCompile Include="..\..\..\source\modules\asura-core\mesh\obj_handler.cpp"> <Filter>mesh</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_gpu_buffer.cpp"> + <Filter>graphics\binding</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\index_buffer.cpp"> + <Filter>graphics</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\graphics\vertex_buffer.cpp"> + <Filter>graphics</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\source\modules\asura-core\application.h" /> @@ -359,6 +368,12 @@ <ClInclude Include="..\..\..\source\modules\asura-core\mesh\obj_handler.h"> <Filter>mesh</Filter> </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\graphics\index_buffer.h"> + <Filter>graphics</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\graphics\vertex_buffer.h"> + <Filter>graphics</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\..\source\modules\asura-core\font\string.inl"> diff --git a/build/tools/bindingGen/obj/Debug/bindingGen.csproj.FileListAbsolute.txt b/build/tools/bindingGen/obj/Debug/bindingGen.csproj.FileListAbsolute.txt index c868e47..f26ed78 100644 --- a/build/tools/bindingGen/obj/Debug/bindingGen.csproj.FileListAbsolute.txt +++ b/build/tools/bindingGen/obj/Debug/bindingGen.csproj.FileListAbsolute.txt @@ -8,3 +8,10 @@ D:\Documents\VisualStudio2017\Projects\Asura\Build\tools\bindingGen\obj\Debug\bi D:\Documents\VisualStudio2017\Projects\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.csproj.CoreCompileInputs.cache D:\Documents\VisualStudio2017\Projects\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.exe D:\Documents\VisualStudio2017\Projects\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.pdb +D:\Asura\bin\win64\bindingGen.exe.config +D:\Asura\bin\win64\bindingGen.exe +D:\Asura\bin\win64\bindingGen.pdb +D:\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.csprojAssemblyReference.cache +D:\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.csproj.CoreCompileInputs.cache +D:\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.exe +D:\Asura\Build\tools\bindingGen\obj\Debug\bindingGen.pdb diff --git a/build/tools/bindingGen/obj/Debug/bindingGen.exe b/build/tools/bindingGen/obj/Debug/bindingGen.exe Binary files differindex 016c299..db18b14 100644 --- a/build/tools/bindingGen/obj/Debug/bindingGen.exe +++ b/build/tools/bindingGen/obj/Debug/bindingGen.exe diff --git a/source/Asura.Editor/graphics/brush.cpp b/source/Asura.Editor/graphics/brush.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/Asura.Editor/graphics/brush.cpp diff --git a/source/Asura.Editor/graphics/brush.h b/source/Asura.Editor/graphics/brush.h new file mode 100644 index 0000000..5ffdba4 --- /dev/null +++ b/source/Asura.Editor/graphics/brush.h @@ -0,0 +1,20 @@ +#ifndef __ASURA_EDITOR_BRUSH_H__ +#define __ASURA_EDITOR_BRUSH_H__ + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// ˢָģʽ + /// + class Brush + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/Asura.Editor/graphics/pen.cpp b/source/Asura.Editor/graphics/pen.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/Asura.Editor/graphics/pen.cpp diff --git a/source/Asura.Editor/graphics/pen.h b/source/Asura.Editor/graphics/pen.h new file mode 100644 index 0000000..87a031c --- /dev/null +++ b/source/Asura.Editor/graphics/pen.h @@ -0,0 +1,20 @@ +#ifndef __ASURA_EDITOR_PEN_H__ +#define __ASURA_EDITOR_PEN_H__ + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// ʣָƵʽ + /// + class Pen + { + + }; + + } +} + +#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 index 6274f56..ee6be43 100644 --- a/source/Asura.Editor/graphics/shaders/image.shader.h +++ b/source/Asura.Editor/graphics/shaders/image.shader.h @@ -24,7 +24,7 @@ void main() R"( in vec2 uv; -uniform sampler2D img; +uniform sampler2D asura_maintex; void main() { diff --git a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp new file mode 100644 index 0000000..7a63c48 --- /dev/null +++ b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp @@ -0,0 +1,120 @@ +#include <stdlib.h> + +#include "../image.h" +#include "../gpu_buffer.h" + +using namespace std; +using namespace Luax; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(GPUBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Fill", _Fill }, + { "GetSize", _GetSize }, + { "GetCount", _GetCount } + ); + } + + LUAX_POSTPROCESS(GPUBuffer) + { + LUAX_REGISTER_ENUM(state, "EBufferType", + { "VERTEX", BUFFER_TYPE_VERTEX }, + { "INDEX", BUFFER_TYPE_INDEX } + ); + LUAX_REGISTER_ENUM(state, "EBufferUsage", + { "STREAM", BUFFER_USAGE_STREAM }, + { "DYNAMIC", BUFFER_USAGE_DYNAMIC }, + { "STATIC", BUFFER_USAGE_STATIC } + ); + LUAX_REGISTER_ENUM(state, "EBufferDataType", + { "INT", BUFFER_DATA_TYPE_INT }, + { "FLOAT", BUFFER_DATA_TYPE_FLOAT }, + { "UNSIGNED_BYTE", BUFFER_DATA_TYPE_UNSIGNED_BYTE } + ); + + } + + // buffer = GPUBuffer.New(bufferType, bufferUsage, bufferDataType, size) + // buffer = GPUBuffer.New(image) + // buffer = GPUBuffer.New(mesh2d) + // buffer = GPUBuffer.New(canvas) + // buffer = GPUBuffer.New(shape) + LUAX_IMPL_METHOD(GPUBuffer, _New) + { + LUAX_STATE(L); + + return 0; + } + + // gpubuffer:Fill({data unit list}, offseti) + // data_unit_list ݵtable + // offseti : ʼǵĵطڵ(0ʼ + LUAX_IMPL_METHOD(GPUBuffer, _Fill) + { + LUAX_PREPARE(L, GPUBuffer); + + // ʹbufferӦbufferڵһεʱʼsizeСbufferȻ䡣 + int offset = state.GetValue(3, 0); + int count = lua_objlen(L, 2); + int size = count * self->GetDataTypeSize(); + byte* data = (byte*)malloc(size); + int unit = self->GetDataTypeSize(); + int i = 1; + lua_rawgeti(L, 2, i); + while (!lua_isnil(L, -1)) + { + switch (self->mDataType) + { + case GL_INT: + { + int n = state.CheckValue<int>(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_FLOAT: + { + float n = state.CheckValue<float>(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_UNSIGNED_BYTE: + { + unsigned char n = state.CheckValue<unsigned char>(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + } + state.Pop(1); // value + lua_rawgeti(L, 2, ++i); + } + state.Pop(); // nil + + self->Fill(data, size, offset * unit); + + free(data); + return 0; + } + + // gpubuffer:GetSize() + LUAX_IMPL_METHOD(GPUBuffer, _GetSize) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->mSize); + return 0; + } + + LUAX_IMPL_METHOD(GPUBuffer, _GetCount) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->mSize / self->GetDataTypeSize()); + return 0; + } + + } +} diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 76ac635..99373e3 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -13,7 +13,6 @@ namespace AsuraEngine LUAX_REGISTER_METHODS(state, { "New", _New }, - { "Update", _Update }, { "GetWidth", _GetWidth }, { "GetHeight", _GetHeight }, { "GetSize", _GetSize }, @@ -34,15 +33,6 @@ namespace AsuraEngine return 1; } - // successed = image:Update(imgData) - LUAX_IMPL_METHOD(Image, _Update) - { - LUAX_PREPARE(L, Image); - ImageData* imgData = state.CheckUserdata<ImageData>(2); - state.Push(self->Load(imgData)); - return 1; - } - // width = image:GetWidth() LUAX_IMPL_METHOD(Image, _GetWidth) { diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index af6e981..e0a6320 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -1,6 +1,7 @@ #include "../shader.h" using namespace std; +using namespace Luax; namespace AsuraEngine { @@ -11,9 +12,8 @@ namespace AsuraEngine { LUAX_REGISTER_METHODS(state, { "New", _New }, - { "Use", _Use }, - { "Unuse", _Unuse }, { "Load", _Load }, + { "Update", _Update }, { "HasUniform", _HasUniform }, { "GetUniformLocation", _GetUniformLocation }, { "SetBuiltInUniforms", _SetBuiltInUniforms }, @@ -22,7 +22,16 @@ namespace AsuraEngine { "SetUniformVector2", _SetUniformVector2 }, { "SetUniformVector3", _SetUniformVector3 }, { "SetUniformVector4", _SetUniformVector4 }, - { "SetUniformColor", _SetUniformColor } + { "SetUniformColor", _SetUniformColor }, + { "SetAttribPosition", _SetAttribPosition }, + { "SetAttribTangent", _SetAttribTangent }, + { "SetAttribNormal", _SetAttribNormal }, + { "SetAttribColor", _SetAttribColor }, + { "SetAttribTexcoord0", _SetAttribTexcoord0 }, + { "SetAttribTexcoord1", _SetAttribTexcoord1 }, + { "SetAttribTexcoord2", _SetAttribTexcoord2 }, + { "SetAttribTexcoord3", _SetAttribTexcoord3 }, + { "SetBuiltInUniforms", _SetBuiltInUniforms } ); } @@ -39,24 +48,16 @@ namespace AsuraEngine return 0; } - // shader:Use() - LUAX_IMPL_METHOD(Shader, _Use) + // shader:Load() + LUAX_IMPL_METHOD(Shader, _Load) { LUAX_PREPARE(L, Shader); - return 0; - - } - // shader:Unuse() - LUAX_IMPL_METHOD(Shader, _Unuse) - { - LUAX_PREPARE(L, Shader); return 0; - } - // shader:Load() - LUAX_IMPL_METHOD(Shader, _Load) + // shader:Update() + LUAX_IMPL_METHOD(Shader, _Update) { LUAX_PREPARE(L, Shader); @@ -99,6 +100,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _SetUniformTexture) { LUAX_PREPARE(L, Shader); + return 0; } @@ -106,6 +108,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _SetUniformVector2) { LUAX_PREPARE(L, Shader); + return 0; } @@ -113,6 +116,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _SetUniformVector3) { LUAX_PREPARE(L, Shader); + return 0; } @@ -120,6 +124,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _SetUniformVector4) { LUAX_PREPARE(L, Shader); + return 0; } @@ -127,6 +132,71 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _SetUniformColor) { LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribPosition() + LUAX_IMPL_METHOD(Shader, _SetAttribPosition) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribTangent() + LUAX_IMPL_METHOD(Shader, _SetAttribTangent) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribNormal() + LUAX_IMPL_METHOD(Shader, _SetAttribNormal) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribColor() + LUAX_IMPL_METHOD(Shader, _SetAttribColor) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribTexcoord0() + LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord0) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribTexcoord1() + LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord1) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribTexcoord2() + LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord2) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetAttribTexcoord3() + LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord3) + { + LUAX_PREPARE(L, Shader); + return 0; } diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp index 537d40d..e51e8f0 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -82,7 +82,6 @@ namespace AsuraEngine void OpenGL::UseShader(Shader* shader) { glUseProgram(shader->GetGLProgram()); - int err = gl.HasError(); state.shader = shader; shader->OnUse(); } @@ -93,6 +92,17 @@ namespace AsuraEngine state.shader = nullptr; } + Shader* OpenGL::GetShader() + { + return state.shader; + } + + void OpenGL::DrawArrays(GLenum mode, GLint first, GLsizei count) + { + glDrawArrays(mode, first, count); + ++state.drawcall; + } + //------------------------------------------------------------------------------// void OpenGL::SetMatrixMode(MatrixMode mode) @@ -120,9 +130,9 @@ namespace AsuraEngine state.matrix[state.matrixMode].LoadIdentity(); } - void OpenGL::Rotate(float angle, float x, float y, float z) + void OpenGL::Rotate(float angle) { - state.matrix[state.matrixMode].Rotate(angle, x, y, z); + state.matrix[state.matrixMode].Rotate(angle); } void OpenGL::Translate(float x, float y) @@ -130,9 +140,9 @@ namespace AsuraEngine state.matrix[state.matrixMode].Translate(x, y); } - void OpenGL::Scale(float x, float y, float z) + void OpenGL::Scale(float x, float y) { - state.matrix[state.matrixMode].Scale(x, y, z); + state.matrix[state.matrixMode].Scale(x, y); } void OpenGL::Ortho(float l, float r, float b, float t, float n, float f) diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index 82b9821..f28b983 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -61,8 +61,12 @@ namespace AsuraEngine void UseShader(Shader* shader); void UnuseShader(); + Shader* GetShader(); - void Draw(); + /// + /// ͳdrawcall + /// + void DrawArrays(GLenum mode, GLint first, GLsizei count); /// /// Matrix stackز @@ -100,6 +104,7 @@ namespace AsuraEngine AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 MatrixStack matrix[3]; ///< model, view, projection MatrixMode matrixMode; ///< ǰľ + uint drawcall; ///< ͳdrawcall } state; private: diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp index 6e6aead..aecfa51 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -5,7 +5,7 @@ namespace AsuraEngine namespace Graphics { - GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, size_t size) + GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, BufferDataType dataType, size_t size) : mTarget(GL_ZERO) , mBuffer(GL_ZERO) , mSize(0) @@ -13,37 +13,56 @@ namespace AsuraEngine , mData(nullptr) #endif { + mTarget = ConvertBufferType(type); + mUsage = ConvertBufferUsage(usage); + mDataType = ConvertBufferDataType(dataType); + mSize = size; + } + + GPUBuffer::~GPUBuffer() + { +#if ASURA_DEBUG + if (mData) + free(mData); +#endif + glDeleteBuffers(1, &mBuffer); + } + + GLenum GPUBuffer::ConvertBufferType(BufferType type) + { switch (type) { case BUFFER_TYPE_VERTEX: - mTarget = GL_ARRAY_BUFFER; - break; + return GL_ARRAY_BUFFER; case BUFFER_TYPE_INDEX: - mTarget = GL_ELEMENT_ARRAY_BUFFER; - break; + return GL_ELEMENT_ARRAY_BUFFER; } + } + + GLenum GPUBuffer::ConvertBufferUsage(BufferUsage usage) + { switch (usage) { case BUFFER_USAGE_STREAM: - mUsage = GL_STREAM_DRAW; - break; + return GL_STREAM_DRAW; case BUFFER_USAGE_DYNAMIC: - mUsage = GL_DYNAMIC_DRAW; - break; + return GL_DYNAMIC_DRAW; case BUFFER_USAGE_STATIC: - mUsage = GL_STATIC_DRAW; - break; + return GL_STATIC_DRAW; } - mSize = size; } - GPUBuffer::~GPUBuffer() + GLenum GPUBuffer::ConvertBufferDataType(BufferDataType type) { -#if ASURA_DEBUG - if (mData) - free(mData); -#endif - glDeleteBuffers(1, &mBuffer); + switch (type) + { + case BUFFER_DATA_TYPE_INT: + return GL_INT; + case BUFFER_DATA_TYPE_FLOAT: + return GL_FLOAT; + case BUFFER_DATA_TYPE_UNSIGNED_BYTE: + return GL_UNSIGNED_BYTE; + } } bool GPUBuffer::Fill(const void * data, size_t size, uint offset) @@ -58,7 +77,7 @@ namespace AsuraEngine if (mBuffer == 0) throw Exception("OpenGL glGenBuffers failed."); glBindBuffer(mTarget, mBuffer); - glBufferData(mTarget, mSize, NULL, mUsage); // ʼСΪsizeĻ + glBufferData(mTarget, mSize, NULL, mUsage); // ʼСΪsizeĻ壬usageŵӦԴ if (gl.HasError()) { glBindBuffer(mTarget, 0); @@ -100,5 +119,24 @@ namespace AsuraEngine return mSize; } + GLenum GPUBuffer::GetDataType() + { + return mDataType; + } + + size_t GPUBuffer::GetDataTypeSize() + { + //https://blog.csdn.net/nklinux/article/details/16919017 + switch (mDataType) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT : + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); + } + } + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h index c79ed4b..f2e83fc 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -14,7 +14,7 @@ namespace AsuraEngine enum BufferType { - BUFFER_TYPE_VERTEX, ///< 㻺 + BUFFER_TYPE_VERTEX, ///< 㻺壬position\tangent\normal\color\texcoord(n) BUFFER_TYPE_INDEX, ///< }; @@ -25,16 +25,22 @@ namespace AsuraEngine BUFFER_USAGE_STATIC, ///< ĺʹ }; + enum BufferDataType + { + BUFFER_DATA_TYPE_INT, + BUFFER_DATA_TYPE_FLOAT, + BUFFER_DATA_TYPE_UNSIGNED_BYTE, + }; + /// - /// GPU壬ֶ㻺֣ÿζڴԴϴݡ + /// GPU壬ֶ㻺vboebo֣ÿζڴԴϴݡ /// - class GPUBuffer - : AEScripting::Portable<GPUBuffer> + ASURA_ABSTRACT class GPUBuffer : public AEScripting::Object { public: - GPUBuffer(BufferType type, BufferUsage usage, size_t size); - ~GPUBuffer(); + GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size); + virtual ~GPUBuffer(); /// /// ʼ\»棬ûgpu bufferԴΪdzʼΪǸ¡ @@ -49,24 +55,39 @@ namespace AsuraEngine uint GetBufferSize(); + GLenum GetDataType(); + private: //----------------------------------------------------------------------------// - LUAX_DECL_FACTORY(GPUBuffer); + LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); LUAX_DECL_ENUM(BufferType, 1); LUAX_DECL_ENUM(BufferUsage, 1); + LUAX_DECL_ENUM(BufferDataType, 2); - LUAX_DECL_METHOD(_New); LUAX_DECL_METHOD(_Fill); LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetCount); //----------------------------------------------------------------------------// + GLenum ConvertBufferType(BufferType type); + GLenum ConvertBufferUsage(BufferUsage type); + GLenum ConvertBufferDataType(BufferDataType type); + size_t GetDataTypeSize(); + GLenum mTarget; GLuint mBuffer; - GLuint mUsage; + /// + /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָ + /// drawcall ʱݸʼַʹbufferȡඥݣԲͬ + /// ԱһbufferСΪ˱ֽӿڵļ࣬ڳʼbufferʱָ + /// ͣڱ͵һ£Բͬͷͬbuffer + /// + GLenum mDataType; + GLuint mUsage; uint mSize; #if ASURA_DEBUG diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index cb5b573..9244e73 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -2,6 +2,7 @@ #include "../core_config.h" +#include "shader.h" #include "image.h" #include "gl.h" @@ -13,16 +14,13 @@ namespace AsuraEngine { Image::Image() - : mVBO(nullptr) - , mWidth(0) + : mWidth(0) , mHeight(0) { } Image::~Image() { - if (mVBO) - delete mVBO; } bool Image::Load(ImageData* imgData) @@ -52,23 +50,6 @@ namespace AsuraEngine , 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(); @@ -118,21 +99,48 @@ namespace AsuraEngine { return mHeight; } - - void Image::UpdateBuffer() + /* + void Image::Render() { - if (!mVBO) + Shader* shader = gl.GetShader(); + if (!shader) return; - float w = mWidth, - h = mHeight; - float buffer[] = { + uint32& w = mWidth, &h = mHeight; + int vertices[] = { 0, 0, 0, 0, 0, h, 0, 1, + w, 0, 1, 0, w, h, 1, 1, - w, 0, 1, 0 }; - mVBO->Fill(buffer, sizeof(buffer)); + // öϵUV + shader->SetAttribPosition(2, GL_INT, GL_FALSE, 4 * sizeof(int), vertices); + shader->SetAttribTexcoord0(2, GL_INT, GL_FALSE, 4 * sizeof(int), &vertices[2]); + gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); } + void Image::Render(AEMath::Recti& quad) + { + // + Shader* shader = gl.GetShader(); + if (!shader) + return; + int &w = quad.w, &h = quad.h; + // UV + float l = quad.x / mWidth, + r = (quad.x + quad.w) / mWidth, + t = quad.y / mHeight, + b = (quad.y + quad.h) / mHeight; + float vertices[] = { + 0, 0, l, t, + 0, h, l, b, + w, 0, r, t, + w, h, r, b, + }; + // öϵUV + shader->SetAttribPosition(2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), vertices); + shader->SetAttribTexcoord0(2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), &vertices[2]); + gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + */ } }
\ 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 abb8a1a..a1fba9a 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -10,11 +10,11 @@ #include "../image/image_data.h" -#include "texture.h" #include "color.h" #include "color32.h" #include "render_state.h" #include "gpu_buffer.h" +#include "texture.h" namespace AsuraEngine { @@ -24,7 +24,9 @@ namespace AsuraEngine /// /// ImageͼƬڴȡϷĽһImageڴ桢Դֻᱣһ /// ݣҪimageêλãźתǶȣʹsprite - /// һֻࡣҪǿǵeditorengineʹòͬķװ + /// һֻࡣҪǿǵeditorengineʹòͬķװImageֻṩȾʱҪ + /// sampler2Dϸ˵ImageأӦImageṩFrameworkУ + /// Ⱦʵspritespriteṩ˶ݺͷ任 /// class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> @@ -44,11 +46,11 @@ namespace AsuraEngine uint GetWidth(); uint GetHeight(); -/* - void Render(const RenderTarget* rt, const RenderState& state) {}; - void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) {}; -*/ - void UpdateBuffer(); + + /// + /// һgpu buffer䶥positionݺUV. + /// + GPUBuffer* GenGPUBuffer(); private: @@ -57,7 +59,7 @@ namespace AsuraEngine LUAX_DECL_FACTORY(Image, Texture); LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Update); + LUAX_DECL_METHOD(_Load); LUAX_DECL_METHOD(_GetWidth); LUAX_DECL_METHOD(_GetHeight); LUAX_DECL_METHOD(_GetSize); @@ -68,11 +70,6 @@ namespace AsuraEngine uint32 mWidth, mHeight; - /// - /// 壬positionUV - /// - GPUBuffer* mVBO; - }; } diff --git a/source/modules/asura-core/graphics/index_buffer.cpp b/source/modules/asura-core/graphics/index_buffer.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/graphics/index_buffer.cpp diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/graphics/index_buffer.h diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp index 920dded..d48a1e0 100644 --- a/source/modules/asura-core/graphics/matrix_stack.cpp +++ b/source/modules/asura-core/graphics/matrix_stack.cpp @@ -58,7 +58,7 @@ namespace AsuraEngine mStack[this->top].Ortho(left, right, bottom, top, near, far); } - void MatrixStack::Rotate(float angle, float x, float y, float z) + void MatrixStack::Rotate(float angle) { mStack[top].Rotate(angle); } @@ -68,7 +68,7 @@ namespace AsuraEngine mStack[top].Translate(x, y); } - void MatrixStack::Scale(float x, float y, float z) + void MatrixStack::Scale(float x, float y) { 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 c8ab3d6..1a318fa 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -43,9 +43,9 @@ namespace AsuraEngine /// /// 任 /// - void Rotate(float angle, float x, float y, float z); + void Rotate(float angle); void Translate(float x, float y); - void Scale(float x, float y, float z); + void Scale(float x, float y); /// /// ͶӰ任 diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 87f0d4b..420986e 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -16,6 +16,7 @@ namespace AsuraEngine /// /// 2D meshһЩ㶯 + /// https://en.wikipedia.org/wiki/Polygon_mesh /// class Mesh2D ASURA_FINAL : public Scripting::Portable<Mesh2D> diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/graphics/render_state.h index 4c3491c..b5814d3 100644 --- a/source/modules/asura-core/graphics/render_state.h +++ b/source/modules/asura-core/graphics/render_state.h @@ -29,7 +29,6 @@ namespace AsuraEngine /// /// λášλúת /// - Math::Transform transform; /// diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 0d92c60..cf3d4b2 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -13,7 +13,7 @@ namespace AsuraEngine /// /// texture unit /// - static int _texture_unit = 0; + static int _texture_unit; const char* Shader::SemanticsName[] = { // uniforms @@ -107,19 +107,8 @@ namespace AsuraEngine throw Exception("Link shader program failed:\n%s", warnning.c_str()); } - // mvplocation - mMVP[MATRIX_MODE_MODEL] = glGetUniformLocation(mProgram, SemanticsName[SEMANTICS_UNIFORM_MODEL_MATRIX]); - mMVP[MATRIX_MODE_VIEW] = glGetUniformLocation(mProgram, SemanticsName[SEMANTICS_UNIFORM_VIEW_MATRIX]); - mMVP[MATRIX_MODE_PROJECTION] = glGetUniformLocation(mProgram, SemanticsName[SEMANTICS_UNIFORM_PROJECTION_MATRIX]); - - mPosition = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_POSITION]); - mTangent = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TANGENT]); - mNormal = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_NORMAL]); - mTexcoord0 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD0]); - mTexcoord1 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD1]); - mTexcoord2 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD2]); - mTexcoord3 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD3]); - mColor = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_COLOR]); + // linklocations + UpdateSemanticsLocations(); return true; } @@ -127,12 +116,20 @@ namespace AsuraEngine void Shader::OnUse() { _texture_unit = 0; - SetBuiltInUniforms(); + // Disableöԣsetʱ + glDisableVertexAttribArray(mPosition); + glDisableVertexAttribArray(mTangent); + glDisableVertexAttribArray(mNormal); + glDisableVertexAttribArray(mColor); + glDisableVertexAttribArray(mTexcoord0); + glDisableVertexAttribArray(mTexcoord1); + glDisableVertexAttribArray(mTexcoord2); + glDisableVertexAttribArray(mTexcoord3); } void Shader::OnUnuse() { - _texture_unit = 0; + _texture_unit; } /* int Shader::GetAttributeLocation(const std::string& name) @@ -223,7 +220,7 @@ namespace AsuraEngine uint Shader::GetGLTextureUnitCount() { - GLint maxTextureUnits = 0; + GLint maxTextureUnits; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); return (uint)maxTextureUnits; } @@ -268,5 +265,86 @@ namespace AsuraEngine return warnings; } + void Shader::UpdateSemanticsLocations() + { + // mvplocation + mMVP[MATRIX_MODE_MODEL] = glGetUniformLocation(mProgram, SemanticsName[SEMANTICS_UNIFORM_MODEL_MATRIX]); + mMVP[MATRIX_MODE_VIEW] = glGetUniformLocation(mProgram, SemanticsName[SEMANTICS_UNIFORM_VIEW_MATRIX]); + mMVP[MATRIX_MODE_PROJECTION] = glGetUniformLocation(mProgram, SemanticsName[SEMANTICS_UNIFORM_PROJECTION_MATRIX]); + + mPosition = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_POSITION]); + mTangent = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TANGENT]); + mNormal = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_NORMAL]); + mTexcoord0 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD0]); + mTexcoord1 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD1]); + mTexcoord2 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD2]); + mTexcoord3 = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TEXCOORD3]); + mColor = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_COLOR]); + } + + void Shader::SetAttribPosition(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mPosition, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mPosition); + } + + void Shader::SetAttribTangent(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mTangent, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mTangent); + } + + void Shader::SetAttribNormal(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mNormal, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mNormal); + } + + void Shader::SetAttribColor(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mColor, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mColor); + } + + void Shader::SetAttribTexcoord0(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mTexcoord0, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mTexcoord0); + } + + void Shader::SetAttribTexcoord1(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mTexcoord1, size, vbo->GetDataType(), normalized, stride, (GLvoid*) offset); + vbo->UnBind(); + glEnableVertexAttribArray(mTexcoord1); + } + + void Shader::SetAttribTexcoord2(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mTexcoord2, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mTexcoord2); + } + + void Shader::SetAttribTexcoord3(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized) + { + vbo->Bind(); + glVertexAttribPointer(mTexcoord3, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); + glEnableVertexAttribArray(mTexcoord3); + } + } }
\ 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 25b36dc..a725ccf 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -45,23 +45,18 @@ namespace AsuraEngine void OnUnuse(); /// - /// öԣAsuraֻ֧2ά + /// öԣЩֵframeworkrenderer汻ãImageMesh2DЩԴ + /// normalizedΪtrueݻڸbuffer¹һ255ɫһ + /// 0~1 /// - //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); - - /// - /// ǰö - /// - void SetAttribPosition(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribTangent(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribNormal(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribTexcoord0(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribTexcoord1(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribTexcoord2(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribTexcoord3(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - void SetAttribColor(int size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); + void SetAttribPosition(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribTangent(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribNormal(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribColor(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribTexcoord0(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribTexcoord1(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribTexcoord2(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); + void SetAttribTexcoord3(int size, GPUBuffer* vbo, GLsizei offset = 0, GLsizei stride = 0, bool normalized = false); /// /// uniform @@ -98,31 +93,40 @@ namespace AsuraEngine LUAX_DECL_FACTORY(Shader); LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Use); - LUAX_DECL_METHOD(_Unuse); LUAX_DECL_METHOD(_Load); LUAX_DECL_METHOD(_Update); LUAX_DECL_METHOD(_HasUniform); LUAX_DECL_METHOD(_GetUniformLocation); - LUAX_DECL_METHOD(_SetBuiltInUniforms); LUAX_DECL_METHOD(_SetUniformFloat); LUAX_DECL_METHOD(_SetUniformTexture); LUAX_DECL_METHOD(_SetUniformVector2); LUAX_DECL_METHOD(_SetUniformVector3); LUAX_DECL_METHOD(_SetUniformVector4); LUAX_DECL_METHOD(_SetUniformColor); + // vertex attributes + LUAX_DECL_METHOD(_SetAttribPosition); + LUAX_DECL_METHOD(_SetAttribTangent); + LUAX_DECL_METHOD(_SetAttribNormal); + LUAX_DECL_METHOD(_SetAttribColor); + LUAX_DECL_METHOD(_SetAttribTexcoord0); + LUAX_DECL_METHOD(_SetAttribTexcoord1); + LUAX_DECL_METHOD(_SetAttribTexcoord2); + LUAX_DECL_METHOD(_SetAttribTexcoord3); + // uniform + LUAX_DECL_METHOD(_SetBuiltInUniforms); //----------------------------------------------------------------------------// std::string GetProgramWarnings(); std::string GetShaderWarnings(GLuint shader); + void UpdateSemanticsLocations(); /// - /// AsuraShader壬Ժuniformframeworkлshaderװ + /// AsuraShader壬Ժuniformframeworkлshaderٴηװ /// ν壬ָshaderԶıⲿʱҪṩЩֵ /// ĻҪ /// - enum ASLSemantics + enum Semantics { // MVP SEMANTICS_UNIFORM_MODEL_MATRIX = 0, @@ -154,24 +158,12 @@ namespace AsuraEngine 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]; - - /// - /// Եlocation - /// GLint mPosition; GLint mTangent; GLint mNormal; GLint mColor; - // ֧UV GLint mTexcoord0; GLint mTexcoord1; GLint mTexcoord2; diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 333a8c6..36a773d 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -78,16 +78,26 @@ namespace AsuraEngine /// UVfilterΪ /// bool IsGenMipmap(); - +/* /// /// Ⱦ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; +*/ + /// + /// Ⱦimage + /// + //virtual void Render() = 0; + + /// + /// Ⱦimage + /// + //virtual void Render(AEMath::Recti& quad) = 0; protected: diff --git a/source/modules/asura-core/graphics/vertex_buffer.cpp b/source/modules/asura-core/graphics/vertex_buffer.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/graphics/vertex_buffer.cpp diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h new file mode 100644 index 0000000..b8245e5 --- /dev/null +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -0,0 +1,29 @@ +#ifndef __ASURA_VERTEX_BUFFER_H__ +#define __ASURA_VERTEX_BUFFER_H__ + +#include <asura-utils/scripting/portable.hpp> + +#include "gpu_buffer.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class VertexBuffer : AEScripting::Portable<VertexBuffer, GPUBuffer> + { + public: + + VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~VertexBuffer(); + + private: + + LUAX_DECL_FACTORY(VertexBuffer, GPUBuffer); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/am2_handler.cpp b/source/modules/asura-core/mesh/am2_handler.cpp index fce7817..31bd51b 100644 --- a/source/modules/asura-core/mesh/am2_handler.cpp +++ b/source/modules/asura-core/mesh/am2_handler.cpp @@ -21,13 +21,13 @@ f surface ASURAMESH2D -p0 +p 0 v 0, 0 t -0.2, 0.45 n -0.3, 0.6 -p1 - +p 1 +f 0, 1, 2 */ diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h index ad4b6c8..409451d 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.h +++ b/source/modules/asura-core/mesh/mesh2d_data.h @@ -40,6 +40,8 @@ namespace AsuraEngine private: + LUAX_DECL_FACTORY(Mesh2DData); + /// /// meshж㡣 /// diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 0a389b0..be22665 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -27,66 +27,27 @@ 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 vec2 asura_tangent; -in vec2 asura_normal; -in vec4 asura_color; -// asura_texcoord(n) -in vec2 asura_texcoord0; -in vec2 asura_texcoord1; -in vec2 asura_texcoord2; -in vec2 asura_texcoord3; - -// 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; +in vec2 asura_position; +in vec2 asura_texcoord0; -uniform mat4 projMatrix; -uniform mat4 modelMatrix; -uniform mat4 viewMatrix; +uniform mat4 asura_projection_matrix; +uniform mat4 asura_model_matrix; +uniform mat4 asura_view_matrix; out vec2 texCoord; void main() { - texCoord = vertUVs; - gl_Position = projMatrix * viewMatrix * modelMatrix * vec4(vertex, 1, 1); + texCoord = asura_texcoord0; + gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1); } )"; string frag = R"( -in vec2 texCoord; +in vec2 texCoord; uniform sampler2D img; -uniform sampler2D img2; void main() { gl_FragColor = texture2D(img, texCoord); @@ -98,7 +59,7 @@ GPUBuffer* vb; struct Vert { - float x, y; // coord + float x, y; // position float s, t; // uv }; @@ -184,37 +145,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, 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); + shader->SetBuiltInUniforms(); + shader->SetAttribPosition(2, vb, 0, 4 * sizeof(float)); + shader->SetAttribTexcoord0(2, vb, 2 * sizeof(float), 4 * sizeof(float)); + gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); gl.UnuseShader(); } glFlush(); @@ -278,7 +221,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, { w, 0, 1, 0 }, { w, h, 1, 1 }, }; - vb = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, sizeof(v)); + vb = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, BUFFER_DATA_TYPE_FLOAT, sizeof(v)); vb->Fill(v, sizeof(v)); }; |