diff options
-rw-r--r-- | Data/Resources/Metatable/Excel/Icons.xlsx | bin | 12385 -> 12404 bytes | |||
-rw-r--r-- | Data/Resources/Metatable/Icons.csv | 4 | ||||
-rw-r--r-- | Data/Resources/Shaders/UI.glsl | 1 | ||||
-rw-r--r-- | Data/boot.lua | 4 | ||||
-rw-r--r-- | Projects/VisualStudio/Editor/Editor.vcxproj | 6 | ||||
-rw-r--r-- | Projects/VisualStudio/Editor/Editor.vcxproj.filters | 18 | ||||
-rw-r--r-- | Runtime/Graphics/Device.cpp | 4 | ||||
-rw-r--r-- | Runtime/Graphics/Device.h | 4 | ||||
-rw-r--r-- | Runtime/Graphics/GPUDataBuffers.cpp | 42 | ||||
-rw-r--r-- | Runtime/Graphics/GPUDataBuffers.h | 160 | ||||
-rw-r--r-- | Runtime/Graphics/GpuDataBuffer.cpp | 206 | ||||
-rw-r--r-- | Runtime/Graphics/GpuDataBuffer.h | 90 | ||||
-rw-r--r-- | Runtime/Graphics/ImageData.h | 23 | ||||
-rw-r--r-- | Runtime/Graphics/OpenGL.h | 25 | ||||
-rw-r--r-- | Runtime/Graphics/Quad.cpp | 104 | ||||
-rw-r--r-- | Runtime/Graphics/Quad.h | 50 | ||||
-rw-r--r-- | Runtime/Graphics/ShaderCompiler.cpp | 7 | ||||
-rw-r--r-- | Runtime/Graphics/ShaderCompiler.h | 33 | ||||
-rw-r--r-- | Runtime/Graphics/VertexBuffer.h | 8 |
19 files changed, 365 insertions, 424 deletions
diff --git a/Data/Resources/Metatable/Excel/Icons.xlsx b/Data/Resources/Metatable/Excel/Icons.xlsx Binary files differindex bc359e5..5f21f2d 100644 --- a/Data/Resources/Metatable/Excel/Icons.xlsx +++ b/Data/Resources/Metatable/Excel/Icons.xlsx diff --git a/Data/Resources/Metatable/Icons.csv b/Data/Resources/Metatable/Icons.csv index 0b7221a..85ea0fd 100644 --- a/Data/Resources/Metatable/Icons.csv +++ b/Data/Resources/Metatable/Icons.csv @@ -1,7 +1,7 @@ Name,Category,Path,Filter,Wrap,Slicing,Left,Right,Top,Bottom, btn_add,Button,buttons/add.png,,,,,,,, -btn_alpha,Button,buttons/alpha.png,,,,,,,, -btn_checker,Button,buttons/checker.png,,,,,,,, +btn_alpha,Button,buttons/alpha.png,Nearest,,,,,,, +btn_checker,Button,buttons/checker.png,,Repeat,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, diff --git a/Data/Resources/Shaders/UI.glsl b/Data/Resources/Shaders/UI.glsl index 12a94db..c4b1f92 100644 --- a/Data/Resources/Shaders/UI.glsl +++ b/Data/Resources/Shaders/UI.glsl @@ -8,5 +8,4 @@ FRAGMENT_SHADER_BEGIN - FRAGMENT_SHADER_END
\ No newline at end of file diff --git a/Data/boot.lua b/Data/boot.lua index 62b5d96..ad8f4da 100644 --- a/Data/boot.lua +++ b/Data/boot.lua @@ -14,7 +14,7 @@ package.cpath=package.cpath .. ";" .. engineCLibs .. ";" .. editorCLibs -- debugging
-- 在这里会报一个异常, 不知道为什么
-require("LuaPanda").start("127.0.0.1",8818)
+--require("LuaPanda").start("127.0.0.1",8818)
-- redirect
if GAMELAB_DEBUG then
@@ -32,7 +32,7 @@ require "GameLab.Editor" require "GameLab.Editor.GUI"
-- debugging
---require("LuaPanda").start("127.0.0.1",8818)
+require("LuaPanda").start("127.0.0.1",8818)
-- launch editor
dofile("./Scripts/EditorApplication.lua")
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index 024d9d9..23f2a61 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -180,7 +180,7 @@ <ClCompile Include="..\..\..\Runtime\Graphics\Device.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\FrameBuffer.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\GlyphAtlas.cpp" />
- <ClCompile Include="..\..\..\Runtime\Graphics\GpuDataBuffer.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\GPUDataBuffers.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\ImageData.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\OpenGL.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\Point.cpp" />
@@ -188,6 +188,7 @@ <ClCompile Include="..\..\..\Runtime\Graphics\Quad.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\RenderTexture.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\Shader.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\ShaderCompiler.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\Texture.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\VertexBuffer.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindCFunctions.cpp" />
@@ -252,7 +253,7 @@ <ClInclude Include="..\..\..\Runtime\Graphics\DeviceDefine.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\FrameBuffer.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\GlyphAtlas.h" />
- <ClInclude Include="..\..\..\Runtime\Graphics\GpuDataBuffer.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\GPUDataBuffers.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\ImageData.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\OpenGL.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\Point.h" />
@@ -260,6 +261,7 @@ <ClInclude Include="..\..\..\Runtime\Graphics\Quad.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\RenderTexture.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\Shader.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\ShaderCompiler.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\Texture.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\VertexBuffer.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBind.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index 81e2dd9..2ec2b77 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -261,9 +261,6 @@ <ClCompile Include="..\..\..\Runtime\Graphics\GlyphAtlas.cpp">
<Filter>Runtime\Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runtime\Graphics\GpuDataBuffer.cpp">
- <Filter>Runtime\Graphics</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\Runtime\Graphics\ImageData.cpp">
<Filter>Runtime\Graphics</Filter>
</ClCompile>
@@ -354,6 +351,12 @@ <ClCompile Include="..\..\..\Editor\Utils\EditorUtils.cpp">
<Filter>Editor\Utils</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\GPUDataBuffers.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\ShaderCompiler.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\Editor\GUI\Dock.h">
@@ -524,9 +527,6 @@ <ClInclude Include="..\..\..\Runtime\Graphics\GlyphAtlas.h">
<Filter>Runtime\Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runtime\Graphics\GpuDataBuffer.h">
- <Filter>Runtime\Graphics</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\Runtime\Graphics\ImageData.h">
<Filter>Runtime\Graphics</Filter>
</ClInclude>
@@ -587,6 +587,12 @@ <ClInclude Include="..\..\..\Editor\Utils\EditorUtils.h">
<Filter>Editor\Utils</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\GPUDataBuffers.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\ShaderCompiler.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/Graphics/Device.cpp b/Runtime/Graphics/Device.cpp index 8136a54..9ba2e23 100644 --- a/Runtime/Graphics/Device.cpp +++ b/Runtime/Graphics/Device.cpp @@ -16,7 +16,7 @@ Device::~Device() void Device::Initialize(DeviceSetting& setting) { - GPU::BufferPool::Instance()->Initialize(); + //GPU::BufferPool::Instance()->Initialize(); } void Device::Enable(DeviceEnable enabled) @@ -72,7 +72,7 @@ void Device::BeginFrame() void Device::EndFrame() { - GPU::BufferPool::Instance()->OnEndFrame(); + //GPU::BufferPool::Instance()->OnEndFrame(); m_IsInsideFrame = false; } diff --git a/Runtime/Graphics/Device.h b/Runtime/Graphics/Device.h index c7a059e..56cb197 100644 --- a/Runtime/Graphics/Device.h +++ b/Runtime/Graphics/Device.h @@ -42,7 +42,7 @@ public: void PresentFrame(); //GET(SharedVertexBuffer*, SharedVBO, m_SharedVBO); - SharedVertexBuffer* GetSharedVBO() { return &m_SharedVBO; } + //SharedVertexBuffer* GetSharedVBO() { return &m_SharedVBO; } GET_SET(Color, ClearColor, m_ClearColor); @@ -65,7 +65,7 @@ private: StencilOp m_StencilOp; byte m_StencilMask; - SharedVertexBuffer m_SharedVBO; + //SharedVertexBuffer m_SharedVBO; bool m_IsInsideFrame; diff --git a/Runtime/Graphics/GPUDataBuffers.cpp b/Runtime/Graphics/GPUDataBuffers.cpp new file mode 100644 index 0000000..9e8df9f --- /dev/null +++ b/Runtime/Graphics/GPUDataBuffers.cpp @@ -0,0 +1,42 @@ +#include "GPUDataBuffers.h"
+
+void foo()
+{
+ GPUDataBuffer<float> buf = GPUDataBuffer<float>(GL_ARRAY_BUFFER, GL_STATIC_DRAW);
+ int n = buf.GetComponentSize();
+}
+
+VBO::VBO() + : GPUDataBuffer<float>(GL_ARRAY_BUFFER, GL_STATIC_DRAW) +{ +} +VBO::VBO(GLenum usage) + : GPUDataBuffer<float>(GL_ARRAY_BUFFER, usage) +{ +} +
+VBO::~VBO() +{ +} + +void VBO::AddVertexAttribute(int index, int numOfComps, int stride) +{ + VertexAttributeDescriptor attribute = VertexAttributeDescriptor();
+ attribute.index = index;
+ attribute.numOfComponents = numOfComps;
+ attribute.stride = stride;
+ m_Layout.attributes.push_back(attribute);
+} +void VBO::AddVertexAttribute(VertexAttributeDescriptor& attribute) +{ + m_Layout.attributes.push_back(attribute);
+} +int VBO::GetVertexAttributesCount() +{ + return m_Layout.attributes.size(); +} +void VBO::ClearVertexAttribute() +{ + m_Layout.attributes.clear();
+} + diff --git a/Runtime/Graphics/GPUDataBuffers.h b/Runtime/Graphics/GPUDataBuffers.h new file mode 100644 index 0000000..62e0413 --- /dev/null +++ b/Runtime/Graphics/GPUDataBuffers.h @@ -0,0 +1,160 @@ +#pragma once + +#include <vector> + +#include "Runtime/Lua/LuaHelper.h" +#include "../Utilities/Type.h" +#include "../Utilities/Singleton.h" +#include "../Utilities/UtilMacros.h" +#include "../Utilities/Assert.h" +#include "OpenGL.h" + +template<typename T> +// GPUͨûײʵ +class GPUDataBuffer +{ +public: + GPUDataBuffer(GLenum target, GLenum usage)/*throw GLException*/ + : m_Target(target) + , m_Usage(usage) + { + glGenBuffers(1, &m_Handle); + + CheckGLError( + glDeleteBuffers(1, &m_Handle); + throw GLException(error); + ); + } + virtual ~GPUDataBuffer() + { + glDeleteBuffers(1, &m_Handle); + } + + // ύ\» + void Upload(int offset, int size, const T* data) + { + glBindBuffer(m_Target, m_Handle); + glBufferSubData(m_Target, offset, size, data); + glBindBuffer(m_Target, 0); + } + + // »ݣUpload + T* Map(uint32 access) + { + glBindBuffer(m_Target, m_Handle); + void* ptr = glMapBuffer(m_Target, access); + glBindBuffer(m_Target, 0); + return ptr; + } + T* MapRange(int offset, int size, uint32 access) // + { + glBindBuffer(m_Target, m_Handle); + void* ptr = glMapBufferRange(m_Target, offset, size, access); + glBindBuffer(m_Target, 0); + return ptr; + } + void FlushMapedRange(int offset, int size) + { + glBindBuffer(m_Target, m_Handle); + glFlushMappedBufferRange(m_Target, offset, size); + glBindBuffer(m_Target, 0); + } + void UnMap() + { + glBindBuffer(m_Target, m_Handle); + glUnmapBuffer(m_Target); + glBindBuffer(m_Target, 0); + } + + // û + void Restore(int size, GLenum usage) + { + RestoreWithData(size, usage, 0); + } + void RestoreWithData(int size, GLenum usage, const T* data) + { + glBindBuffer(m_Target, m_Handle); + glBufferData(m_Target, size, data, usage); + glBindBuffer(m_Target, 0); + m_Size = size; + m_Usage = usage; + } + + void Orphan() + { + glBindBuffer(m_Target, m_Handle); + glBufferData(m_Target, 0, 0, GL_STREAM_DRAW); + glBindBuffer(m_Target, 0); + } + + int GetComponentSize() + { + return sizeof(T); + } + + GET(int, Size, m_Size); + GET(GLenum, Usage, m_Usage); + GET(GLuint, Handle, m_Handle); + +protected: + GLuint m_Handle; + + GLenum m_Target; + GLenum m_Usage; + + int m_Size; + +}; + +struct VertexAttributeDescriptor +{ + int index; // attribute layout index //glBindAttribLocation + int numOfComponents; // 1,2,3,4 + int stride; +}; + +struct VertexDataLayout +{ + std::vector<VertexAttributeDescriptor> attributes; +}; + +class DynamicVBO; +// +class VBO : public GPUDataBuffer<float> +{ +public: + VBO(); + virtual ~VBO(); + + void AddVertexAttribute(int index, int numOfComps, int stride); + void AddVertexAttribute(VertexAttributeDescriptor& attribute); + int GetVertexAttributesCount(); + void ClearVertexAttribute(); + + static const GLenum componentType = GL_FLOAT; + +protected: + friend class DynamicVBO; + VBO(GLenum usage); + + VertexDataLayout m_Layout; + +}; + +// ƵдĹvbo +class DynamicVBO : public VBO +{ +public: + DynamicVBO(); + ~DynamicVBO(); + +}; + +// +class IBO : GPUDataBuffer<UInt16> +{ +public: + static const GLenum componentType = GL_UNSIGNED_SHORT; + + +};
\ No newline at end of file diff --git a/Runtime/Graphics/GpuDataBuffer.cpp b/Runtime/Graphics/GpuDataBuffer.cpp deleted file mode 100644 index d20be65..0000000 --- a/Runtime/Graphics/GpuDataBuffer.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#include <math.h> - -#include "GpuDataBuffer.h" - -namespace GPU -{ - - // bufferҪĿϣGetHandle()Ŀ - // GL_COPY_READ_BUFFER - static const GLenum kBufferTarget = GL_COPY_WRITE_BUFFER; - - DataBuffer::DataBuffer() - { - glGenBuffers(1, &m_Handle); - } - - DataBuffer::~DataBuffer() - { - glDeleteBuffers(1, &m_Handle); - } - - void DataBuffer::Restore(int size, GLenum usage) - { - RestoreWithData(size, usage, 0); - } - - void DataBuffer::RestoreWithData(int size, GLenum usage, const void* data) - { - glBindBuffer(kBufferTarget, m_Handle); - glBufferData(kBufferTarget, size, data, usage); - glBindBuffer(kBufferTarget, 0); - m_Size = size; - m_Usage = usage; - } - - // glBufferSubData - // glMapBuffer - // glMapBufferRange (best one) - - void DataBuffer::Upload(int offset, int size, const void* data) - { - glBindBuffer(kBufferTarget, m_Handle); - glBufferSubData(kBufferTarget, offset, size, data); - glBindBuffer(kBufferTarget, 0); - } - - void* DataBuffer::Map(uint32 access) - { - glBindBuffer(kBufferTarget, m_Handle); - void* ptr = glMapBuffer(kBufferTarget, access); - glBindBuffer(kBufferTarget, 0); - return ptr; - } - - void* DataBuffer::MapRange(int offset, int size, uint32 access) - { - glBindBuffer(kBufferTarget, m_Handle); - void* ptr = glMapBufferRange(kBufferTarget, offset, size, access); - glBindBuffer(kBufferTarget, 0); - return ptr; - } - - void DataBuffer::FlushMapedRange(int offset, int size) - { - glBindBuffer(kBufferTarget, m_Handle); - glFlushMappedBufferRange(kBufferTarget, offset, size); - glBindBuffer(kBufferTarget, 0); - } - - void DataBuffer::UnMap() - { - glBindBuffer(kBufferTarget, m_Handle); - glUnmapBuffer(kBufferTarget); - glBindBuffer(kBufferTarget, 0); - } - - void DataBuffer::Orphan() - { - glBindBuffer(kBufferTarget, m_Handle); - glBufferData(kBufferTarget, 0, 0, GL_STREAM_DRAW); - glBindBuffer(kBufferTarget, 0); - } - - static bool IsBufferPoolCreated = false; - - BufferPool::BufferPool() - :m_LiveBuffers() - { - Assert(!IsBufferPoolCreated); - IsBufferPoolCreated = true; - } - - BufferPool::~BufferPool() - { - - } - - void BufferPool::Initialize() - { - for(int i = 0; i < kSizeClassCount; ++i) - m_LiveBuffers[i].clear(); - } - - static const float kBufferAllocateWeight = 10.0f; //! Default weight for buffer allocation from scratch. - static const float kBufferSizeWeightFactor = 1.f / 8096.f; //!< Weight factor for size difference. - static const float kBufferUsageDiffWeight = 8.f; //!< Weight factor for usage difference. - - static int ComputeBufferWeight(DataBuffer* buffer, int desiredSize, GLenum desiredUsage) - { - const int bufferSize = buffer->GetSize(); - const GLenum bufferUsage = buffer->GetUsage(); - - if(bufferSize == 0) - return kBufferAllocateWeight; - - const int sizeDiff = std::abs(bufferSize - desiredSize); - - return float(sizeDiff)*kBufferSizeWeightFactor + ((bufferUsage != desiredUsage) ? kBufferUsageDiffWeight : 0.f); - } - - DataBuffer* BufferPool::ClaimBuffer(int size, GLenum usage) - { - const float maxWeight = kBufferAllocateWeight; - const int maxCandidates = 5; // Number of potential candidates to consider actually. - - const int sizeClass = GetSizeClass(size); - int numCandidates = 0; // Number of potential candidates considered - int bestBufferNdx = -1; - float bestWeight = std::numeric_limits<float>::infinity(); - - for (int idx = 0; idx < m_LiveBuffers[sizeClass].size(); ++idx) - { - DataBuffer* buffer = m_LiveBuffers[sizeClass][idx]; - const float weight = ComputeBufferWeight(buffer, size, usage); - - if (weight < maxWeight && weight < bestWeight) - { - bestWeight = weight; - bestBufferNdx = idx; - ++numCandidates; - } - - if(numCandidates >= maxCandidates) - break; // Do not try other buffers, sorry. - } - - if (bestBufferNdx >= 0) - { - DataBuffer* selectedBuffer = m_LiveBuffers[sizeClass][bestBufferNdx]; - - if (bestBufferNdx + 1 != m_LiveBuffers[sizeClass].size()) - std::swap(m_LiveBuffers[sizeClass][bestBufferNdx], m_LiveBuffers[sizeClass].back()); - m_LiveBuffers[sizeClass].pop_back(); - - return selectedBuffer; - } - else - return new DataBuffer(); - - } - - void BufferPool::ReleaseBuffer(DataBuffer* buffer) - { - InsertToLive(buffer); - } - - void BufferPool::OnEndFrame() - { - UpdatePendingBuffersArray(); - } - - void BufferPool::UpdatePendingBuffersArray() - { - - } - - void BufferPool::InsertToLive(DataBuffer* buffer) - { - const int bufferSize = buffer->GetSize(); - const int sizeClass = GetSizeClass(bufferSize); - - m_LiveBuffers[sizeClass].push_back(buffer); - } - - uint BufferPool::GetSizeClass(uint bufferSize) - { - for (int idx = 0; idx < kSizeClassCount; ++idx) - { - if(bufferSize < GetSizeClassLimit(idx)) - return idx; - } - Assert(false); // never reach here - return 0; - } - - DataBuffer* ClaimBuffer(int size, GLenum usage ) - { - return BufferPool::Instance()->ClaimBuffer(size, usage); - } - - void ReleaseBuffer(DataBuffer* buffer) - { - BufferPool::Instance()->ReleaseBuffer(buffer); - } - -} diff --git a/Runtime/Graphics/GpuDataBuffer.h b/Runtime/Graphics/GpuDataBuffer.h deleted file mode 100644 index 0d65d3d..0000000 --- a/Runtime/Graphics/GpuDataBuffer.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef GPU_DATABUFFER_H -#define GPU_DATABUFFER_H - -#include <vector> - -#include "../Utilities/Type.h" -#include "../Utilities/Singleton.h" -#include "../Utilities/UtilMacros.h" -#include "../Utilities/Assert.h" -#include "OpenGL.h" - -namespace GPU -{ - - class DataBuffer - { - public: - void Upload(int offset, int size, const void* data); - void* Map(uint32 access); - void* MapRange(int offset, int size, uint32 access); // best performance - void FlushMapedRange(int offset, int size); - - void UnMap(); - - void Orphan(); - - // claim storage of size - void Restore(int size, GLenum usage); - // claim storage of size and fill it - void RestoreWithData(int size, GLenum usage, const void* data); - - GET(int, Size, m_Size); - GET(GLenum, Usage, m_Usage); - GET(GLuint, Handle, m_Handle); - - private: - friend class BufferPool; - - DataBuffer(); - ~DataBuffer(); - - GLuint m_Handle; - int m_Size; - GLenum m_Usage; - }; - - // recycle data buffer - class BufferPool : public Singleton<BufferPool> - { - public: - BufferPool(); - ~BufferPool(); - - void Initialize(); - - DataBuffer* ClaimBuffer(int size, GLenum usage); - void ReleaseBuffer(DataBuffer* buffer); - - void OnEndFrame(); - - private: - - inline int GetSizeClassLimit(int classNdx); - - void UpdatePendingBuffersArray(); - void InsertToLive(DataBuffer* buffer); - uint GetSizeClass(uint bufferSize); - - enum { - kSizeClassBaseLog2 = 10, - kSizeClassStepLog2 = 1, - kSizeClassCount = 7 - }; - - std::vector<DataBuffer*> m_LiveBuffers[kSizeClassCount]; - - }; - - inline int BufferPool::GetSizeClassLimit(int classNdx) - { - // (0, 2^10] 2^11 2^12 2^13 2^14 2^15 INT_MAX - return classNdx + 1 < kSizeClassCount ? (1 << (classNdx*kSizeClassStepLog2 + kSizeClassBaseLog2)) : INT_MAX; - } - - DataBuffer* ClaimBuffer(int size = 0, GLenum usage = GL_ARRAY_BUFFER); - void ReleaseBuffer(DataBuffer* buffer); - -} - -#endif
\ No newline at end of file diff --git a/Runtime/Graphics/ImageData.h b/Runtime/Graphics/ImageData.h index 4525ee3..7bf0335 100644 --- a/Runtime/Graphics/ImageData.h +++ b/Runtime/Graphics/ImageData.h @@ -46,27 +46,4 @@ private: LUA_BIND_DECL_METHOD(_GetSize); }; -enum EImageDataAsyncError -{ - NoFile = 1, - ParseFailed = 2, - InvalidFormat = 3, -}; - -struct ImageDataRequest -{ - bool isDone, hasError; - int error; - int progress, all; - ImageData* result; - std::vector<ImageData*> results; -}; - -namespace ImageDataUtil -{ - ImageData* Load(const char* path); - ImageDataRequest* LoadAsync(const char* path); - ImageDataRequest* LoadAsync(std::vector<const char*> paths); -} - #endif
\ No newline at end of file diff --git a/Runtime/Graphics/OpenGL.h b/Runtime/Graphics/OpenGL.h index 69755e1..b1b777e 100644 --- a/Runtime/Graphics/OpenGL.h +++ b/Runtime/Graphics/OpenGL.h @@ -8,17 +8,26 @@ //http://docs.gl/gl3/glClear #define CheckGLError(action)\ -if(true){ \ - GLenum error; \ +if(true){ \ + GLenum error; \ while ((error = glGetError()) != GL_NO_ERROR) { \ - action \ - } \ + action \ + } \ } -class GLException : std::exception +extern std::string g_sharedGLErrorMsg; + +class GLException : public std::exception { +public: + GLException(const char* what) + : std::exception(what) + {} + GLException(int glError) + { + g_sharedGLErrorMsg = std::to_string(glError); + std::exception(g_sharedGLErrorMsg.c_str()); + } }; -extern std::string g_sharedGLErrorMsg; - -#endif +#endif
\ No newline at end of file diff --git a/Runtime/Graphics/Quad.cpp b/Runtime/Graphics/Quad.cpp index cbe8b74..aa4c9f5 100644 --- a/Runtime/Graphics/Quad.cpp +++ b/Runtime/Graphics/Quad.cpp @@ -1,52 +1,52 @@ -#include "../Math/Vector2.h" -#include "../Math/Vector3.h" -#include "Quad.h" -#include "Device.h" - -struct QuadVBOLayout -{ - Vector3 position; - Vector2 uv; -}; - -void Quad::Draw() -{ - const int nVerts = 4; - const int nIndices = 6; - - float pos[] = { - m_Left, m_Bottom, 0, // left-bottom - m_Right, m_Bottom, 0, // right-bottom - m_Right, m_Top, 0, // right-top - m_Left, m_Top, 0, // top-left - }; - float uv[] = { - 0, 0, - 1, 0, - 1, 1, - 0, 1, - }; - int indices[] = { - 0, 1, 3, // right-top - 1, 2, 3, // left-bottom - }; - - uint8* vb; - uint16* ib; - - uint attrs = Mask(VertexAttr_Position) | Mask(VertexAttr_TexCoord0); - g_SharedVBO.GetChunk(attrs, 4, 6, RenderMode_Triangle, (void**)&vb, (void**)&ib); - - QuadVBOLayout* dst = (QuadVBOLayout*)vb; - for (int i = 0; i < nVerts; ++i) - { - dst[i].position.Set(pos[3 * i], pos[3 * i + 1], pos[3 * i + 2]); - dst[i].uv.Set(uv[2 * i], uv[2 * i + 1]); - } - - for (int i = 0; i < nIndices; ++i) - ib[i] = indices[i]; - - g_SharedVBO.ReleaseChunk(4, 6); - g_SharedVBO.DrawChunk(); -}
\ No newline at end of file +//#include "../Math/Vector2.h" +//#include "../Math/Vector3.h" +//#include "Quad.h" +//#include "Device.h" +// +//struct QuadVBOLayout +//{ +// Vector3 position; +// Vector2 uv; +//}; +// +//void Quad::Draw() +//{ +// const int nVerts = 4; +// const int nIndices = 6; +// +// float pos[] = { +// m_Left, m_Bottom, 0, // left-bottom +// m_Right, m_Bottom, 0, // right-bottom +// m_Right, m_Top, 0, // right-top +// m_Left, m_Top, 0, // top-left +// }; +// float uv[] = { +// 0, 0, +// 1, 0, +// 1, 1, +// 0, 1, +// }; +// int indices[] = { +// 0, 1, 3, // right-top +// 1, 2, 3, // left-bottom +// }; +// +// uint8* vb; +// uint16* ib; +// +// uint attrs = Mask(VertexAttr_Position) | Mask(VertexAttr_TexCoord0); +// g_SharedVBO.GetChunk(attrs, 4, 6, RenderMode_Triangle, (void**)&vb, (void**)&ib); +// +// QuadVBOLayout* dst = (QuadVBOLayout*)vb; +// for (int i = 0; i < nVerts; ++i) +// { +// dst[i].position.Set(pos[3 * i], pos[3 * i + 1], pos[3 * i + 2]); +// dst[i].uv.Set(uv[2 * i], uv[2 * i + 1]); +// } +// +// for (int i = 0; i < nIndices; ++i) +// ib[i] = indices[i]; +// +// g_SharedVBO.ReleaseChunk(4, 6); +// g_SharedVBO.DrawChunk(); +//}
\ No newline at end of file diff --git a/Runtime/Graphics/Quad.h b/Runtime/Graphics/Quad.h index 0e38ec4..58db95a 100644 --- a/Runtime/Graphics/Quad.h +++ b/Runtime/Graphics/Quad.h @@ -1,25 +1,25 @@ -#ifndef QUAD_H -#define QUAD_H - -#include "../Utilities/UtilMacros.h" - -class Quad -{ -public: - Quad(float l, float r, float t, float b); - - void Set(float l, float r, float t, float b); - - GET_SET(float, Left, m_Left); - GET_SET(float, Right, m_Right); - GET_SET(float, Top, m_Top); - GET_SET(float, Bottom, m_Bottom); - - void Draw(); - -private: - float m_Left, m_Right, m_Top, m_Bottom; - -}; - -#endif
\ No newline at end of file +//#ifndef QUAD_H +//#define QUAD_H +// +//#include "../Utilities/UtilMacros.h" +// +//class Quad +//{ +//public: +// Quad(float l, float r, float t, float b); +// +// void Set(float l, float r, float t, float b); +// +// GET_SET(float, Left, m_Left); +// GET_SET(float, Right, m_Right); +// GET_SET(float, Top, m_Top); +// GET_SET(float, Bottom, m_Bottom); +// +// void Draw(); +// +//private: +// float m_Left, m_Right, m_Top, m_Bottom; +// +//}; +// +//#endif
\ No newline at end of file diff --git a/Runtime/Graphics/ShaderCompiler.cpp b/Runtime/Graphics/ShaderCompiler.cpp new file mode 100644 index 0000000..d68b64e --- /dev/null +++ b/Runtime/Graphics/ShaderCompiler.cpp @@ -0,0 +1,7 @@ +#include "ShaderCompiler.h"
+
+int GLSLCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh)
+{
+
+ return 0;
+}
diff --git a/Runtime/Graphics/ShaderCompiler.h b/Runtime/Graphics/ShaderCompiler.h new file mode 100644 index 0000000..2917cf4 --- /dev/null +++ b/Runtime/Graphics/ShaderCompiler.h @@ -0,0 +1,33 @@ +#pragma once
+
+#include <string>
+#include "Runtime/Threading/Mutex.h"
+#include "Runtime/Threading/Job.h"
+
+// GLSL(GameLab Shading Language)
+
+// in: .glsl path
+// out: vsh & fsh
+class CompileGLSLJob : public Job
+{
+
+};
+
+// in: glsl shader
+// out: vsh & fsh
+class CompileGLSLShaderJob : public Job
+{
+
+};
+
+enum EGLSLCompileErrorCode
+{
+ Success = 0,
+};
+
+class GLSLCompiler
+{
+public:
+ static int Compile(std::string& src, std::string& vsh, std::string& fsh);
+
+};
diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h index 9179e0d..cf33cc5 100644 --- a/Runtime/Graphics/VertexBuffer.h +++ b/Runtime/Graphics/VertexBuffer.h @@ -7,7 +7,7 @@ #include "../Shaders/ShaderChannel.h" #include "OpenGL.h" -#include "GpuDataBuffer.h" +#include "GPUDataBuffers.h" enum VertexAttr { @@ -62,7 +62,8 @@ public: private: VertexBufferType m_Type; - GPU::DataBuffer *m_VB, *m_IB;// vertex buffer and index buffer + VBO *m_VB; + IBO *m_IB;// vertex buffer and index buffer }; @@ -87,7 +88,8 @@ private: enum { DataBufferThreshold = 1024 }; // shared vbo and ibo - GPU::DataBuffer *m_CurVB, *m_CurIB; + VBO *m_CurVB; + IBO *m_CurIB; // restore vbo and ibo data if not using pinned memory mapping std::vector<byte> m_CurVBData; |