summaryrefslogtreecommitdiff
path: root/source/modules
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules')
-rw-r--r--source/modules/asura-box2d/physics/body.h2
-rw-r--r--source/modules/asura-box2d/physics/chain_shape.h32
-rw-r--r--source/modules/asura-core/core_config.h2
-rw-r--r--source/modules/asura-core/graphics/binding/_gpu_buffer.cpp13
-rw-r--r--source/modules/asura-core/graphics/binding/_index_buffer.cpp32
-rw-r--r--source/modules/asura-core/graphics/binding/_shader.cpp35
-rw-r--r--source/modules/asura-core/graphics/binding/_vertex_buffer.cpp39
-rw-r--r--source/modules/asura-core/graphics/gl.cpp30
-rw-r--r--source/modules/asura-core/graphics/gl.h34
-rw-r--r--source/modules/asura-core/graphics/gpu_buffer.cpp13
-rw-r--r--source/modules/asura-core/graphics/gpu_buffer.h16
-rw-r--r--source/modules/asura-core/graphics/image.cpp42
-rw-r--r--source/modules/asura-core/graphics/image.h3
-rw-r--r--source/modules/asura-core/graphics/index_buffer.cpp18
-rw-r--r--source/modules/asura-core/graphics/index_buffer.h33
-rw-r--r--source/modules/asura-core/graphics/mesh2d.h18
-rw-r--r--source/modules/asura-core/graphics/render_state.h2
-rw-r--r--source/modules/asura-core/graphics/shader.cpp145
-rw-r--r--source/modules/asura-core/graphics/shader.h41
-rw-r--r--source/modules/asura-core/graphics/vertex_buffer.cpp18
-rw-r--r--source/modules/asura-core/graphics/vertex_buffer.h10
-rw-r--r--source/modules/asura-core/mesh/mesh2d_data.h12
-rw-r--r--source/modules/asura-fmod/audio/source.h20
-rw-r--r--source/modules/asura-fmod/fmod_module.h9
24 files changed, 472 insertions, 147 deletions
diff --git a/source/modules/asura-box2d/physics/body.h b/source/modules/asura-box2d/physics/body.h
index ce695ed..3a4aa5f 100644
--- a/source/modules/asura-box2d/physics/body.h
+++ b/source/modules/asura-box2d/physics/body.h
@@ -34,7 +34,7 @@ namespace AsuraEngine
LUAX_DECL_FACTORY(Body);
- LUAX_DECL_ENUM(BodyType);
+ LUAX_DECL_ENUM(BodyType, 1);
LUAX_DECL_METHOD(_GetType);
LUAX_DECL_METHOD(_GetX);
diff --git a/source/modules/asura-box2d/physics/chain_shape.h b/source/modules/asura-box2d/physics/chain_shape.h
index e69de29..dd03ddf 100644
--- a/source/modules/asura-box2d/physics/chain_shape.h
+++ b/source/modules/asura-box2d/physics/chain_shape.h
@@ -0,0 +1,32 @@
+#ifndef __ASURA_CHAIN_SHAPE_H__
+#define __ASURA_CHAIN_SHAPE_H__
+
+// 3rd-party
+#include <Box2D/Collision/Shapes/b2ChainShape.h>
+
+// asura modules
+#include <asura-utils/scripting/portable.hpp>
+
+namespace AsuraEngine
+{
+ namespace Physics
+ {
+
+ class ChainShape
+ : AEScripting::Portable<ChainShape>
+ {
+ public:
+
+ ChainShape();
+ ~ChainShape();
+
+ private:
+
+ b2ChainShape* mShape;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-core/core_config.h b/source/modules/asura-core/core_config.h
index 717f254..8a0e8c7 100644
--- a/source/modules/asura-core/core_config.h
+++ b/source/modules/asura-core/core_config.h
@@ -8,4 +8,6 @@
#define ASURA_OPENGL_GLUT (1 << 3)
#define ASURA_OPENGL_LOADER (ASURA_OPENGL_GLAD|ASURA_OPENGL_GLEE|ASURA_OPENGL_GLUT)
+#define ASURA_GL_PROFILE 1
+
#endif \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp
index 7a63c48..f55ba64 100644
--- a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp
+++ b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp
@@ -14,7 +14,6 @@ namespace AsuraEngine
LUAX_REGISTRY(GPUBuffer)
{
LUAX_REGISTER_METHODS(state,
- { "New", _New },
{ "Fill", _Fill },
{ "GetSize", _GetSize },
{ "GetCount", _GetCount }
@@ -45,14 +44,14 @@ namespace AsuraEngine
// buffer = GPUBuffer.New(mesh2d)
// buffer = GPUBuffer.New(canvas)
// buffer = GPUBuffer.New(shape)
- LUAX_IMPL_METHOD(GPUBuffer, _New)
- {
- LUAX_STATE(L);
+ //LUAX_IMPL_METHOD(GPUBuffer, _New)
+ //{
+ // LUAX_STATE(L);
- return 0;
- }
+ // return 0;
+ //}
- // gpubuffer:Fill({data unit list}, offseti)
+ // gpubuffer:Fill({data_unit_list}, offseti)
// data_unit_list ݵtable
// offseti : ʼǵĵطڵ(0ʼ
LUAX_IMPL_METHOD(GPUBuffer, _Fill)
diff --git a/source/modules/asura-core/graphics/binding/_index_buffer.cpp b/source/modules/asura-core/graphics/binding/_index_buffer.cpp
new file mode 100644
index 0000000..56bffb7
--- /dev/null
+++ b/source/modules/asura-core/graphics/binding/_index_buffer.cpp
@@ -0,0 +1,32 @@
+#include "../index_buffer.h"
+
+using namespace std;
+using namespace Luax;
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ LUAX_REGISTRY(IndexBuffer)
+ {
+ LUAX_REGISTER_METHODS(state,
+ { "New", _New }
+ );
+ }
+
+ LUAX_POSTPROCESS(IndexBuffer)
+ {
+
+ }
+
+ // IndexBuffer.New()
+ LUAX_IMPL_METHOD(IndexBuffer, _New)
+ {
+ LUAX_STATE(L);
+
+ return 0;
+ }
+
+ }
+}
diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp
index e0a6320..0484997 100644
--- a/source/modules/asura-core/graphics/binding/_shader.cpp
+++ b/source/modules/asura-core/graphics/binding/_shader.cpp
@@ -136,11 +136,16 @@ namespace AsuraEngine
return 0;
}
- // shader:SetAttribPosition()
+ // shader:SetAttribPosition(vbo, offseti, stridei, normalized)
LUAX_IMPL_METHOD(Shader, _SetAttribPosition)
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ bool normalized = state.GetValue<bool>(5, false);
+ self->SetAttribPosition(vbo, offseti, stridei, normalized);
return 0;
}
@@ -149,6 +154,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribTangent(vbo, offseti, stridei);
return 0;
}
@@ -157,6 +166,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribNormal(vbo, offseti, stridei);
return 0;
}
@@ -165,6 +178,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribColor(vbo, offseti, stridei);
return 0;
}
@@ -173,6 +190,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribPosition(vbo, offseti, stridei);
return 0;
}
@@ -181,6 +202,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribPosition(vbo, offseti, stridei);
return 0;
}
@@ -189,6 +214,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribPosition(vbo, offseti, stridei);
return 0;
}
@@ -197,6 +226,10 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Shader);
+ VertexBuffer* vbo = state.CheckUserdata<VertexBuffer>(2);
+ uint offseti = state.GetValue<uint>(3, 0);
+ uint stridei = state.GetValue<uint>(4, 0);
+ self->SetAttribPosition(vbo, offseti, stridei);
return 0;
}
diff --git a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp
new file mode 100644
index 0000000..666e529
--- /dev/null
+++ b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp
@@ -0,0 +1,39 @@
+#include "../vertex_buffer.h"
+
+using namespace std;
+using namespace Luax;
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ LUAX_REGISTRY(VertexBuffer)
+ {
+ LUAX_REGISTER_METHODS(state,
+ { "New", _New }
+ );
+ }
+
+ LUAX_POSTPROCESS(VertexBuffer)
+ {
+
+ }
+
+ // vbo = VertexBuffer.New(usage, data_type, count)
+ LUAX_IMPL_METHOD(VertexBuffer, _New)
+ {
+ LUAX_STATE(L);
+
+ BufferUsage usage = (BufferUsage)state.CheckValue<uint>(1);
+ BufferDataType datatype = (BufferDataType)state.CheckValue<uint>(2);
+ uint count = state.CheckValue<uint>(3);
+
+ VertexBuffer* vbo = new VertexBuffer(usage, datatype, count * GPUBuffer::GetDataTypeSize(datatype));
+ vbo->PushLuaxUserdata(state);
+
+ return 1;
+ }
+
+ }
+}
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index e51e8f0..13c623f 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -68,6 +68,19 @@ namespace AsuraEngine
return glGetError();
}
+ void OpenGL::SetDrawColor(float r, float g, float b, float a)
+ {
+ state.drawColor.x = r;
+ state.drawColor.y = g;
+ state.drawColor.z = b;
+ state.drawColor.w = a;
+ }
+
+ AEMath::Vector4f& OpenGL::GetDrawColor()
+ {
+ return state.drawColor;
+ }
+
void OpenGL::SetViewport(const Recti v)
{
state.viewport = v;
@@ -81,8 +94,14 @@ namespace AsuraEngine
void OpenGL::UseShader(Shader* shader)
{
- glUseProgram(shader->GetGLProgram());
- state.shader = shader;
+ if (state.shader != shader)
+ {
+ glUseProgram(shader->GetGLProgram());
+ state.shader = shader;
+#if ASURA_GL_PROFILE
+ ++stats.shaderSwitch;
+#endif
+ }
shader->OnUse();
}
@@ -100,7 +119,12 @@ namespace AsuraEngine
void OpenGL::DrawArrays(GLenum mode, GLint first, GLsizei count)
{
glDrawArrays(mode, first, count);
- ++state.drawcall;
+ // shader disableAttributeArray
+ if (state.shader)
+ state.shader->DisableAttribArraies();
+#if ASURA_GL_PROFILE
+ ++stats.drawCall;
+#endif
}
//------------------------------------------------------------------------------//
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index f28b983..6bb1ee0 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -8,6 +8,7 @@
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/math/rect.hpp>
#include <asura-utils/math/matrix44.h>
+#include <asura-utils/math/vector4.h>
#include "matrix_stack.h"
@@ -18,7 +19,6 @@ namespace AsuraEngine
class Profiler;
class Shader;
- class GPUBuffer;
enum MatrixMode
{
@@ -27,7 +27,7 @@ namespace AsuraEngine
MATRIX_MODE_VIEW = 2,
};
- enum GLPrams
+ enum GLParams
{
GL_PARAM_MAX_TEXTURE_UNIT = 1,
};
@@ -48,7 +48,7 @@ namespace AsuraEngine
///
/// óֵ
///
- int GetParam(GLPrams param);
+ int GetParam(GLParams param);
///
/// ʼOpenGLIJڴOpenGL֮󡣴˺עOpenGLĵַ
@@ -84,6 +84,9 @@ namespace AsuraEngine
uint GetMatrixDepth();
uint GetMatrixIndex();
+ void SetDrawColor(float r, float g, float b, float a);
+ AEMath::Vector4f& GetDrawColor();
+
///
/// ʾ
///
@@ -100,23 +103,32 @@ namespace AsuraEngine
///
struct
{
- Shader* shader; ///< ǰʹõshader
- AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[3]; ///< model, view, projection
- MatrixMode matrixMode; ///< ǰľ
- uint drawcall; ///< ͳdrawcall
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack matrix[3]; ///< model, view, projection
+ MatrixMode matrixMode; ///< ǰľ
+ AEMath::Vector4f drawColor; ///< Ƶɫ
} state;
+#if ASURA_GL_PROFILE
+ struct
+ {
+ uint drawCall; ///< ͳdrawcall
+ uint canvasSwitch; ///< лtextureĴ
+ uint shaderSwitch; ///< лshaderĴ
+ } stats;
+#endif
+
private:
friend class Profiler;
- LUAX_DECL_SINGLETON(OpenGL);
-
//----------------------------------------------------------------------------//
+ LUAX_DECL_SINGLETON(OpenGL);
+
LUAX_DECL_ENUM(MatrixMode, 1);
- LUAX_DECL_ENUM(GLPrams, 1);
+ LUAX_DECL_ENUM(GLParams, 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 aecfa51..e16a4ac 100644
--- a/source/modules/asura-core/graphics/gpu_buffer.cpp
+++ b/source/modules/asura-core/graphics/gpu_buffer.cpp
@@ -138,5 +138,18 @@ namespace AsuraEngine
}
}
+ size_t GPUBuffer::GetDataTypeSize(GLenum datatype)
+ {
+ switch (datatype)
+ {
+ 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 f2e83fc..c492cbb 100644
--- a/source/modules/asura-core/graphics/gpu_buffer.h
+++ b/source/modules/asura-core/graphics/gpu_buffer.h
@@ -33,15 +33,17 @@ namespace AsuraEngine
};
///
- /// GPU壬ֶ㻺vboebo֣ÿζڴԴϴݡ
+ /// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡ
///
- ASURA_ABSTRACT class GPUBuffer : public AEScripting::Object
+ ASURA_ABSTRACT class GPUBuffer
{
public:
GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size);
virtual ~GPUBuffer();
+ static size_t GetDataTypeSize(GLenum datatype);
+
///
/// ʼ\»棬ûgpu bufferԴΪdzʼΪǸ¡
///
@@ -53,9 +55,16 @@ namespace AsuraEngine
void Bind();
void UnBind();
+ ///
+ /// bufferĴС(Byte)
+ ///
uint GetBufferSize();
-
+ ///
+ /// bufferԪظ=size/datatypesize
+ ///
+ uint GetBufferCount();
GLenum GetDataType();
+ size_t GetDataTypeSize();
private:
@@ -76,7 +85,6 @@ namespace AsuraEngine
GLenum ConvertBufferType(BufferType type);
GLenum ConvertBufferUsage(BufferUsage type);
GLenum ConvertBufferDataType(BufferDataType type);
- size_t GetDataTypeSize();
GLenum mTarget;
GLuint mBuffer;
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index 9244e73..ad2ae9a 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -99,48 +99,6 @@ namespace AsuraEngine
{
return mHeight;
}
- /*
- void Image::Render()
- {
- Shader* shader = gl.GetShader();
- if (!shader)
- return;
- uint32& w = mWidth, &h = mHeight;
- int vertices[] = {
- 0, 0, 0, 0,
- 0, h, 0, 1,
- w, 0, 1, 0,
- w, h, 1, 1,
- };
- // öϵ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 a1fba9a..cdc1b1a 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -1,6 +1,7 @@
#ifndef __ASURA_ENGINE_IMAGE_H__
#define __ASURA_ENGINE_IMAGE_H__
+// asura modules
#include <asura-utils/math/rect.hpp>
#include <asura-utils/math/vector2.hpp>
#include <asura-utils/scripting/portable.hpp>
@@ -8,8 +9,10 @@
#include <asura-utils/stringmap.hpp>
#include <asura-utils/manager.hpp>
+// module
#include "../image/image_data.h"
+// folder
#include "color.h"
#include "color32.h"
#include "render_state.h"
diff --git a/source/modules/asura-core/graphics/index_buffer.cpp b/source/modules/asura-core/graphics/index_buffer.cpp
index e69de29..fd0295d 100644
--- a/source/modules/asura-core/graphics/index_buffer.cpp
+++ b/source/modules/asura-core/graphics/index_buffer.cpp
@@ -0,0 +1,18 @@
+#include "index_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ IndexBuffer::IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size)
+ : GPUBuffer(BUFFER_TYPE_INDEX, usage, datatype, size)
+ {
+ }
+
+ IndexBuffer::~IndexBuffer()
+ {
+ }
+
+ }
+}
diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h
index e69de29..5fca0ea 100644
--- a/source/modules/asura-core/graphics/index_buffer.h
+++ b/source/modules/asura-core/graphics/index_buffer.h
@@ -0,0 +1,33 @@
+#ifndef __ASURA_INDEX_BUFFER_H__
+#define __ASURA_INDEX_BUFFER_H__
+
+#include <asura-utils/scripting/portable.hpp>
+
+#include "gpu_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ class IndexBuffer ASURA_FINAL
+ : public AEScripting::Portable<IndexBuffer>
+ , public GPUBuffer
+ {
+ public:
+
+ IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size);
+ ~IndexBuffer();
+
+ private:
+
+ LUAX_DECL_FACTORY(IndexBuffer);
+
+ LUAX_DECL_METHOD(_New);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h
index 420986e..0c3627f 100644
--- a/source/modules/asura-core/graphics/mesh2d.h
+++ b/source/modules/asura-core/graphics/mesh2d.h
@@ -1,13 +1,20 @@
#ifndef __ASURA_ENGINE_MESH2D_H__
#define __ASURA_ENGINE_MESH2D_H__
+// cpp
#include <vector>
+// asura modules
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/math/vector2.hpp>
+// module
+#include "../mesh/mesh2d_data.h"
+
+// folder
#include "color.h"
-#include "gpu_buffer.h"
+#include "vertex_buffer.h"
+#include "index_buffer.h"
namespace AsuraEngine
{
@@ -24,9 +31,10 @@ namespace AsuraEngine
public:
Mesh2D();
-
~Mesh2D();
+ bool Load(AEMesh::Mesh2DData* data);
+
private:
//----------------------------------------------------------------------------//
@@ -36,10 +44,10 @@ namespace AsuraEngine
//----------------------------------------------------------------------------//
///
- /// mesh2d dataйvbo ebo
+ /// mesh2d dataйvboebo
///
- GPUBuffer* mVBO;
- GPUBuffer* mEBO;
+ VertexBuffer* mVBO;
+ IndexBuffer* mEBO;
};
diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/graphics/render_state.h
index b5814d3..4817dfa 100644
--- a/source/modules/asura-core/graphics/render_state.h
+++ b/source/modules/asura-core/graphics/render_state.h
@@ -1,9 +1,11 @@
#ifndef __ASURA_ENGINE_RENDER_STATE_H__
#define __ASURA_ENGINE_RENDER_STATE_H__
+// asura modules
#include <asura-utils/math/vector2.hpp>
#include <asura-utils/math/transform.h>
+// folder
#include "blend_mode.h"
namespace AsuraEngine
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index cf3d4b2..a2e230a 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -17,21 +17,23 @@ namespace AsuraEngine
const char* Shader::SemanticsName[] = {
// uniforms
- "asura_model_matrix",
- "asura_view_matrix",
- "asura_projection_matrix",
- // attributes
- "asura_position",
- "asura_tangent",
- "asura_normal",
- "asura_texcoord0",
- "asura_texcoord1",
- "asura_texcoord2",
- "asura_texcoord3",
- "asura_color"
+ "asura_model_matrix", // mat4
+ "asura_view_matrix", // mat4
+ "asura_projection_matrix", // mat4
+ "asura_draw_color", // vec4
+ // attributes
+ "asura_position", // vec2
+ "asura_tangent", // vec2
+ "asura_normal", // vec2
+ "asura_texcoord0", // vec2
+ "asura_texcoord1", // vec2
+ "asura_texcoord2", // vec2
+ "asura_texcoord3", // vec2
+ "asura_color" // vec4
};
Shader::Shader()
+ : mEnabledAttributes(0)
{
}
@@ -116,28 +118,33 @@ namespace AsuraEngine
void Shader::OnUse()
{
_texture_unit = 0;
- // Disableöԣsetʱ
- glDisableVertexAttribArray(mPosition);
- glDisableVertexAttribArray(mTangent);
- glDisableVertexAttribArray(mNormal);
- glDisableVertexAttribArray(mColor);
- glDisableVertexAttribArray(mTexcoord0);
- glDisableVertexAttribArray(mTexcoord1);
- glDisableVertexAttribArray(mTexcoord2);
- glDisableVertexAttribArray(mTexcoord3);
}
void Shader::OnUnuse()
{
_texture_unit;
}
-/*
- int Shader::GetAttributeLocation(const std::string& name)
+
+ void Shader::DisableAttribArraies()
{
- GLint loc = glGetAttribLocation(mProgram, name.c_str());
- return loc;
+ if(mEnabledAttributes & ATTRIBUTE_POSITION)
+ glDisableVertexAttribArray(mPosition);
+ if (mEnabledAttributes & ATTRIBUTE_TANGENT)
+ glDisableVertexAttribArray(mTangent);
+ if (mEnabledAttributes & ATTRIBUTE_NORMAL)
+ glDisableVertexAttribArray(mNormal);
+ if (mEnabledAttributes & ATTRIBUTE_COLOR)
+ glDisableVertexAttribArray(mColor);
+ if (mEnabledAttributes & ATTRIBUTE_TEXCOORD0)
+ glDisableVertexAttribArray(mTexcoord0);
+ if (mEnabledAttributes & ATTRIBUTE_TEXCOORD1)
+ glDisableVertexAttribArray(mTexcoord1);
+ if (mEnabledAttributes & ATTRIBUTE_TEXCOORD2)
+ glDisableVertexAttribArray(mTexcoord2);
+ if (mEnabledAttributes & ATTRIBUTE_TEXCOORD3)
+ glDisableVertexAttribArray(mTexcoord3);
}
-*/
+
uint Shader::GetUniformLocation(const std::string& uniform)
{
GLint loc = glGetUniformLocation(mProgram, uniform.c_str());
@@ -210,6 +217,8 @@ namespace AsuraEngine
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));
+ // draw color
+ SetUniformVector4(mDrawColor, gl.GetDrawColor());
}
//void Shader::GetUniform()
@@ -268,82 +277,106 @@ namespace AsuraEngine
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_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]);
+ mPosition = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_POSITION]);
+ mTangent = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_TANGENT]);
+ mNormal = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_NORMAL]);
+ mColor = glGetAttribLocation(mProgram, SemanticsName[SEMANTICS_ATTRIBUTE_COLOR]);
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)
+ void Shader::SetAttribPosition(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mPosition);
vbo->Bind();
- glVertexAttribPointer(mPosition, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mPosition, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mPosition);
+ mEnabledAttributes |= ATTRIBUTE_POSITION;
}
- void Shader::SetAttribTangent(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribTangent(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mTangent);
vbo->Bind();
- glVertexAttribPointer(mTangent, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mTangent, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mTangent);
+ mEnabledAttributes |= ATTRIBUTE_TANGENT;
}
- void Shader::SetAttribNormal(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribNormal(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mNormal);
vbo->Bind();
- glVertexAttribPointer(mNormal, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mNormal, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mNormal);
+ mEnabledAttributes |= ATTRIBUTE_NORMAL;
}
- void Shader::SetAttribColor(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribColor(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mColor);
vbo->Bind();
- glVertexAttribPointer(mColor, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mColor, 4, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mColor);
+ mEnabledAttributes |= ATTRIBUTE_COLOR;
}
- void Shader::SetAttribTexcoord0(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribTexcoord0(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mTexcoord0);
vbo->Bind();
- glVertexAttribPointer(mTexcoord0, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mTexcoord0, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mTexcoord0);
+ mEnabledAttributes |= ATTRIBUTE_TEXCOORD0;
}
- void Shader::SetAttribTexcoord1(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribTexcoord1(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mTexcoord1);
vbo->Bind();
- glVertexAttribPointer(mTexcoord1, size, vbo->GetDataType(), normalized, stride, (GLvoid*) offset);
+ glVertexAttribPointer(mTexcoord1, 2, vbo->GetDataType(), normalized, stride, (GLvoid*) offset);
vbo->UnBind();
- glEnableVertexAttribArray(mTexcoord1);
+ mEnabledAttributes |= ATTRIBUTE_TEXCOORD1;
}
- void Shader::SetAttribTexcoord2(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribTexcoord2(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mTexcoord2);
vbo->Bind();
- glVertexAttribPointer(mTexcoord2, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mTexcoord2, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mTexcoord2);
+ mEnabledAttributes |= ATTRIBUTE_TEXCOORD2;
}
- void Shader::SetAttribTexcoord3(int size, GPUBuffer* vbo, GLsizei offset, GLsizei stride , bool normalized)
+ void Shader::SetAttribTexcoord3(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
{
+ GLsizei offset = offseti * vbo->GetDataTypeSize();
+ GLsizei stride = stridei * vbo->GetDataTypeSize();
+ glEnableVertexAttribArray(mTexcoord3);
vbo->Bind();
- glVertexAttribPointer(mTexcoord3, size, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(mTexcoord3, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- glEnableVertexAttribArray(mTexcoord3);
+ mEnabledAttributes |= ATTRIBUTE_TEXCOORD3;
}
}
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index a725ccf..9bb745e 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -17,7 +17,8 @@
#include "gl.h"
#include "color.h"
#include "texture.h"
-#include "gpu_buffer.h"
+#include "vertex_buffer.h"
+#include "index_buffer.h"
namespace AsuraEngine
{
@@ -45,18 +46,23 @@ namespace AsuraEngine
void OnUnuse();
///
+ /// Disable֮ǰSetAttribXXXattributesÿdrawcallʱᱻglá
+ ///
+ void DisableAttribArraies();
+
+ ///
/// öԣЩֵframeworkrenderer汻ãImageMesh2DЩԴ
/// normalizedΪtrueݻڸbuffer¹һ255ɫһ
/// 0~1
///
- 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);
+ void SetAttribPosition(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribTangent(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribNormal(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribColor(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribTexcoord0(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribTexcoord1(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribTexcoord2(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
+ void SetAttribTexcoord3(VertexBuffer* vbo, uint offseti = 0, uint stridei = 0,bool normalized = false);
///
/// uniform
@@ -132,6 +138,8 @@ namespace AsuraEngine
SEMANTICS_UNIFORM_MODEL_MATRIX = 0,
SEMANTICS_UNIFORM_VIEW_MATRIX,
SEMANTICS_UNIFORM_PROJECTION_MATRIX,
+ // ʱɫ
+ SEMANTICS_UNIFORM_DRAW_COLOR,
//
SEMANTICS_ATTRIBUTE_POSITION,
//
@@ -149,6 +157,18 @@ namespace AsuraEngine
SEMANTICS_COUNT
};
+ enum Attribute
+ {
+ ATTRIBUTE_POSITION = 1,
+ ATTRIBUTE_TANGENT = 1 << 1,
+ ATTRIBUTE_NORMAL = 1 << 2,
+ ATTRIBUTE_COLOR = 1 << 3,
+ ATTRIBUTE_TEXCOORD0 = 1 << 4,
+ ATTRIBUTE_TEXCOORD1 = 1 << 5,
+ ATTRIBUTE_TEXCOORD2 = 1 << 6,
+ ATTRIBUTE_TEXCOORD3 = 1 << 7,
+ };
+
///
/// Asura shader ַͳһ
///
@@ -157,6 +177,7 @@ namespace AsuraEngine
GLuint mProgram;
GLuint mVertShader;
GLuint mFragShader;
+ GLuint mDrawColor;
//
GLint mMVP[3];
@@ -169,6 +190,8 @@ namespace AsuraEngine
GLint mTexcoord2;
GLint mTexcoord3;
+ int mEnabledAttributes;
+
};
}
diff --git a/source/modules/asura-core/graphics/vertex_buffer.cpp b/source/modules/asura-core/graphics/vertex_buffer.cpp
index e69de29..437bd48 100644
--- a/source/modules/asura-core/graphics/vertex_buffer.cpp
+++ b/source/modules/asura-core/graphics/vertex_buffer.cpp
@@ -0,0 +1,18 @@
+#include "vertex_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ VertexBuffer::VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size)
+ : GPUBuffer(BUFFER_TYPE_VERTEX, usage, datatype, size)
+ {
+ }
+
+ VertexBuffer::~VertexBuffer()
+ {
+ }
+
+ }
+}
diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h
index b8245e5..f00b4d2 100644
--- a/source/modules/asura-core/graphics/vertex_buffer.h
+++ b/source/modules/asura-core/graphics/vertex_buffer.h
@@ -10,16 +10,20 @@ namespace AsuraEngine
namespace Graphics
{
- class VertexBuffer : AEScripting::Portable<VertexBuffer, GPUBuffer>
+ class VertexBuffer ASURA_FINAL
+ : public AEScripting::Portable<VertexBuffer>
+ , public GPUBuffer
{
public:
VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size);
~VertexBuffer();
- private:
+ private:
- LUAX_DECL_FACTORY(VertexBuffer, GPUBuffer);
+ LUAX_DECL_FACTORY(VertexBuffer);
+
+ LUAX_DECL_METHOD(_New);
};
diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h
index 409451d..78b2427 100644
--- a/source/modules/asura-core/mesh/mesh2d_data.h
+++ b/source/modules/asura-core/mesh/mesh2d_data.h
@@ -30,15 +30,15 @@ namespace AsuraEngine
///
/// meshĶݺ
///
- class Mesh2DData
+ class Mesh2DData
: AEIO::DecodedData
, AEScripting::Portable<Mesh2DData>
{
- public:
+ public:
void Decode(AEIO::DataBuffer& buffer) override;
-
- private:
+
+ private:
LUAX_DECL_FACTORY(Mesh2DData);
@@ -50,11 +50,13 @@ namespace AsuraEngine
///
/// ebo
///
- std::vector<float> mIndices;
+ std::vector<float> mIndices;
};
}
}
+namespace AEMesh = AsuraEngine::Mesh;
+
#endif \ No newline at end of file
diff --git a/source/modules/asura-fmod/audio/source.h b/source/modules/asura-fmod/audio/source.h
new file mode 100644
index 0000000..4585415
--- /dev/null
+++ b/source/modules/asura-fmod/audio/source.h
@@ -0,0 +1,20 @@
+#ifndef __ASURA_FMOD_SOURCE_H__
+#define __ASURA_FMOD_SOURCE_H__
+
+namespace AsruaEngine
+{
+ namespace Audio
+ {
+
+ ///
+ /// fmod
+ ///
+ class Source
+ {
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-fmod/fmod_module.h b/source/modules/asura-fmod/fmod_module.h
new file mode 100644
index 0000000..67b8618
--- /dev/null
+++ b/source/modules/asura-fmod/fmod_module.h
@@ -0,0 +1,9 @@
+#ifndef __ASURA_FMOD_MODULE_H__
+#define __ASURA_FMOD_MODULE_H__
+
+namespace AsuraEngine
+{
+
+}
+
+#endif \ No newline at end of file