summaryrefslogtreecommitdiff
path: root/source/tests
diff options
context:
space:
mode:
Diffstat (limited to 'source/tests')
-rw-r--r--source/tests/win32/01-window/03_sub_menu.cpp85
1 files changed, 14 insertions, 71 deletions
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp
index 0a389b0..be22665 100644
--- a/source/tests/win32/01-window/03_sub_menu.cpp
+++ b/source/tests/win32/01-window/03_sub_menu.cpp
@@ -27,66 +27,27 @@ HWND wnd;
AEMath::Recti viewport;
-
-/*
-shader в
-* MVP matrix
-* position
-* UV
-* UV_0
-* UV_1
-* UV_2
-* UV_n
-* framework涨壬DZ༭ҪΪ༭ȾͼƬȾ
-* Asura Shader Semantics.
-*/
-string shader_frame = R"(
-//
-in vec2 asura_position;
-in vec2 asura_tangent;
-in vec2 asura_normal;
-in vec4 asura_color;
-// asura_texcoord(n)
-in vec2 asura_texcoord0;
-in vec2 asura_texcoord1;
-in vec2 asura_texcoord2;
-in vec2 asura_texcoord3;
-
-// uniform
-uniform mat4 asura_projection_matrix;
-uniform mat4 asura_model_matrix;
-uniform mat4 asura_view_matrix;
-
-uniform mat4 asura_draw_color;
-
-uniform int asura_layer; // 0~10000Ȳ
-
-uniform vec2 asura_time; // 뵱ǰʱǰ֡ļ
-
-)";
-
string vert = R"(
-in vec2 vertex;
-in vec2 vertUVs;
+in vec2 asura_position;
+in vec2 asura_texcoord0;
-uniform mat4 projMatrix;
-uniform mat4 modelMatrix;
-uniform mat4 viewMatrix;
+uniform mat4 asura_projection_matrix;
+uniform mat4 asura_model_matrix;
+uniform mat4 asura_view_matrix;
out vec2 texCoord;
void main()
{
- texCoord = vertUVs;
- gl_Position = projMatrix * viewMatrix * modelMatrix * vec4(vertex, 1, 1);
+ texCoord = asura_texcoord0;
+ gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1);
}
)";
string frag = R"(
-in vec2 texCoord;
+in vec2 texCoord;
uniform sampler2D img;
-uniform sampler2D img2;
void main()
{
gl_FragColor = texture2D(img, texCoord);
@@ -98,7 +59,7 @@ GPUBuffer* vb;
struct Vert
{
- float x, y; // coord
+ float x, y; // position
float s, t; // uv
};
@@ -184,37 +145,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //С˷ʽ
{
- int uvAttribLoc = shader->GetAttributeLocation("vertUVs");
- int vertAttribLoc = shader->GetAttributeLocation("vertex");
int imgLoc = shader->GetUniformLocation("img");
- int img2Loc = shader->GetUniformLocation("img2");
- int projmat = shader->GetUniformLocation("projMatrix");
- int mmat = shader->GetUniformLocation("modelMatrix");
- int vmat = shader->GetUniformLocation("viewMatrix");
int code = gl.GetError();
gl.UseShader(shader);
shader->SetUniformTexture(imgLoc, *img);
- shader->SetUniformTexture(img2Loc, *img);
gl.SetMatrixMode(MATRIX_MODE_PROJECTION);
- gl.PushMatrix();
gl.LoadIdentity();
gl.Ortho(0, viewport.w, viewport.h, 0, -1, 1);
- shader->SetUniformMatrix44(projmat, gl.GetMatrix(MATRIX_MODE_PROJECTION));
- gl.PopMatrix();
gl.SetMatrixMode(MATRIX_MODE_MODEL);
gl.LoadIdentity();
- gl.Translate(100, 10);
- shader->SetUniformMatrix44(mmat, gl.GetMatrix(MATRIX_MODE_MODEL));
- shader->SetUniformMatrix44(vmat, gl.GetMatrix(MATRIX_MODE_VIEW));
- vb->Bind();
- glVertexAttribPointer(vertAttribLoc, 2, GL_FLOAT, GL_FALSE, sizeof(Vert), 0);
- glVertexAttribPointer(uvAttribLoc, 2, GL_FLOAT, GL_FALSE, sizeof(Vert), (const void*)(2 * sizeof(float)));
- vb->UnBind();
- glEnableVertexAttribArray(vertAttribLoc);
- glEnableVertexAttribArray(uvAttribLoc);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glDisableVertexAttribArray(vertAttribLoc);
- glDisableVertexAttribArray(uvAttribLoc);
+ shader->SetBuiltInUniforms();
+ shader->SetAttribPosition(2, vb, 0, 4 * sizeof(float));
+ shader->SetAttribTexcoord0(2, vb, 2 * sizeof(float), 4 * sizeof(float));
+ gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
gl.UnuseShader();
}
glFlush();
@@ -278,7 +221,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
{ w, 0, 1, 0 },
{ w, h, 1, 1 },
};
- vb = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, sizeof(v));
+ vb = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, BUFFER_DATA_TYPE_FLOAT, sizeof(v));
vb->Fill(v, sizeof(v));
};