cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

lukcho
Journeyman III

a bug with quering GL_BGRA vertex attributes

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;

}

0 Likes
2 Replies
gsellers
Staff

Hi,

Thanks for the report. Well written and concise - should be easy enough to find the problem if it's in the driver. Let us take a look at it and then I'll post back here with an update.

Graham

0 Likes

Thanx for the reply!

Here is a little more info: the returned size is 4 instead of GL_BGRA and the returned type is GL_BGRA instead of GL_UNSIGNED_BYTE

Then an easy workaround would be just to check if the returned type is GL_BGRA (it normally can never be this value) and if so conclude that the vertex attribute is actually in the special BGRA format.

0 Likes