cancel
Showing results for 
Search instead for 
Did you mean: 

OpenGL & Vulkan

einzuweitesfeld
Adept I

Integer vertex specification is cast from GLint to GLfloat

Jump to solution

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

0 Likes
Reply
1 Solution

Accepted Solutions
dorisyan
Staff
Staff

Re: Integer vertex specification is cast from GLint to GLfloat

Jump to solution

Hi einzuweitesfeld‌, here is some problem in the file 'Quelle1.cpp', when you try to pass the array of generic vertex attributes with type GL_INT, you should use glVertexAttribIPointer instead of glVertexAttribPointer, function 'glVertexAttribPointer' will convert the data from int to float. More details please refer to https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribPointer.xhtml

Thanks!

View solution in original post

0 Likes
Reply
3 Replies
dorisyan
Staff
Staff

Re: Integer vertex specification is cast from GLint to GLfloat

Jump to solution

Hi einzuweitesfeld‌, thanks for your report, and I will investigate it as soon as possible.

0 Likes
Reply
dorisyan
Staff
Staff

Re: Integer vertex specification is cast from GLint to GLfloat

Jump to solution

Hi einzuweitesfeld‌, here is some problem in the file 'Quelle1.cpp', when you try to pass the array of generic vertex attributes with type GL_INT, you should use glVertexAttribIPointer instead of glVertexAttribPointer, function 'glVertexAttribPointer' will convert the data from int to float. More details please refer to https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribPointer.xhtml

Thanks!

0 Likes
Reply
einzuweitesfeld
Adept I

Re: Integer vertex specification is cast from GLint to GLfloat

Jump to solution

Thanks for the clarification. It now works as expected.

That's really something I should have figured out myself. Sorry for stealing your time.

0 Likes
Reply