MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / initializeGL

Method initializeGL

compute/example/nbody.cpp:123–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123void NBodyWidget::initializeGL()
124{
125 // create context, command queue and program
126 m_context = compute::opengl_create_shared_context();
127 m_queue = compute::command_queue(m_context, m_context.get_device());
128 m_program = compute::program::create_with_source(source, m_context);
129 m_program.build();
130
131 // prepare random particle positions that will be transferred to the vbo
132 float4_* temp = new float4_[m_particles];
133 boost::random::uniform_real_distribution<float> dist(-0.5f, 0.5f);
134 boost::random::mt19937_64 gen;
135 for(size_t i = 0; i < m_particles; i++) {
136 temp[i][0] = dist(gen);
137 temp[i][1] = dist(gen);
138 temp[i][2] = dist(gen);
139 temp[i][3] = 1.0f;
140 }
141
142 // create an OpenGL vbo
143 GLuint vbo = 0;
144 glGenBuffers(1, &vbo);
145 glBindBuffer(GL_ARRAY_BUFFER, vbo);
146 glBufferData(GL_ARRAY_BUFFER, m_particles*sizeof(float4_), temp, GL_DYNAMIC_DRAW);
147
148 // create a OpenCL buffer from the vbo
149 m_position = compute::opengl_buffer(m_context, vbo);
150 delete[] temp;
151
152 // create buffer for velocities
153 m_velocity = new compute::vector<float4_>(m_particles, m_context);
154 compute::fill(m_velocity->begin(), m_velocity->end(), float4_(0.0f, 0.0f, 0.0f, 0.0f), m_queue);
155
156 // create compute kernels
157 m_velocity_kernel = m_program.create_kernel("updateVelocity");
158 m_velocity_kernel.set_arg(0, m_position);
159 m_velocity_kernel.set_arg(1, m_velocity->get_buffer());
160 m_velocity_kernel.set_arg(2, m_dt);
161 m_velocity_kernel.set_arg(3, m_particles);
162 m_position_kernel = m_program.create_kernel("updatePosition");
163 m_position_kernel.set_arg(0, m_position);
164 m_position_kernel.set_arg(1, m_velocity->get_buffer());
165 m_position_kernel.set_arg(2, m_dt);
166}
167void NBodyWidget::resizeGL(int width, int height)
168{
169 // update viewport

Callers

nothing calls this directly

Calls 10

opengl_bufferClass · 0.85
buildMethod · 0.80
create_kernelMethod · 0.80
command_queueClass · 0.50
fillFunction · 0.50
get_deviceMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
set_argMethod · 0.45

Tested by

no test coverage detected