//This example uses/needs: //ARB_buffer_storage (core in 4.4) //glCopyBufferSubData (core in 3.1) #include //#define GL_GLEXT_PROTOTYPES #include #include using namespace std; SDL_GLContext glRenderContext; SDL_Window *mainWindow; extern "C" typedef void (*PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint * buffers); extern "C" typedef void (*PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint * buffers); extern "C" typedef void (*PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); extern "C" typedef void (*PFNGLBUFFERSTORAGEPROC) (GLenum target, GLsizeiptr size, const void * data, GLbitfield flags); extern "C" typedef void (*PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); static PFNGLGENBUFFERSARBPROC glGenBuffers; static PFNGLDELETEBUFFERSPROC glDeleteBuffers; static PFNGLBINDBUFFERPROC glBindBuffer; static PFNGLBUFFERSTORAGEPROC glBufferStorage; static PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData; int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) { cout << "Unable to initialize SDL: " << SDL_GetError() << endl; return -1; } mainWindow = SDL_CreateWindow( "An SDL2 window", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position 300, // width, in pixels 300, // height, in pixels SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE// | SDL_WINDOW_FULLSCREEN ); if (!mainWindow) { cout << "Error in SDL_CreateWindow: " << SDL_GetError() << endl; return -1; } //mesa/radeonsi only supports GL3.3 in Core SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, GL_CONTEXT_FLAG_DEBUG_BIT); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); glRenderContext = SDL_GL_CreateContext(mainWindow); if (!glRenderContext) { cout << "Error in SDL_GL_CreateContext: " << SDL_GetError() << endl; return -1; } SDL_GL_SetSwapInterval(1); glGenBuffers = reinterpret_cast( SDL_GL_GetProcAddress("glGenBuffers")); glDeleteBuffers = reinterpret_cast( SDL_GL_GetProcAddress("glDeleteBuffers")); glBindBuffer = reinterpret_cast( SDL_GL_GetProcAddress("glBindBuffer")); glBufferStorage = reinterpret_cast( SDL_GL_GetProcAddress("glBufferStorage")); glCopyBufferSubData = reinterpret_cast( SDL_GL_GetProcAddress("glCopyBufferSubData")); int bufferSize = 200 * 1024 * 1024; GLuint clientBufferId, serverBufferId; glGenBuffers(1, &clientBufferId); glBindBuffer(GL_ARRAY_BUFFER, clientBufferId); glBufferStorage(GL_ARRAY_BUFFER, bufferSize, 0, 0); glGenBuffers(1, &serverBufferId); glBindBuffer(GL_ARRAY_BUFFER, serverBufferId); glBufferStorage(GL_ARRAY_BUFFER, bufferSize, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_COPY_READ_BUFFER, clientBufferId); glBindBuffer(GL_COPY_WRITE_BUFFER, serverBufferId); glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, bufferSize); glDeleteBuffers(1, &clientBufferId); glDeleteBuffers(1, &serverBufferId); SDL_GL_DeleteContext(glRenderContext); SDL_DestroyWindow(mainWindow); SDL_Quit(); return 0; }