Test reading instanced data via client memory pointers in GL

This commit is contained in:
baldurk
2020-07-29 15:17:45 +01:00
parent c8c281b503
commit d03acd3b6c
2 changed files with 52 additions and 2 deletions
+31 -2
View File
@@ -26,7 +26,8 @@
RD_TEST(GL_VAO_0, OpenGLGraphicsTest)
{
static constexpr const char *Description = "Uses VAO 0 (i.e. never binds a VAO)";
static constexpr const char *Description =
"Uses VAO 0 (i.e. never binds a VAO) as well as testing client memory pointer behaviour.";
std::string common = R"EOSHADER(
@@ -49,9 +50,11 @@ layout(location = 2) in vec2 UV;
out v2f vertOut;
uniform vec4 instance_xform;
void main()
{
vertOut.pos = vec4(Position.xyz, 1);
vertOut.pos = vec4(Position.x + float(gl_InstanceID % 4), Position.y + float(gl_InstanceID / 4), Position.z, 1) * vec4(instance_xform.xy, 1, 1);
gl_Position = vertOut.pos;
vertOut.col = Color;
vertOut.uv = vec4(UV.xy, 0, 1);
@@ -102,8 +105,14 @@ void main()
GLuint program = MakeProgram(common + vertex, common + pixel);
GLint loc = glGetUniformLocation(program, "instance_xform");
glEnable(GL_SCISSOR_TEST);
while(Running())
{
glScissor(0, 0, GLsizei(screenWidth), GLsizei(screenHeight));
float col[] = {0.2f, 0.2f, 0.2f, 1.0f};
glClearBufferfv(GL_COLOR, 0, col);
@@ -116,6 +125,8 @@ void main()
glUseProgram(program);
glUniform4f(loc, 1.0f, 1.0f, 0.0f, 0.0f);
// use both buffers
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib);
glBindBuffer(GL_ARRAY_BUFFER, vb);
@@ -150,6 +161,24 @@ void main()
glViewport((screenWidth * 3) / 4, 0, GLsizei(screenWidth) / 4, GLsizei(screenHeight));
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, idxs);
// draw with instance data that requires more data than a non-instanced stream would need
glViewport(0, 0, GLsizei(screenWidth) / 2, GLsizei(screenHeight) / 2);
glScissor(0, 0, GLsizei(screenWidth) / 2, GLsizei(screenHeight) / 2);
glClearBufferfv(GL_COLOR, 0, col);
Vec4f instcols[20] = {};
for(size_t i = 4; i < ARRAY_COUNT(instcols); i++)
instcols[i].z = 0.5f * (i - 3);
glUniform4f(loc, 0.25f, 0.25f, 0.0f, 0.0f);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vec4f), instcols);
glVertexAttribDivisor(1, 1);
glDrawElementsInstancedBaseInstance(GL_TRIANGLES, 3, GL_UNSIGNED_INT, idxs, 16, 4);
glVertexAttribDivisor(1, 0);
Present();
}
+21
View File
@@ -52,3 +52,24 @@ class GL_VAO_0(rdtest.TestCase):
draw = draw.next
draw = self.find_draw("Instanced")
self.check(draw is not None)
self.controller.SetFrameEvent(draw.eventId, False)
# Each instance should have color output of 0.5 * instance in blue
for i in range(0, draw.numInstances):
postvs_data = self.get_postvs(draw, rd.MeshDataStage.VSOut, 0, draw.numIndices, i)
postvs_ref = {
0: {
'vtx': 0,
'idx': 0,
'v2f_block.col': [0.0, 0.0, 0.5*(i+1), 0.0],
},
}
self.check_mesh_data(postvs_ref, postvs_data)
rdtest.log.success('Instance {} is OK'.format(i))