34 m_program=
read_program(
"gkit2_tutos/M2/read_buffer.glsl");
37 std::vector<int> data(1024);
39 glGenBuffers(1, &m_gpu_buffer1);
40 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_gpu_buffer1);
41 #ifdef USE_BUFFER_STORAGE
42 glBufferStorage(GL_SHADER_STORAGE_BUFFER,
sizeof(
int) * data.size(), data.data(), 0);
44 glBufferData(GL_SHADER_STORAGE_BUFFER,
sizeof(
int) * data.size(), data.data(), GL_STATIC_COPY);
47 glGenBuffers(1, &m_gpu_buffer2);
48 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_gpu_buffer2);
49 #ifdef USE_BUFFER_STORAGE
50 glBufferStorage(GL_SHADER_STORAGE_BUFFER,
sizeof(
int) * data.size(),
nullptr, 0);
52 glBufferData(GL_SHADER_STORAGE_BUFFER,
sizeof(
int) * data.size(),
nullptr, GL_STATIC_COPY);
55 glGenBuffers(1, &m_read_buffer);
56 glBindBuffer(GL_COPY_READ_BUFFER, m_read_buffer);
57 #ifdef USE_BUFFER_STORAGE
59 glBufferStorage(GL_COPY_READ_BUFFER,
sizeof(
int) * data.size(),
nullptr, GL_CLIENT_STORAGE_BIT | GL_MAP_READ_BIT);
61 glBufferStorage(GL_COPY_READ_BUFFER,
sizeof(
int) * data.size(),
nullptr, GL_CLIENT_STORAGE_BIT);
64 glBufferData(GL_COPY_READ_BUFFER,
sizeof(
int) * data.size(),
nullptr, GL_DYNAMIC_READ);
67 #ifdef USE_BUFFER_STORAGE
68 printf(
"!! use buffer storage\n");
70 printf(
"!! use buffer data\n");
88 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_gpu_buffer1);
89 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_gpu_buffer2);
92 glUseProgram(m_program);
93 glDispatchCompute(4, 1, 1);
96 glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
101 glBindBuffer(GL_COPY_READ_BUFFER, m_read_buffer);
102 glCopyBufferSubData(GL_SHADER_STORAGE_BUFFER, GL_COPY_READ_BUFFER, 0, 0,
sizeof(
int)*1024);
109 int *tmp= (
int *) glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
111 for(
unsigned i= 0; i < 1024; i++)
115 glUnmapBuffer(GL_COPY_READ_BUFFER);
119 printf(
"!! use get buffer\n");
121 std::vector<int> tmp(1024);
122 glGetBufferSubData(GL_COPY_READ_BUFFER, 0,
sizeof(
int) * tmp.size(), tmp.data());
123 for(
unsigned i= 0; i < tmp.size(); i++)
App(const int width, const int height, const int major=3, const int minor=3)
constructeur, dimensions de la fenetre et version d'openGL.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().