Hello,
I'm using xorg-edgers' packages on Ubuntu Jaunty, so I have equivalent
of mesa 7.5 from git (intel 945GM), up to date.
Recently (but unfortunately I can't tell exactly when), some of my own
OpenGL programs using VBOs and glMapBuffer broke. I'm not sure if it's a
bug of the intel DRI driver or a misuse of glMapBuffer, so I first ask
on the list before possibly filling a bug report.
I'm attaching a little OpenGL program showing the problem. It displays a
rotating cube. When using glMapBuffer/memcpy/glUnmapBuffer, it works for
the first frame and crashes for the next one. If I use glBufferData it
works fine.
Is it expected, or is it a bug?
Note that it works with LIBGL_ALWAYS_SOFTWARE=1. It worked before too
(Mesa 7.4). It crashes with linux 2.6.30 as well as 2.6.28, both KMS and
UMS tested.
Yours,
David HENRY.
/*
* gcc -Wall -ansi -lGL -lGLU -lGLEW -lglut vbo.c -o vbo
*/
#include <GL/glew.h>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct VN_t
{
GLfloat v[3]; /* position */
GLfloat n[3]; /* normal */
};
static struct VN_t cube[24] = {
{ { 0.0, 0.0, 0.0 }, { 0.0, 0.0, -1.0 } },
{ { 0.0, 1.0, 0.0 }, { 0.0, 0.0, -1.0 } },
{ { 1.0, 1.0, 0.0 }, { 0.0, 0.0, -1.0 } },
{ { 1.0, 0.0, 0.0 }, { 0.0, 0.0, -1.0 } },
{ { 0.0, 0.0, 1.0 }, { 0.0, 0.0, 1.0 } },
{ { 1.0, 0.0, 1.0 }, { 0.0, 0.0, 1.0 } },
{ { 1.0, 1.0, 1.0 }, { 0.0, 0.0, 1.0 } },
{ { 0.0, 1.0, 1.0 }, { 0.0, 0.0, 1.0 } },
{ { 1.0, 0.0, 1.0 }, { 1.0, 0.0, 0.0 } },
{ { 1.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } },
{ { 1.0, 1.0, 0.0 }, { 1.0, 0.0, 0.0 } },
{ { 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0 } },
{ { 0.0, 0.0, 1.0 }, { -1.0, 0.0, 0.0 } },
{ { 0.0, 1.0, 1.0 }, { -1.0, 0.0, 0.0 } },
{ { 0.0, 1.0, 0.0 }, { -1.0, 0.0, 0.0 } },
{ { 0.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 } },
{ { 0.0, 1.0, 1.0 }, { 0.0, 1.0, 0.0 } },
{ { 1.0, 1.0, 1.0 }, { 0.0, 1.0, 0.0 } },
{ { 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 } },
{ { 0.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 } },
{ { 0.0, 0.0, 1.0 }, { 0.0, -1.0, 0.0 } },
{ { 0.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 } },
{ { 1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 } },
{ { 1.0, 0.0, 1.0 }, { 0.0, -1.0, 0.0 } },
};
static GLushort indices[24] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
};
GLuint vboId = 0;
GLuint iboId = 0;
static void
init ()
{
GLenum err = glewInit ();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf (stderr, "Error: %s\n", glewGetErrorString (err));
exit (EXIT_FAILURE);
}
if (!GLEW_ARB_vertex_buffer_object)
{
fprintf (stderr, "Error: missing ARB_vertex_buffer_object extension\n");
exit (EXIT_FAILURE);
}
/* OpenGL initialization */
glClearColor (0.1f, 0.1f, 0.1f, 0.0f);
glShadeModel (GL_SMOOTH);
glEnable (GL_CULL_FACE);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
/* VBO setup */
glGenBuffersARB (1, &vboId);
glGenBuffersARB (1, &iboId);
glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER, iboId);
glBufferDataARB (GL_ELEMENT_ARRAY_BUFFER, 24 * sizeof (GLushort), &indices, GL_STATIC_DRAW);
glBindBufferARB (GL_ARRAY_BUFFER, vboId);
glBufferDataARB (GL_ARRAY_BUFFER, 24 * sizeof (struct VN_t), NULL, GL_STREAM_DRAW_ARB);
glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBufferARB (GL_ARRAY_BUFFER, 0);
}
static void
reshape (int w, int h)
{
if (h == 0)
h = 1;
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45.0, (GLfloat)w/(GLfloat)h, 0.1, 1000.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glutPostRedisplay ();
}
static void
display ()
{
GLenum err;
struct VN_t *v;
static float angle = 25.0;
static int frame = 1;
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Camera setup */
glLoadIdentity ();
glTranslated (0.0f, 0.0f, -3.0f);
glRotated (35.0f, 1.0f, 0.0f, 0.0f);
glRotated (angle, 0.0f, 1.0f, 0.0f);
glTranslatef (-0.5f, -0.5f, -0.5f);
angle += 0.2;
glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER, iboId);
glBindBufferARB (GL_ARRAY_BUFFER, vboId);
if (0)
{
/*glBufferSubDataARB (GL_ARRAY_BUFFER, 0, 24 * sizeof (struct vertex), &cube);*/
glBufferDataARB (GL_ARRAY_BUFFER, 24 * sizeof (struct VN_t), &cube, GL_STREAM_DRAW_ARB);
}
else
{
/*glBufferDataARB (GL_ARRAY_BUFFER, 24 * sizeof (struct vertex), NULL, GL_STREAM_DRAW_ARB);*/
v = (struct VN_t *)glMapBufferARB (GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
memcpy (v, &cube, sizeof (cube));
glUnmapBufferARB (GL_ARRAY_BUFFER_ARB);
}
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, sizeof (struct VN_t), (char *)(sizeof (GLfloat) * 3));
glVertexPointer (3, GL_FLOAT, sizeof (struct VN_t), 0);
glDrawElements (GL_QUADS, 24, GL_UNSIGNED_SHORT, 0);
glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBufferARB (GL_ARRAY_BUFFER, 0);
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_NORMAL_ARRAY);
err = glGetError ();
if (err != GL_NO_ERROR)
fprintf (stderr, "OpenGL error: %s\n", gluErrorString (err));
printf ("frame %i\n", frame++);
glutSwapBuffers ();
glutPostRedisplay ();
}
static void
keyPress (unsigned char key, int x, int y)
{
/* Escape */
if (key == 27)
exit (0);
glutPostRedisplay ();
}
int
main (int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (640, 480);
glutCreateWindow ("VBO demo");
init ();
glutReshapeFunc (reshape);
glutDisplayFunc (display);
glutKeyboardFunc (keyPress);
glutMainLoop ();
return 0;
}
------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel