Skip to content

Commit

Permalink
Basic tests for non-zero UNPACK_ROW_LENGTH and glTexImage?D APIs
Browse files Browse the repository at this point in the history
Covers:
glTexImage1D
glTexImage2D
glTexImage3D
  • Loading branch information
Zorro666 committed Nov 6, 2023
1 parent 37fe6e0 commit cf004e8
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions util/test/demos/gl/gl_texture_zoo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ void main()
GLuint tex;
};

struct TexImageTestCase
{
TestCase base;
TexData data;
Vec4i dimensions;
};

std::string MakeName(const TestCase &test)
{
std::string name = "Texture " + std::to_string(test.dim) + "D";
Expand Down Expand Up @@ -760,6 +767,7 @@ void main()
}

std::vector<TestCase> test_textures;
std::vector<TexImageTestCase> test_teximage_textures;

const GLFormat color_tests[] = {
TEST_CASE(TextureType::Regular, GL_RGBA32F, 4, 4, DataType::Float),
Expand Down Expand Up @@ -905,6 +913,66 @@ void main()
FinaliseTest(t);
}
}
const GLFormat teximage_test = TEST_CASE(TextureType::Regular, GL_RGBA8, 4, 1, DataType::UNorm);
TestCase tests[] = {
{teximage_test, GL_TEXTURE_1D, 1, false},
{teximage_test, GL_TEXTURE_2D, 2, false},
{teximage_test, GL_TEXTURE_3D, 3, false},
};
for(TestCase test : tests)
{
if(QueryFormatBool(test.target, test.fmt.internalFormat, GL_INTERNALFORMAT_SUPPORTED) &&
QueryFormatBool(test.target, test.fmt.internalFormat, GL_FRAGMENT_TEXTURE))
{
test.isMSAA = false;
test.isRect = false;
test.isCube = false;
test.canRender = false;
test.canDepth = false;
test.canStencil = false;

test.tex = MakeTexture();
glBindTexture(test.target, test.tex);
glTexParameteri(test.target, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri(test.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(test.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Vec4i dimensions(texWidth, texHeight, texDepth);

if(test.dim == 1)
dimensions.y = dimensions.z = 1;
else if(test.dim == 2)
dimensions.z = 1;

glObjectLabel(GL_TEXTURE, test.tex, -1, (MakeName(test) + " " + test.fmt.name).c_str());

GLint m = 0;
GLint s = 0;
TexData packed_data;
MakeData(packed_data, test.fmt.cfg, dimensions, m, s);

uint32_t mipHeight = dimensions.y;
uint32_t mipDepth = dimensions.z;

const uint32_t rowLengthMultiplier = 2;

TexData data;
data.rowPitch = packed_data.rowPitch * rowLengthMultiplier;
data.slicePitch = packed_data.slicePitch * rowLengthMultiplier;
data.byteData.resize(packed_data.byteData.size() * rowLengthMultiplier);
for(uint32_t z = 0; z < mipDepth; ++z)
{
for(uint32_t y = 0; y < mipHeight; ++y)
{
memcpy(&data.byteData[z * data.slicePitch + y * data.rowPitch],
&packed_data.byteData[z * packed_data.slicePitch + y * packed_data.rowPitch],
packed_data.rowPitch);
}
}
test.hasData = !data.byteData.empty();
test_teximage_textures.push_back({test, data, dimensions});
}
}

popMarker();

Expand Down Expand Up @@ -1167,6 +1235,60 @@ void main()
// pop the last format region
popMarker();

pushMarker("TexImage tests");
for(TexImageTestCase &test : test_teximage_textures)
{
if(test.base.hasData && test.base.tex)
{
setMarker(MakeName(test.base));
glBindTexture(test.base.target, test.base.tex);
// ROW_LENGTH is in pixels not bytes
glPixelStorei(GL_UNPACK_ROW_LENGTH, test.data.rowPitch / test.base.fmt.cfg.componentCount);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);

uint32_t mipWidth = test.dimensions.x;
uint32_t mipHeight = test.dimensions.y;
uint32_t mipDepth = test.dimensions.z;
GLenum format = GL_RGBA;
GLenum type = GL_UNSIGNED_BYTE;
GLint border = 0;
GLint mip = 0;
if(test.base.dim == 1)
{
glTexImage1D(test.base.target, mip, test.base.fmt.internalFormat, mipWidth, border,
format, type, test.data.byteData.data());
}
else if(test.base.dim == 2)
{
glTexImage2D(test.base.target, mip, test.base.fmt.internalFormat, mipWidth, mipHeight,
border, format, type, test.data.byteData.data());
}
else if(test.base.dim == 3)
{
glTexImage3D(test.base.target, mip, test.base.fmt.internalFormat, mipWidth, mipHeight,
mipDepth, border, format, type, test.data.byteData.data());
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

glViewport(viewX, viewY, 10, 10);
glScissor(viewX + 1, viewY + 1, 8, 8);

glUseProgram(GetProgram(test.base));

glBindTextureUnit(0, test.base.tex);
glDrawArrays(GL_TRIANGLES, 0, 3);

viewX += 10;
if(viewX + 10 > (float)screenWidth)
{
viewX = 0;
viewY -= 10;
}
}
}
popMarker();

glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight));
glDisable(GL_SCISSOR_TEST);

Expand Down

0 comments on commit cf004e8

Please sign in to comment.