summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Asura.Editor/graphics/drawer.h1
-rw-r--r--source/Asura.Editor/graphics/shaders/poly_line.shader.h15
-rw-r--r--source/Asura.Editor/graphics/shaders/poly_shape.shader.h0
-rw-r--r--source/Asura.Editor/graphics/shaders/polygon.shader.h29
-rw-r--r--source/modules/asura-core/graphics/binding/_shader.cpp105
-rw-r--r--source/modules/asura-core/graphics/color.cpp8
-rw-r--r--source/modules/asura-core/graphics/color.h2
-rw-r--r--source/modules/asura-core/graphics/gl.cpp18
-rw-r--r--source/modules/asura-core/graphics/gl.h20
-rw-r--r--source/modules/asura-core/graphics/mesh2d.h10
-rw-r--r--source/modules/asura-core/graphics/render_state.h2
-rw-r--r--source/modules/asura-core/graphics/shader.cpp151
-rw-r--r--source/modules/asura-core/graphics/shader.h98
-rw-r--r--source/modules/asura-core/mesh/mesh2d_data.h26
-rw-r--r--source/modules/asura-utils/math/matrix44.h5
-rw-r--r--source/tests/win32/01-window/03_sub_menu.cpp64
16 files changed, 161 insertions, 393 deletions
diff --git a/source/Asura.Editor/graphics/drawer.h b/source/Asura.Editor/graphics/drawer.h
index a61a7f2..85cc88a 100644
--- a/source/Asura.Editor/graphics/drawer.h
+++ b/source/Asura.Editor/graphics/drawer.h
@@ -26,6 +26,7 @@ namespace AsuraEditor
void DrawTexts();
void DrawCircle(int x, int y, float d);
void DrawPoint(int x, int y);
+ void DrawPolyline();
private:
diff --git a/source/Asura.Editor/graphics/shaders/poly_line.shader.h b/source/Asura.Editor/graphics/shaders/poly_line.shader.h
deleted file mode 100644
index 763fd45..0000000
--- a/source/Asura.Editor/graphics/shaders/poly_line.shader.h
+++ /dev/null
@@ -1,15 +0,0 @@
-
-const char* s = R"(
-in vec2 asura_position;
-in vec2 asura_texcoord0;
-
-uniform mat4 asura_model_matrix;
-uniform mat4 asura_view_matrix;
-uniform mat4 asura_projection_matrix;
-
-void main()
-{
- gl_Position = asura_model_
-}
-
-)"; \ No newline at end of file
diff --git a/source/Asura.Editor/graphics/shaders/poly_shape.shader.h b/source/Asura.Editor/graphics/shaders/poly_shape.shader.h
deleted file mode 100644
index e69de29..0000000
--- a/source/Asura.Editor/graphics/shaders/poly_shape.shader.h
+++ /dev/null
diff --git a/source/Asura.Editor/graphics/shaders/polygon.shader.h b/source/Asura.Editor/graphics/shaders/polygon.shader.h
new file mode 100644
index 0000000..eed4f5a
--- /dev/null
+++ b/source/Asura.Editor/graphics/shaders/polygon.shader.h
@@ -0,0 +1,29 @@
+#ifndef __ASURA_EDITOR_SHADER_H__
+#include "../shader.h"
+#endif
+
+//
+static AsuraEditor::Graphics::ShaderProgram polygon_shader =
+{
+ R"(
+in vec2 position;
+
+uniform mat4 mvp_matrix;
+
+void main()
+{
+ gl_Position = mvp_matrix * vec4(position, 0, 1);
+}
+
+)",
+
+R"(
+uniform vec4 color;
+
+void main()
+{
+ gl_FragColor = color;
+}
+
+)"
+}; \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp
index 0484997..71f4e28 100644
--- a/source/modules/asura-core/graphics/binding/_shader.cpp
+++ b/source/modules/asura-core/graphics/binding/_shader.cpp
@@ -23,14 +23,6 @@ namespace AsuraEngine
{ "SetUniformVector3", _SetUniformVector3 },
{ "SetUniformVector4", _SetUniformVector4 },
{ "SetUniformColor", _SetUniformColor },
- { "SetAttribPosition", _SetAttribPosition },
- { "SetAttribTangent", _SetAttribTangent },
- { "SetAttribNormal", _SetAttribNormal },
- { "SetAttribColor", _SetAttribColor },
- { "SetAttribTexcoord0", _SetAttribTexcoord0 },
- { "SetAttribTexcoord1", _SetAttribTexcoord1 },
- { "SetAttribTexcoord2", _SetAttribTexcoord2 },
- { "SetAttribTexcoord3", _SetAttribTexcoord3 },
{ "SetBuiltInUniforms", _SetBuiltInUniforms }
);
}
@@ -136,102 +128,5 @@ namespace AsuraEngine
return 0;
}
- // 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;
- }
-
- // shader:SetAttribTangent()
- LUAX_IMPL_METHOD(Shader, _SetAttribTangent)
- {
- 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;
- }
-
- // shader:SetAttribNormal()
- LUAX_IMPL_METHOD(Shader, _SetAttribNormal)
- {
- 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;
- }
-
- // shader:SetAttribColor()
- LUAX_IMPL_METHOD(Shader, _SetAttribColor)
- {
- 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;
- }
-
- // shader:SetAttribTexcoord0()
- LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord0)
- {
- 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;
- }
-
- // shader:SetAttribTexcoord1()
- LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord1)
- {
- 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;
- }
-
- // shader:SetAttribTexcoord2()
- LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord2)
- {
- 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;
- }
-
- // shader:SetAttribTexcoord3()
- LUAX_IMPL_METHOD(Shader, _SetAttribTexcoord3)
- {
- 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/color.cpp b/source/modules/asura-core/graphics/color.cpp
index 9343939..76e0942 100644
--- a/source/modules/asura-core/graphics/color.cpp
+++ b/source/modules/asura-core/graphics/color.cpp
@@ -39,6 +39,14 @@ namespace AsuraEngine
{
}
+ void Color::Set(float r, float g, float b, float a)
+ {
+ this->r = r;
+ this->g = g;
+ this->b = b;
+ this->a = a;
+ }
+
//Color Color::operator *(const Color& c)
//{
// r *= c.r;
diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h
index 197921f..ababcf7 100644
--- a/source/modules/asura-core/graphics/color.h
+++ b/source/modules/asura-core/graphics/color.h
@@ -38,6 +38,8 @@ namespace AsuraEngine
Color operator *(const Color& c);
+ void Set(float r, float g, float b, float a);
+
float r, g, b, a;
//----------------------------------------------------------------------------//
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index 13c623f..08c50c3 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -5,6 +5,7 @@
#include "gl.h"
#include "shader.h"
#include "matrix_stack.h"
+#include "color.h"
using namespace AEMath;
@@ -70,13 +71,10 @@ namespace AsuraEngine
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;
+ state.drawColor.Set(r, g, b, a);
}
- AEMath::Vector4f& OpenGL::GetDrawColor()
+ Color& OpenGL::GetDrawColor()
{
return state.drawColor;
}
@@ -119,9 +117,6 @@ namespace AsuraEngine
void OpenGL::DrawArrays(GLenum mode, GLint first, GLsizei count)
{
glDrawArrays(mode, first, count);
- // shader disableAttributeArray
- if (state.shader)
- state.shader->DisableAttribArraies();
#if ASURA_GL_PROFILE
++stats.drawCall;
#endif
@@ -179,6 +174,13 @@ namespace AsuraEngine
return state.matrix[mode].GetTop();
}
+ AEMath::Matrix44 OpenGL::GetMVPMatrix()
+ {
+ return state.matrix[MATRIX_MODE_MODEL].GetTop()
+ * state.matrix[MATRIX_MODE_MODEL].GetTop()
+ * state.matrix[MATRIX_MODE_MODEL].GetTop();
+ }
+
uint OpenGL::GetMatrixDepth()
{
return state.matrix[state.matrixMode].GetCapacity();
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index 6bb1ee0..a4d9de2 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -10,6 +10,7 @@
#include <asura-utils/math/matrix44.h>
#include <asura-utils/math/vector4.h>
+#include "color.h"
#include "matrix_stack.h"
namespace AsuraEngine
@@ -23,8 +24,8 @@ namespace AsuraEngine
enum MatrixMode
{
MATRIX_MODE_PROJECTION = 0,
- MATRIX_MODE_MODEL = 1,
- MATRIX_MODE_VIEW = 2,
+ MATRIX_MODE_MODEL = 1,
+ MATRIX_MODE_VIEW = 2,
};
enum GLParams
@@ -62,7 +63,7 @@ namespace AsuraEngine
void UseShader(Shader* shader);
void UnuseShader();
Shader* GetShader();
-
+
///
/// ͳdrawcall
///
@@ -81,11 +82,12 @@ namespace AsuraEngine
void Scale(float x, float y);
void Ortho(float l, float r, float b, float t, float n, float f);
AEMath::Matrix44& GetMatrix(MatrixMode mode);
+ AEMath::Matrix44 GetMVPMatrix();
uint GetMatrixDepth();
uint GetMatrixIndex();
void SetDrawColor(float r, float g, float b, float a);
- AEMath::Vector4f& GetDrawColor();
+ Color& GetDrawColor();
///
/// ʾ
@@ -103,11 +105,11 @@ namespace AsuraEngine
///
struct
{
- Shader* shader; ///< ǰʹõshader
- AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[3]; ///< model, view, projection
- MatrixMode matrixMode; ///< ǰľ
- AEMath::Vector4f drawColor; ///< Ƶɫ
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack matrix[3]; ///< model, view, projection
+ MatrixMode matrixMode; ///< ǰľ
+ Color drawColor; ///< Ƶɫ
} state;
#if ASURA_GL_PROFILE
diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h
index 0c3627f..f2770e1 100644
--- a/source/modules/asura-core/graphics/mesh2d.h
+++ b/source/modules/asura-core/graphics/mesh2d.h
@@ -37,17 +37,15 @@ namespace AsuraEngine
private:
- //----------------------------------------------------------------------------//
-
LUAX_DECL_FACTORY(Mesh2D);
-
- //----------------------------------------------------------------------------//
+
+ LUAX_DECL_METHOD(_SetVertex);
///
- /// mesh2d dataйvboebo
+ /// mesh2d dataйvertex bufferindex buffer
///
VertexBuffer* mVBO;
- IndexBuffer* mEBO;
+ IndexBuffer* mIBO;
};
diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/graphics/render_state.h
index 4817dfa..b5814d3 100644
--- a/source/modules/asura-core/graphics/render_state.h
+++ b/source/modules/asura-core/graphics/render_state.h
@@ -1,11 +1,9 @@
#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 a2e230a..a0c14b4 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -15,25 +15,7 @@ namespace AsuraEngine
///
static int _texture_unit;
- const char* Shader::SemanticsName[] = {
- // uniforms
- "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)
{
}
@@ -109,9 +91,6 @@ namespace AsuraEngine
throw Exception("Link shader program failed:\n%s", warnning.c_str());
}
- // linklocations
- UpdateSemanticsLocations();
-
return true;
}
@@ -125,26 +104,6 @@ namespace AsuraEngine
_texture_unit;
}
- void Shader::DisableAttribArraies()
- {
- 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());
@@ -211,14 +170,10 @@ namespace AsuraEngine
glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements());
}
- void Shader::SetBuiltInUniforms()
+ void Shader::SetUniformColor(uint loc, const Color& color)
{
- // model\view\projection matrix
- SetUniformMatrix44(mMVP[MATRIX_MODE_MODEL], gl.GetMatrix(MATRIX_MODE_MODEL));
- SetUniformMatrix44(mMVP[MATRIX_MODE_VIEW], gl.GetMatrix(MATRIX_MODE_VIEW));
- SetUniformMatrix44(mMVP[MATRIX_MODE_PROJECTION], gl.GetMatrix(MATRIX_MODE_PROJECTION));
- // draw color
- SetUniformVector4(mDrawColor, gl.GetDrawColor());
+ if (gl.state.shader == this)
+ glUniform4f(loc, color.r, color.g, color.b, color.a);
}
//void Shader::GetUniform()
@@ -274,109 +229,25 @@ 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]);
- 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]);
- }
-
- void Shader::SetAttribPosition(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
+ void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized)
{
GLsizei offset = offseti * vbo->GetDataTypeSize();
GLsizei stride = stridei * vbo->GetDataTypeSize();
- glEnableVertexAttribArray(mPosition);
+ glEnableVertexAttribArray(loc);
vbo->Bind();
- glVertexAttribPointer(mPosition, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
+ glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_POSITION;
}
- void Shader::SetAttribTangent(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
+ int Shader::GetAttributeLocation(const std::string& attribute)
{
- GLsizei offset = offseti * vbo->GetDataTypeSize();
- GLsizei stride = stridei * vbo->GetDataTypeSize();
- glEnableVertexAttribArray(mTangent);
- vbo->Bind();
- glVertexAttribPointer(mTangent, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_TANGENT;
- }
-
- 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, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_NORMAL;
- }
-
- 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, 4, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_COLOR;
- }
-
- 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, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_TEXCOORD0;
- }
-
- 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, 2, vbo->GetDataType(), normalized, stride, (GLvoid*) offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_TEXCOORD1;
- }
-
- 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, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_TEXCOORD2;
+ int loc = glGetAttribLocation(mProgram, attribute.c_str());
+ return loc;
}
- void Shader::SetAttribTexcoord3(VertexBuffer* vbo, uint offseti, uint stridei,bool normalized)
+ void Shader::DisableAttribute(int loc)
{
- GLsizei offset = offseti * vbo->GetDataTypeSize();
- GLsizei stride = stridei * vbo->GetDataTypeSize();
- glEnableVertexAttribArray(mTexcoord3);
- vbo->Bind();
- glVertexAttribPointer(mTexcoord3, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset);
- vbo->UnBind();
- mEnabledAttributes |= ATTRIBUTE_TEXCOORD3;
+ glDisableVertexAttribArray(loc);
}
}
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index 9bb745e..b7bc70d 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -44,25 +44,15 @@ namespace AsuraEngine
void OnUse();
void OnUnuse();
-
- ///
- /// Disable֮ǰSetAttribXXXattributesÿdrawcallʱᱻglá
- ///
- void DisableAttribArraies();
-
+
///
/// öԣЩֵframeworkrenderer汻ãImageMesh2DЩԴ
/// normalizedΪtrueݻڸbuffer¹һ255ɫһ
/// 0~1
///
- 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);
+ void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false);
+ int GetAttributeLocation(const std::string& attribute);
+ void DisableAttribute(int loc);
///
/// uniform
@@ -77,11 +67,6 @@ namespace AsuraEngine
void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44);
bool SetUniformTexture(uint loc, const Texture& texture);
- ///
- /// \uniform
- ///
- void SetBuiltInUniforms();
-
float GetUniformFloat(uint loc);
AEMath::Vector2f GetUniformVector2(uint loc);
AEMath::Vector3f GetUniformVector3(uint loc);
@@ -110,14 +95,9 @@ namespace AsuraEngine
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);
+ LUAX_DECL_METHOD(_GetAttributeLocation);
+ LUAX_DECL_METHOD(_SetAttribute);
+ LUAX_DECL_METHOD(_DisableAttribute);
// uniform
LUAX_DECL_METHOD(_SetBuiltInUniforms);
@@ -125,73 +105,11 @@ namespace AsuraEngine
std::string GetProgramWarnings();
std::string GetShaderWarnings(GLuint shader);
- void UpdateSemanticsLocations();
-
- ///
- /// AsuraShader壬Ժuniformframeworkлshaderٴηװ
- /// ν壬ָshaderԶıⲿ򽻻ʱҪṩЩֵ
- /// ĻҪ
- ///
- enum Semantics
- {
- // MVP
- SEMANTICS_UNIFORM_MODEL_MATRIX = 0,
- SEMANTICS_UNIFORM_VIEW_MATRIX,
- SEMANTICS_UNIFORM_PROJECTION_MATRIX,
- // ʱɫ
- SEMANTICS_UNIFORM_DRAW_COLOR,
- //
- SEMANTICS_ATTRIBUTE_POSITION,
- //
- SEMANTICS_ATTRIBUTE_TANGENT,
- //
- SEMANTICS_ATTRIBUTE_NORMAL,
- // UV
- SEMANTICS_ATTRIBUTE_TEXCOORD0,
- SEMANTICS_ATTRIBUTE_TEXCOORD1,
- SEMANTICS_ATTRIBUTE_TEXCOORD2,
- SEMANTICS_ATTRIBUTE_TEXCOORD3,
- // ɫ
- SEMANTICS_ATTRIBUTE_COLOR,
-
- 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 ַͳһ
- ///
- static const char* SemanticsName[SEMANTICS_COUNT];
GLuint mProgram;
GLuint mVertShader;
GLuint mFragShader;
- GLuint mDrawColor;
-
- //
- GLint mMVP[3];
- GLint mPosition;
- GLint mTangent;
- GLint mNormal;
- GLint mColor;
- GLint mTexcoord0;
- GLint mTexcoord1;
- GLint mTexcoord2;
- GLint mTexcoord3;
-
- int mEnabledAttributes;
-
+
};
}
diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h
index 78b2427..8cb9723 100644
--- a/source/modules/asura-core/mesh/mesh2d_data.h
+++ b/source/modules/asura-core/mesh/mesh2d_data.h
@@ -1,12 +1,15 @@
#ifndef __ASURA_MESH2D_DATA_H__
#define __ASURA_MESH2D_DATA_H__
+// cpp
+#include <vector>
+
+// asura modules
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/math/vector2.hpp>
#include <asura-utils/io/decoded_data.h>
-#include <vector>
-
+// module
#include "../graphics/color.h"
#include "../graphics/gpu_buffer.h"
@@ -21,8 +24,6 @@ namespace AsuraEngine
struct Vertex
{
AEMath::Vector2f position; ///<
- AEMath::Vector2f tangent; ///<
- AEMath::Vector2f normal; ///<
AEGraphics::Color color; ///< ɫ
AEMath::Vector2f texCoord[4]; ///< UVs
};
@@ -36,11 +37,26 @@ namespace AsuraEngine
{
public:
+ enum Mesh2DComponent
+ {
+ MESH2D_COMPONENT_POSITION,
+ MESH2D_COMPONENT_COLOR,
+ MESH2D_COMPONENT_TEXCOORD0,
+ MESH2D_COMPONENT_TEXCOORD1,
+ MESH2D_COMPONENT_TEXCOORD2,
+ MESH2D_COMPONENT_TEXCOORD3,
+ };
+
void Decode(AEIO::DataBuffer& buffer) override;
private:
LUAX_DECL_FACTORY(Mesh2DData);
+
+ LUAX_DECL_ENUM(Mesh2DComponent, 1);
+
+ LUAX_DECL_METHOD(_GetVertices);
+ LUAX_DECL_METHOD(_GetVertex);
///
/// meshж㡣
@@ -52,6 +68,8 @@ namespace AsuraEngine
///
std::vector<float> mIndices;
+ int mComponents;
+
};
}
diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h
index addee98..30033c5 100644
--- a/source/modules/asura-utils/math/matrix44.h
+++ b/source/modules/asura-utils/math/matrix44.h
@@ -73,6 +73,11 @@ namespace AsuraEngine
/////
//void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const;
+ ///
+ /// ʽ
+ ///
+ float Calculate();
+
private:
///
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp
index ba384cb..9ddc8d7 100644
--- a/source/tests/win32/01-window/03_sub_menu.cpp
+++ b/source/tests/win32/01-window/03_sub_menu.cpp
@@ -30,8 +30,8 @@ AEMath::Recti viewport;
string vert = R"(
-in vec2 asura_position;
-in vec2 asura_texcoord0;
+in vec2 position;
+in vec2 uv;
uniform mat4 asura_projection_matrix;
uniform mat4 asura_model_matrix;
@@ -41,23 +41,35 @@ out vec2 texCoord;
void main()
{
- texCoord = asura_texcoord0;
- gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1);
+ gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(position, 0, 1);
+ texCoord = uv;
}
)";
string frag = R"(
in vec2 texCoord;
uniform sampler2D img;
+uniform vec4 color ;
void main()
{
- gl_FragColor = texture2D(img, texCoord);
+ //gl_FragColor = color * texture2D(img, texCoord);
+ gl_FragColor = color;
}
)";
Shader* shader;
VertexBuffer* vb;
+struct
+{
+ int pos;
+ int tex;
+ int m;
+ int v;
+ int p;
+ int color;
+} locs;
+
struct Vert
{
float x, y; // position
@@ -118,8 +130,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
if (gl.Inited())
{
RECT rect;
- GetWindowRect(hwnd, &rect);
- viewport.Set(0, 0, rect.right - rect.left, rect.bottom - rect.top);
+ GetClientRect(hwnd, &rect);
+ viewport.Set(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
gl.SetViewport(viewport);
}
}
@@ -140,8 +152,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
glBindTexture(GL_TEXTURE_2D, tex); //
+ // Χ
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ // ˲
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -154,11 +168,20 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
gl.LoadIdentity();
gl.Ortho(0, viewport.w, viewport.h, 0, -1, 1);
gl.SetMatrixMode(MATRIX_MODE_MODEL);
- gl.Translate(1, 0);
- shader->SetBuiltInUniforms();
- shader->SetAttribPosition(vb, 0, 4);
- shader->SetAttribTexcoord0(vb, 2, 4);
- gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ gl.LoadIdentity();
+ gl.Translate(100, 100);
+ shader->SetUniformMatrix44(locs.m, gl.GetMatrix(MATRIX_MODE_MODEL));
+ shader->SetUniformMatrix44(locs.v, gl.GetMatrix(MATRIX_MODE_VIEW));
+ shader->SetUniformMatrix44(locs.p, gl.GetMatrix(MATRIX_MODE_PROJECTION));
+ shader->SetAttribute(locs.pos, vb, 0, 4);
+ shader->SetAttribute(locs.tex, vb, 2, 4);
+ gl.SetDrawColor(1, 1, 0, 1);
+ shader->SetUniformColor(locs.color, gl.GetDrawColor());
+ //glLineWidth(1);
+ gl.DrawArrays(GL_LINE_STRIP, 0, 5);
+ //gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ shader->DisableAttribute(locs.pos);
+ shader->DisableAttribute(locs.tex);
gl.UnuseShader();
}
glFlush();
@@ -216,15 +239,28 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
{
int w = img->GetWidth();
int h = img->GetHeight();
+ //Vert v[] = {
+ // { 0.5f, 0.5f, 0, 0 },
+ //{ 0.5f, h + 0.5f, 0, 1 },
+ //{ w + 0.5f, 0.5f, 1, 0 },
+ //{ w + 0.5f, h + 0.5f, 1, 1 },
+ //};
Vert v[] = {
{ 0.5f, 0.5f, 0, 0 },
- { 0.5f, h + 0.5f, 0, 1 },
- { w + 0.5f, 0.5f, 1, 0 },
+ { 0.5f, h + 55.8f, 0, 1 },
{ w + 0.5f, h + 0.5f, 1, 1 },
+ { w + 0.5f, 0.5f, 1, 0 },
+ { 0.5f, 0.5f, 0, 0 },
};
vb = new VertexBuffer(BUFFER_USAGE_STATIC, BUFFER_DATA_TYPE_FLOAT, sizeof(v));
vb->Fill(v, sizeof(v));
};
+ locs.m = shader->GetUniformLocation("asura_model_matrix");
+ locs.v = shader->GetUniformLocation("asura_view_matrix");
+ locs.p = shader->GetUniformLocation("asura_projection_matrix");
+ locs.color = shader->GetUniformLocation("color");
+ locs.pos = shader->GetAttributeLocation("position");
+ locs.tex = shader->GetAttributeLocation("uv");
break;