Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <GL/glew.h>
- #include <SDL2/SDL.h>
- static SDL_Window *win;
- static SDL_GLContext *ctx;
- void setupGL()
- {
- SDL_Init(SDL_INIT_VIDEO);
- win = SDL_CreateWindow("CopyBufferBug", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 64, 64, SDL_WINDOW_OPENGL);
- ctx = SDL_GL_CreateContext(win);
- glewInit();
- }
- static void teardownGL()
- {
- SDL_GL_DeleteContext(ctx);
- SDL_DestroyWindow(win);
- SDL_Quit();
- }
- int main(int argc, char *argv[])
- {
- setupGL();
- /* These don't matter I think */
- #define BLOCK_SIZE 128
- #define BUFFER1_SIZE BLOCK_SIZE
- #define BUFFER2_SIZE BLOCK_SIZE
- #define BUFFER1_TARGET GL_COPY_READ_BUFFER
- #define BUFFER2_TARGET GL_COPY_WRITE_BUFFER
- #define BUFFER1_USAGE GL_DYNAMIC_DRAW
- #define BUFFER2_USAGE GL_DYNAMIC_DRAW
- GLuint buffers[2];
- glGenBuffers(2, buffers);
- /* We allocate both buffers with undefined memory */
- glBindBuffer(BUFFER1_TARGET, buffers[0]);
- glBufferData(BUFFER1_TARGET, BUFFER1_SIZE, 0, BUFFER1_USAGE);
- glBindBuffer(BUFFER2_TARGET, buffers[1]);
- glBufferData(BUFFER2_TARGET, BUFFER2_SIZE, 0, BUFFER2_USAGE);
- /* Then copy (undefined) bytes from the first into the second buffer */
- /* Note: If I comment this line out, everything works */
- glCopyBufferSubData(BUFFER1_TARGET, BUFFER2_TARGET, 0, 0, BUFFER1_SIZE);
- /* Generate random string */
- FILE *rand = fopen("/dev/urandom", "r");
- char data[BLOCK_SIZE];
- fread(data, 1, sizeof(data), rand);
- fclose(rand);
- /* We fill the second buffer with defined data */
- /* Note: If I execute this call twice (just copy paste the line), everything works */
- glBufferSubData(BUFFER2_TARGET, 0, sizeof(data), data);
- /* Then download it again to compare its contents against client buffer */
- char data2[BLOCK_SIZE];
- glGetBufferSubData(BUFFER2_TARGET, 0, sizeof(data2), data2);
- if (memcmp(data, data2, sizeof(data)))
- printf("Data does NOT match up!\n");
- else
- printf("Data matches.\n");
- glDeleteBuffers(2, buffers);
- teardownGL();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement