AnsweredAssumed Answered

a bug with quering GL_BGRA vertex attributes

Question asked by lukcho on Jun 18, 2012
Latest reply on Jun 19, 2012 by lukcho

the special vertex attribute format with size=GL_BGRA, type=GL_UNSIGNED_BYTE, normalized=GL_TRUE works fine but

when queried about the size and the type the driver returns wrong info

 

here is simple win32-based code to demonstrate the bug:

 

 

#include <string.h>

#include <windows.h>

#include <GL/gl.h>

#include "glext.h"

 

void get_vertex_attrib_bgra_test()

{

GLuint buf;

GLint size;

GLenum type;

 

PFNGLGETVERTEXATTRIBIVPROC _glGetVertexAttribiv;

PFNGLVERTEXATTRIBPOINTERPROC _glVertexAttribPointer;

PFNGLGENBUFFERSPROC _glGenBuffers;

PFNGLBINDBUFFERPROC _glBindBuffer;

PFNGLBUFFERDATAPROC _glBufferData;

 

*(PROC *)&_glGetVertexAttribiv = wglGetProcAddress("glGetVertexAttribiv");

*(PROC *)&_glVertexAttribPointer = wglGetProcAddress("glVertexAttribPointer");

*(PROC *)&_glGenBuffers = wglGetProcAddress("glGenBuffers");

*(PROC *)&_glBindBuffer = wglGetProcAddress("glBindBuffer");

*(PROC *)&_glBufferData = wglGetProcAddress("glBufferData");

 

_glGenBuffers(1, &buf);

_glBindBuffer(GL_ARRAY_BUFFER, buf);

_glVertexAttribPointer(0, GL_BGRA, GL_UNSIGNED_BYTE, GL_TRUE, 16, NULL);

 

_glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size);

_glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type);

 

// check to see that according to the driver there is no error

if (glGetError()) _asm int 3

 

// but the driver returns incorrect data!

if (size != GL_BGRA || type != GL_UNSIGNED_BYTE) _asm int 3

}

 

LRESULT CALLBACK wnd_proc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)

{

switch (msg) {

case WM_NCCREATE: return 1;

case WM_PAINT: ValidateRect(wnd, NULL);

default: return 0;

}

}

 

int CALLBACK WinMain(HINSTANCE inst, HINSTANCE prev_inst, char *cl, int cs)

{

WNDCLASSA wc;

HWND wnd;

HDC dc;

PIXELFORMATDESCRIPTOR pfd;

int pf;

HGLRC rc;

 

memset(&wc, 0, sizeof(wc));

wc.hInstance = inst;

wc.lpfnWndProc = wnd_proc;

wc.lpszClassName = "_test_class_name";

RegisterClassA(&wc);

wnd = CreateWindowExA(0, wc.lpszClassName, NULL, WS_POPUP, 0, 0, 64, 32, NULL, NULL, NULL, NULL);

dc = GetDC(wnd);

memset(&pfd, 0, sizeof(pfd));

pfd.nSize = sizeof(pfd);

pfd.nVersion = 1;

pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DEPTH_DONTCARE;

pf = ChoosePixelFormat(dc, &pfd);

SetPixelFormat(dc, pf, NULL);

rc = wglCreateContext(dc);

wglMakeCurrent(dc, rc);

 

get_vertex_attrib_bgra_test();

 

return 0;

}

Outcomes