AnsweredAssumed Answered

Integer vertex specification is cast from GLint to GLfloat

Question asked by einzuweitesfeld on Apr 30, 2019
Latest reply on May 14, 2019 by einzuweitesfeld

I'm trying to render a quad (two triangles) on screen with the vertex array buffer data of type GLint (typedef'd to an int32_t on my system) but the data I get in the vertex shader is as if the GLint had been cast to GLfloat.

The specific part of code where I provide the vertex data reads:

  glGenVertexArrays(1, &g_quadVA);
  glBindVertexArray(g_quadVA);

  //Vertizes
  glGenBuffers(1, &g_quadVBO);
  glBindBuffer(GL_ARRAY_BUFFER, g_quadVBO);
  glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLint), g_quad_vertex_buffer_data, GL_STATIC_DRAW);

  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 0, NULL);

  //Indizes
  glGenBuffers(1, &g_quadIBO);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_quadIBO);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(GLuint), g_quadindices, GL_STATIC_DRAW);

As you can see, I'm specifying the vertex array number 0 with type GL_INT (g_quad_vertex_buffer_data is an GLint array). In the Vertex Shader I'm also using

layout(location = 0)         in  ivec2 eingKnoten;

i.e. I define the vertex input as type ivec2. The data I get when reading eingKnoten.x in the VS isn't the integer I specify in the application though but rather bit for bit the value of (GLfloat)g_quad_vertex_buffer_data[#] i.e. a floating point number.

My question is: Am I missing something? Is glVertexAttribPointer(.., GL_INT, ..)  and in ivec2 eingKnoten all that's needed to do when using integer vertex data?

 

I've attached a small test case that illustrates my question. It's a VS 2015 project where the main code is in Quelle1.cpp and the shaders are Shaders/test.{frag, vert}

On my system it renders a small, red rectangle.

 

My operatnig system is Windows 7 64bit, my card is an RX480 with the following driver:

 

Radeon Settings Version - 2019.0326.2353.42986
View Release Notes - https://www.amd.com/en/support/kb/release-notes/rn-rad-win-19-4-1
Driver Packaging Version - 18.50.31.01-190326a-340999C-RadeonSoftwareAdrenalin2019
Provider - Advanced Micro Devices, Inc.
2D Driver Version - 8.1.1.1634
Direct3D® Version - 9.14.10.01377
OpenGL® Version - 25.20.15000.13547
OpenCL™ Version - 10.0.2766.5
AMD Audio Driver Version - 7.12.0.7728
Vulkan™ Driver Version - 2.0.78
Vulkan™ API Version - 1.1.101

Attachments

Outcomes