0

I was trying to use the following vertex format:

attribute 0, GL_UNSIGNED_SHORT, size 1, offset 0, stride 8;
attribute 1, GL_UNSIGNED_SHORT, size 1, offset 2, stride 8;
attribute 2, GL_UNSIGNED_BYTE,  size 2, offset 4, stride 8, normalized;
attribute 3, GL_UNSIGNED_SHORT, size 1, offset 6, stride 8.

It works on a NVIDIA card, but when ran on an AMD card, the vertices get broken (mutant models appearing). No OpenGL error is given, and works without problems when changed to the following format:

attribute 0, GL_FLOAT, size 3, offset 0,  stride 36;
attribute 1, GL_FLOAT, size 3, offset 12, stride 36;
attribute 2, GL_FLOAT, size 3, offset 24, stride 36.

OR (packing all attributes into one)

attribute 0, GL_UNSIGNED_SHORT, size 4, offset 0, stride 8.

The in-vertex shader definition for the first vertex format is:

#version 330 

layout ( location = 0 ) in float in_vsAttrib0;
layout ( location = 1 ) in float in_vsAttrib1;
layout ( location = 2 ) in vec2  in_vsAttrib2;
layout ( location = 3 ) in float in_vsAttrib3;

Have I missed something in the OpenGL specification about this, or could it be a driver issue?

iH8
  • 27,722
  • 4
  • 67
  • 76
  • 1) Can you please also tell us what your vertex data looks like. Seperate buffers, packed buffer it makes a difference 2) Shorts and bytes are integer values where your shader expects floating point values. 3) How do you plan to normalize a integer value? 4) You don't set attribute 3 in the second block making it undefined and you don't set attribute 1 to 3 in block 3 also undefined. 5) Perhaps you should read the specification : http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml – Xonar Dec 23 '13 at 19:58
  • @Xonar: 3) fixed-point normalization --> For an unsigned byte value, the scale is 1.0/255.0 and bias is 0.0. So for example, given a value of **255**: 255 * 1.0/255.0 + 0.0 = **1.0** (the value GLSL will use). If the normalized flag is turned off, then GLSL effectively just casts the integer data type to floating-point without any fixed-point range adjustment. – Andon M. Coleman Dec 23 '13 at 20:07
  • @AndonM.Coleman Thanks for correcting me. After re-reading the specification I see my mistake. – Xonar Dec 24 '13 at 05:47
  • @Xonar: 1) It looks like the first specified vertex format, single buffer. Would work with separate buffers (from experience), but I need to keep the upload as simple and bandwidth friendly as possible. 2) Even if shader expects floating point values, OpenGL will convert them on the fly (optionally normalize in their respective integer range). 4) It is just an alternate vertex format I might use (by applying changes to the shaders as well), but it is way too big (36 bytes, instead of 8). 5) I've read it and it doesn't say that a graphics adapter may not support any of these formats. – user1919664 Dec 27 '13 at 12:38
  • @user1919664 1) If it looks like you specified then it should work. You have gaps in your data, are you sure your data is packed like that? Shorts are two bytes and a byte is one byte. Your types specify that you need 7 bytes storage, but your total is only 5. So how does your original data look? 2) Yes, but that's seldom what you want to do, unless you'll always have integer values. 4) You usually don't want to be pushing lots of data to the gpu realtime (Upload once, use often, but there are cases that that won't work). – Xonar Dec 27 '13 at 13:07
  • 1) I have no gaps in my data. It is packed correctly. It is not 7 bytes, it is 8, as the 3rd attribute is of size 2 (2 components, each one byte). The original data is a structure exactly of this format. 4) That's exactly what I am doing. I packed my data to the smallest possible structure, instead of using floating points all around, at the cost of unpacking them in the vertex shader, which is negligible. – user1919664 Dec 28 '13 at 17:54
  • Have you checked what data is actually being used in your vertex shader. Simply draw to a transformation buffer and check in both cases. Also make sure that you are using updated graphics drivers. – Xonar Dec 31 '13 at 10:43

0 Answers0