mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
[Misc] (All): Run format_code.sh
This commit is contained in:
@@ -8,13 +8,9 @@ using namespace MobileGL::MG_Impl::GLImpl;
|
||||
|
||||
class ProgramTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
}
|
||||
void SetUp() override { MG_State::pGLContext = new MG_State::GLState::GLContext(); }
|
||||
|
||||
void TearDown() override {
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
void TearDown() override { delete MG_State::pGLContext; }
|
||||
};
|
||||
|
||||
TEST_F(ProgramTest, Sanity) {
|
||||
@@ -94,7 +90,6 @@ void main() {
|
||||
fragColor = vec4(OutColor, float(intVal));
|
||||
})";
|
||||
|
||||
|
||||
TEST_F(ProgramTest, CompileVertex) {
|
||||
GLuint vs = CreateShader(GL_VERTEX_SHADER);
|
||||
ShaderSource(vs, 1, &vsSrc, NULL);
|
||||
@@ -215,32 +210,24 @@ TEST_F(ProgramTest, UniformMatrixFunctions) {
|
||||
// Test UniformMatrix2fv
|
||||
auto locProjMat = GetUniformLocation(program, "ProjMat");
|
||||
ASSERT_NE(locProjMat, -1);
|
||||
|
||||
|
||||
// 4x4 matrix (16 elements) - identity matrix
|
||||
GLfloat matrix4x4[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
GLfloat matrix4x4[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
// Test UniformMatrix4fv with count = 1 and transpose = GL_FALSE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_FALSE, matrix4x4);
|
||||
|
||||
|
||||
// Test UniformMatrix4fv with count = 1 and transpose = GL_TRUE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_TRUE, matrix4x4);
|
||||
|
||||
|
||||
// Test with a non-identity matrix
|
||||
GLfloat nonIdentityMatrix[16] = {
|
||||
1.0f, 2.0f, 3.0f, 4.0f,
|
||||
5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f,
|
||||
13.0f, 14.0f, 15.0f, 16.0f
|
||||
};
|
||||
|
||||
GLfloat nonIdentityMatrix[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f};
|
||||
|
||||
// Test with transpose = GL_FALSE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_FALSE, nonIdentityMatrix);
|
||||
|
||||
|
||||
// Test with transpose = GL_TRUE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_TRUE, nonIdentityMatrix);
|
||||
}
|
||||
@@ -288,8 +275,8 @@ TEST_F(ProgramTest, UniformMatrixTranspose) {
|
||||
// [1 3]
|
||||
// [2 4]
|
||||
GLfloat matrix2x2[4] = {
|
||||
1.0f, 2.0f, // First column
|
||||
3.0f, 4.0f // Second column
|
||||
1.0f, 2.0f, // First column
|
||||
3.0f, 4.0f // Second column
|
||||
};
|
||||
|
||||
// Expected values when transpose = GL_FALSE (no transpose):
|
||||
@@ -318,7 +305,7 @@ TEST_F(ProgramTest, UniformMatrixTranspose) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
EXPECT_FLOAT_EQ(result2x2_transpose[i], expected2x2_transpose[i]);
|
||||
}
|
||||
|
||||
|
||||
// Test 3x3 matrix transpose
|
||||
auto locMat3 = GetUniformLocation(program, "TestMat3");
|
||||
ASSERT_NE(locMat3, -1);
|
||||
@@ -327,9 +314,9 @@ TEST_F(ProgramTest, UniformMatrixTranspose) {
|
||||
// [2 5 8]
|
||||
// [3 6 9]
|
||||
GLfloat matrix3x3[9] = {
|
||||
1.0f, 2.0f, 3.0f, // First column
|
||||
4.0f, 5.0f, 6.0f, // Second column
|
||||
7.0f, 8.0f, 9.0f // Third column
|
||||
1.0f, 2.0f, 3.0f, // First column
|
||||
4.0f, 5.0f, 6.0f, // Second column
|
||||
7.0f, 8.0f, 9.0f // Third column
|
||||
};
|
||||
|
||||
// Expected values when transpose = GL_FALSE (no transpose):
|
||||
@@ -360,40 +347,40 @@ TEST_F(ProgramTest, UniformMatrixTranspose) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
EXPECT_FLOAT_EQ(result3x3_transpose[i], expected3x3_transpose[i]);
|
||||
}
|
||||
|
||||
|
||||
// Test 4x4 matrix transpose
|
||||
auto locProjMat = GetUniformLocation(program, "ProjMat");
|
||||
ASSERT_NE(locProjMat, -1);
|
||||
|
||||
|
||||
// Test matrix (column-major as expected by OpenGL):
|
||||
// [1 5 9 13]
|
||||
// [2 6 10 14]
|
||||
// [3 7 11 15]
|
||||
// [4 8 12 16]
|
||||
GLfloat matrix4x4[16] = {
|
||||
1.0f, 2.0f, 3.0f, 4.0f, // First column
|
||||
5.0f, 6.0f, 7.0f, 8.0f, // Second column
|
||||
9.0f, 10.0f, 11.0f, 12.0f, // Third column
|
||||
13.0f, 14.0f, 15.0f, 16.0f // Fourth column
|
||||
1.0f, 2.0f, 3.0f, 4.0f, // First column
|
||||
5.0f, 6.0f, 7.0f, 8.0f, // Second column
|
||||
9.0f, 10.0f, 11.0f, 12.0f, // Third column
|
||||
13.0f, 14.0f, 15.0f, 16.0f // Fourth column
|
||||
};
|
||||
|
||||
|
||||
// Expected values when transpose = GL_FALSE (no transpose):
|
||||
// [1 5 9 13]
|
||||
// [2 6 10 14]
|
||||
// [3 7 11 15]
|
||||
// [4 8 12 16]
|
||||
GLfloat expected4x4_no_transpose[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f};
|
||||
|
||||
GLfloat expected4x4_no_transpose[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f};
|
||||
|
||||
// Expected values when transpose = GL_TRUE (transposed):
|
||||
// [1 2 3 4]
|
||||
// [5 6 7 8]
|
||||
// [9 10 11 12]
|
||||
// [13 14 15 16]
|
||||
// Stored in column-major order
|
||||
GLfloat expected4x4_transpose[16] = {1.0f, 5.0f, 9.0f, 13.0f, 2.0f, 6.0f, 10.0f, 14.0f,
|
||||
3.0f, 7.0f, 11.0f, 15.0f, 4.0f, 8.0f, 12.0f, 16.0f};
|
||||
|
||||
GLfloat expected4x4_transpose[16] = {1.0f, 5.0f, 9.0f, 13.0f, 2.0f, 6.0f, 10.0f, 14.0f,
|
||||
3.0f, 7.0f, 11.0f, 15.0f, 4.0f, 8.0f, 12.0f, 16.0f};
|
||||
|
||||
// Test with transpose = GL_FALSE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_FALSE, matrix4x4);
|
||||
GLfloat result4x4_no_transpose[16];
|
||||
@@ -401,7 +388,7 @@ TEST_F(ProgramTest, UniformMatrixTranspose) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
EXPECT_FLOAT_EQ(result4x4_no_transpose[i], expected4x4_no_transpose[i]);
|
||||
}
|
||||
|
||||
|
||||
// Test with transpose = GL_TRUE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_TRUE, matrix4x4);
|
||||
GLfloat result4x4_transpose[16];
|
||||
@@ -444,29 +431,25 @@ TEST_F(ProgramTest, UniformLocationGaps) {
|
||||
// Test that uniform locations are correctly assigned even with gaps
|
||||
// ProjMat is at location 0
|
||||
ASSERT_EQ(GetUniformLocation(program, "ProjMat"), 0);
|
||||
|
||||
|
||||
// TestMat3 is at location 10 (gap from 1-9)
|
||||
ASSERT_EQ(GetUniformLocation(program, "TestMat3"), 10);
|
||||
|
||||
|
||||
// TestMat2 is at location 20 (gap from 11-19)
|
||||
ASSERT_EQ(GetUniformLocation(program, "TestMat2"), 20);
|
||||
|
||||
|
||||
// Gray is at location 1 (no gap)
|
||||
ASSERT_EQ(GetUniformLocation(program, "Gray"), 1);
|
||||
|
||||
|
||||
// Saturation is at location 6 (gap from 2-5)
|
||||
ASSERT_EQ(GetUniformLocation(program, "Saturation"), 6);
|
||||
|
||||
|
||||
// Verify that locations in gaps correctly return -1
|
||||
ASSERT_EQ(GetUniformLocation(program, "NonExistentUniform"), -1);
|
||||
|
||||
|
||||
// Test uniform operations on locations with gaps
|
||||
GLfloat matrix3[9] = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
GLfloat matrix3[9] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
// Test setting and getting uniform at location 10 (TestMat3)
|
||||
UniformMatrix3fv(10, 1, GL_FALSE, matrix3);
|
||||
GLfloat result[9];
|
||||
@@ -474,19 +457,16 @@ TEST_F(ProgramTest, UniformLocationGaps) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
EXPECT_FLOAT_EQ(result[i], matrix3[i]);
|
||||
}
|
||||
|
||||
|
||||
// Test setting and getting uniform at location 20 (TestMat2)
|
||||
GLfloat matrix2[4] = {
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f
|
||||
};
|
||||
GLfloat matrix2[4] = {1.0f, 0.0f, 0.0f, 1.0f};
|
||||
UniformMatrix2fv(20, 1, GL_FALSE, matrix2);
|
||||
GLfloat result2[4];
|
||||
GetUniformfv(program, 20, result2);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
EXPECT_FLOAT_EQ(result2[i], matrix2[i]);
|
||||
}
|
||||
|
||||
|
||||
// Test that accessing a gap location (e.g., 5) doesn't cause issues
|
||||
// This should not crash or cause undefined behavior
|
||||
Uniform1i(5, 114514); // Just to make sure we don't crash
|
||||
|
||||
Reference in New Issue
Block a user