summaryrefslogtreecommitdiff
path: root/source/modules
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-04-03 21:56:51 +0800
committerchai <chaifix@163.com>2019-04-03 21:56:51 +0800
commite13616b5c40f912853be99f0603f0e4c97b22062 (patch)
tree6663eab986dbf0317f326bce863edc3d7bf3332e /source/modules
parentc8a6a8e2dd6f015a31b4f8191ad945a78fe77f3d (diff)
*misc
Diffstat (limited to 'source/modules')
-rw-r--r--source/modules/asura-box2d/physics/binding/_body.cpp1
-rw-r--r--source/modules/asura-core/graphics/gl.cpp72
-rw-r--r--source/modules/asura-core/graphics/gl.h13
-rw-r--r--source/modules/asura-core/graphics/image.h5
-rw-r--r--source/modules/asura-core/graphics/shader.cpp37
-rw-r--r--source/modules/asura-core/graphics/shader.h5
-rw-r--r--source/modules/asura-core/graphics/texture.h2
-rw-r--r--source/modules/asura-utils/io/compressor.h2
-rw-r--r--source/modules/asura-utils/io/data_buffer.h16
-rw-r--r--source/modules/asura-utils/io/file_data.cpp9
-rw-r--r--source/modules/asura-utils/io/io_task.cpp6
-rw-r--r--source/modules/asura-utils/io/io_task.h7
-rw-r--r--source/modules/asura-utils/scripting/portable.hpp10
-rw-r--r--source/modules/asura-utils/threading/task.h3
-rw-r--r--source/modules/asura-utils/threading/thread.cpp4
-rw-r--r--source/modules/asura-utils/type.h2
-rw-r--r--source/modules/asura-utils/utils_module.cpp2
17 files changed, 134 insertions, 62 deletions
diff --git a/source/modules/asura-box2d/physics/binding/_body.cpp b/source/modules/asura-box2d/physics/binding/_body.cpp
index 68f3aaf..51cc0ab 100644
--- a/source/modules/asura-box2d/physics/binding/_body.cpp
+++ b/source/modules/asura-box2d/physics/binding/_body.cpp
@@ -45,7 +45,6 @@ namespace AsuraEngine
LUAX_IMPL_METHOD(Body, _GetType)
{
LUAX_PREPARE(L, Body);
-
return 0;
}
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index e199a41..47476a7 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -12,24 +12,24 @@ namespace AsuraEngine
namespace Graphics
{
+#if ASURA_DEBUG
static bool _instantiated = false;
+#endif
- //
OpenGL gl;
OpenGL::OpenGL()
{
- // Ҫڶʵ
+#if ASURA_DEBUG
ASSERT(!_instantiated);
_instantiated = true;
+#endif
}
OpenGL::~OpenGL()
{
}
- //------------------------------------------------------------------------------//
-
void OpenGL::SetViewport(const Recti v)
{
glViewport(v.x, v.y, v.w, v.h);
@@ -52,5 +52,69 @@ namespace AsuraEngine
state.shader = nullptr;
}
+ //------------------------------------------------------------------------------//
+
+ void OpenGL::SetMatrixMode(MatrixMode mode)
+ {
+ state.matrixMode = mode;
+ }
+
+ MatrixMode OpenGL::GetMatrixMode()
+ {
+ return state.matrixMode;
+ }
+
+ void OpenGL::PushMatrix()
+ {
+ state.matrix[state.matrixMode].Push();
+ }
+
+ void OpenGL::PopMatrix()
+ {
+ state.matrix[state.matrixMode].Pop();
+ }
+
+ void OpenGL::LoadIdentity()
+ {
+ state.matrix[state.matrixMode].LoadIdentity();
+ }
+
+ void OpenGL::Rotate(float angle, float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Rotate(angle, x, y, z);
+ }
+
+ void OpenGL::Translate(float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Translate(x, y, z);
+ }
+
+ void OpenGL::Scale(float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Scale(x, y, z);
+ }
+
+ void OpenGL::Ortho(float l, float r, float b, float t, float n, float f)
+ {
+ state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f);
+ }
+
+ AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode)
+ {
+ return state.matrix[state.matrixMode].GetTop();
+ }
+
+ uint OpenGL::GetMatrixDepth()
+ {
+ return state.matrix[state.matrixMode].GetCapacity();
+ }
+
+ uint OpenGL::GetMatrixIndex()
+ {
+ return state.matrix[state.matrixMode].GetTopIndex();
+ }
+
+ //------------------------------------------------------------------------------//
+
}
} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index 3104288..6838bc9 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -22,15 +22,14 @@ namespace AsuraEngine
enum MatrixMode
{
MATRIX_PROJECTION = 0,
- MATRIX_MODELVIEW,
- _MATRIX_COUNT
+ MATRIX_MODELVIEW = 1,
};
///
/// OpenGLģһЩopengl״̬׷١ڱ༭രڻ£һڶӦһhwnd
/// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳
/// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL
- /// ĵ״̬
+ /// ĵ״ֶ̬֧Ⱦ
///
class OpenGL : public AEScripting::Portable<OpenGL>
{
@@ -69,10 +68,10 @@ namespace AsuraEngine
///
struct
{
- Shader* shader; ///< ǰʹõshader
- AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[_MATRIX_COUNT]; ///< ͶӰ
- MatrixMode matrixMode; ///< ǰľ
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack matrix[2]; ///< 任
+ MatrixMode matrixMode; ///< ǰľ
} state;
private:
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 2e6ced2..e4aecd1 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -28,9 +28,8 @@ namespace AsuraEngine
/// һֻࡣҪǿǵeditorengineʹòͬķװ
///
class Image ASURA_FINAL
- : public Texture
- , public Scripting::Portable<Image>
- , public AEIO::Renewable
+ : public AEIO::Renewable
+ , public AEScripting::Portable<Image, Texture>
{
public:
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index fdcdf1b..c26ddf1 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -12,24 +12,25 @@ namespace AsuraEngine
Shader::Shader()
{
- mProgram = glCreateProgram();
- if (mProgram == 0)
- throw Exception("Cannot create OpenGL shader program.");
-
- mVertShader = glCreateShader(GL_VERTEX_SHADER);
- if (mVertShader == 0)
- {
- glDeleteProgram(mProgram);
- throw Exception("Cannot create OpenGL vertex shader.");
- }
-
- mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
- if (mFragShader == 0)
- {
- glDeleteProgram(mProgram);
- glDeleteShader(mVertShader);
- throw Exception("Cannot create OpenGL fragment shader.");
- }
+ //Fix: Ҫʱ
+ //mProgram = glCreateProgram();
+ //if (mProgram == 0)
+ // throw Exception("Cannot create OpenGL shader program.");
+
+ //mVertShader = glCreateShader(GL_VERTEX_SHADER);
+ //if (mVertShader == 0)
+ //{
+ // glDeleteProgram(mProgram);
+ // throw Exception("Cannot create OpenGL vertex shader.");
+ //}
+
+ //mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ //if (mFragShader == 0)
+ //{
+ // glDeleteProgram(mProgram);
+ // glDeleteShader(mVertShader);
+ // throw Exception("Cannot create OpenGL fragment shader.");
+ //}
}
Shader::~Shader()
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index 6d51b8e..f4bce25 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -82,11 +82,6 @@ namespace AsuraEngine
private:
///
- /// ǰshader
- ///
- static Shader* mCurrentShader;
-
- ///
/// ñ
/// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
/// vec2 Asura_RenderTargetSize RTĴСΪλ
diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h
index f19f3a7..571c617 100644
--- a/source/modules/asura-core/graphics/texture.h
+++ b/source/modules/asura-core/graphics/texture.h
@@ -57,7 +57,7 @@ namespace AsuraEngine
/// ϲԵѿϵΪ׼EditorҲϽΪԭ㣬Ϊ
/// 㡣
///
- ASURA_ABSTRACT class Texture : virtual public AEScripting::NativeAccessor
+ ASURA_ABSTRACT class Texture : public AEScripting::Object
{
public:
diff --git a/source/modules/asura-utils/io/compressor.h b/source/modules/asura-utils/io/compressor.h
index 30a074c..65fd88a 100644
--- a/source/modules/asura-utils/io/compressor.h
+++ b/source/modules/asura-utils/io/compressor.h
@@ -20,8 +20,6 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_Compress);
LUAX_DECL_METHOD(_Decompress);
-
-
};
}
diff --git a/source/modules/asura-utils/io/data_buffer.h b/source/modules/asura-utils/io/data_buffer.h
index 61d158b..c60444e 100644
--- a/source/modules/asura-utils/io/data_buffer.h
+++ b/source/modules/asura-utils/io/data_buffer.h
@@ -56,6 +56,14 @@ namespace AsuraEngine
private:
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_GetData);
+ LUAX_DECL_METHOD(_GetSize);
+ LUAX_DECL_METHOD(_GetCapacity);
+ LUAX_DECL_METHOD(_Refactor);
+ LUAX_DECL_METHOD(_Load);
+ LUAX_DECL_METHOD(_Clear);
+
///
/// Buffer׵ַݵij
///
@@ -69,14 +77,6 @@ namespace AsuraEngine
AEThreading::Mutex mMutex;
- LUAX_DECL_METHOD(_New);
- LUAX_DECL_METHOD(_GetData);
- LUAX_DECL_METHOD(_GetSize);
- LUAX_DECL_METHOD(_GetCapacity);
- LUAX_DECL_METHOD(_Refactor);
- LUAX_DECL_METHOD(_Load);
- LUAX_DECL_METHOD(_Clear);
-
};
}
diff --git a/source/modules/asura-utils/io/file_data.cpp b/source/modules/asura-utils/io/file_data.cpp
index 92333cf..ad58db9 100644
--- a/source/modules/asura-utils/io/file_data.cpp
+++ b/source/modules/asura-utils/io/file_data.cpp
@@ -21,6 +21,8 @@ namespace AsuraEngine
FileData::~FileData()
{
+ if (mData)
+ mData->Release();
}
const std::string& FileData::GetFileName()
@@ -40,7 +42,12 @@ namespace AsuraEngine
void FileData::BindData(ASURA_MOVE DataBuffer* buffer)
{
+ if (!buffer)
+ return;
+ if (mData)
+ mData->Release();
mData = buffer;
+ mData->Retain();
}
DataBuffer* FileData::GetDataBuffer()
@@ -49,4 +56,4 @@ namespace AsuraEngine
}
}
-}
+} \ No newline at end of file
diff --git a/source/modules/asura-utils/io/io_task.cpp b/source/modules/asura-utils/io/io_task.cpp
index 5f0e1c8..ca03b09 100644
--- a/source/modules/asura-utils/io/io_task.cpp
+++ b/source/modules/asura-utils/io/io_task.cpp
@@ -15,10 +15,14 @@ namespace AsuraEngine
: mPath(path)
, mBuffer(buffer)
{
+ if (buffer)
+ buffer->Retain();
}
IOTask::~IOTask()
{
+ if (mBuffer)
+ mBuffer->Release();
}
bool IOTask::Execute()
@@ -31,6 +35,8 @@ namespace AsuraEngine
// pathȡݱmBuffer
else if (mType == IOTASK_TYPE_READ)
{
+ if (!mBuffer)
+ return false;
file.Open(File::FILE_MODE_READ);
file.ReadAll(mBuffer);
file.Close();
diff --git a/source/modules/asura-utils/io/io_task.h b/source/modules/asura-utils/io/io_task.h
index 09c8798..0cf5023 100644
--- a/source/modules/asura-utils/io/io_task.h
+++ b/source/modules/asura-utils/io/io_task.h
@@ -24,8 +24,7 @@ namespace AsuraEngine
/// ȡļ
///
class IOTask ASURA_FINAL
- : public AEThreading::Task
- , public AEScripting::Portable<IOTask>
+ : public AEScripting::Portable<IOTask, AEThreading::Task>
{
public:
@@ -46,8 +45,8 @@ namespace AsuraEngine
std::string mPath;
IOTaskType mType;
- asura_ref DataBuffer* mBuffer;
- Luax::LuaxMemberRef mBufferRef;
+ DataBuffer* mBuffer;
+ Luax::LuaxMemberRef mBufferRef;
};
diff --git a/source/modules/asura-utils/scripting/portable.hpp b/source/modules/asura-utils/scripting/portable.hpp
index ffed49e..1c05163 100644
--- a/source/modules/asura-utils/scripting/portable.hpp
+++ b/source/modules/asura-utils/scripting/portable.hpp
@@ -15,15 +15,15 @@ namespace AsuraEngine
{
///
- /// ҪעluanativeҪ̳дģ塣
+ /// ҪΪ࣬userdatamember ref̳д࣬ע̳С
///
- template<typename T>
- using Portable = Luax::LuaxNativeClass<T>;
+ using Object = Luax::LuaxObject;
///
- /// ҪΪ࣬userdatamember ref̳д࣬ע̳С
+ /// ҪעluanativeҪ̳дģ塣
///
- using NativeAccessor = Luax::ILuaxNativeAccessor;
+ template<typename TYPE, typename BASE = Luax::LuaxObject>
+ using Portable = Luax::LuaxNativeClass<TYPE, BASE>;
}
}
diff --git a/source/modules/asura-utils/threading/task.h b/source/modules/asura-utils/threading/task.h
index 3b3a79c..9073045 100644
--- a/source/modules/asura-utils/threading/task.h
+++ b/source/modules/asura-utils/threading/task.h
@@ -12,8 +12,7 @@ namespace AsuraEngine
///
/// ϣһ̴߳񣬼̳TaskдExecute
///
- ASURA_ABSTRACT class Task
- : public virtual AEScripting::NativeAccessor
+ ASURA_ABSTRACT class Task : public AEScripting::Object
{
public:
diff --git a/source/modules/asura-utils/threading/thread.cpp b/source/modules/asura-utils/threading/thread.cpp
index fc397d2..0899485 100644
--- a/source/modules/asura-utils/threading/thread.cpp
+++ b/source/modules/asura-utils/threading/thread.cpp
@@ -43,6 +43,7 @@ namespace AsuraEngine
{
lock(mTaskQueueMutex)
{
+ task->Retain();
mTaskQueue.push(task);
}
return true;
@@ -207,6 +208,7 @@ namespace AsuraEngine
if (mType == THREAD_TYPE_DEFERRED)
{
mFinishedMutex.Lock();
+ task->Retain();
mFinishedTasks.push(task);
mFinishedMutex.Unlock();
}
@@ -218,6 +220,7 @@ namespace AsuraEngine
}
mTaskQueueMutex.Lock();
mTaskQueue.pop();
+ task->Release();
mTaskQueueMutex.Unlock();
}
}
@@ -262,6 +265,7 @@ namespace AsuraEngine
this->LuaxRelease<Task>(state, task);
mFinishedMutex.Lock();
mFinishedTasks.pop();
+ task->Release();
mFinishedMutex.Unlock();
}
}
diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h
index 7f80bfa..738c4f1 100644
--- a/source/modules/asura-utils/type.h
+++ b/source/modules/asura-utils/type.h
@@ -70,6 +70,8 @@ namespace AsuraEngine
/// ƶָȨ
///
#define ASURA_MOVE
+
+#define ASURA_DEBUG 1
//--------------------------------------------------------------------------------//
diff --git a/source/modules/asura-utils/utils_module.cpp b/source/modules/asura-utils/utils_module.cpp
index 61780e6..5616be4 100644
--- a/source/modules/asura-utils/utils_module.cpp
+++ b/source/modules/asura-utils/utils_module.cpp
@@ -10,10 +10,10 @@ namespace AsuraEngine
{
// IO
LUAX_REGISTER_SINGLETON(state, Filesystem);
+ LUAX_REGISTER_FACTORY(state, IOTask);
LUAX_REGISTER_FACTORY(state, DataBuffer);
LUAX_REGISTER_FACTORY(state, FileData);
LUAX_REGISTER_FACTORY(state, File);
- LUAX_REGISTER_FACTORY(state, IOTask);
// Threading
LUAX_REGISTER_FACTORY(state, Thread);
}