trunk/3rdparty/bgfx/examples/24-nbody/nbody.cpp
r245332 | r245333 | |
117 | 117 | , 0 |
118 | 118 | ); |
119 | 119 | |
120 | | const bgfx::Caps* caps = bgfx::getCaps(); |
121 | | const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE); |
| 120 | // Imgui. |
| 121 | imguiCreate(); |
122 | 122 | |
123 | | if (computeSupported) |
124 | | { |
125 | | // Imgui. |
126 | | imguiCreate(); |
| 123 | bgfx::VertexDecl quadVertexDecl; |
| 124 | quadVertexDecl.begin() |
| 125 | .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) |
| 126 | .end(); |
127 | 127 | |
128 | | bgfx::VertexDecl quadVertexDecl; |
129 | | quadVertexDecl.begin() |
130 | | .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) |
131 | | .end(); |
| 128 | // Create static vertex buffer. |
| 129 | bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer( |
| 130 | // Static data can be passed with bgfx::makeRef |
| 131 | bgfx::makeRef(s_quadVertices, sizeof(s_quadVertices) ) |
| 132 | , quadVertexDecl |
| 133 | ); |
132 | 134 | |
133 | | // Create static vertex buffer. |
134 | | bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer( |
135 | | // Static data can be passed with bgfx::makeRef |
136 | | bgfx::makeRef(s_quadVertices, sizeof(s_quadVertices) ) |
137 | | , quadVertexDecl |
138 | | ); |
| 135 | // Create static index buffer. |
| 136 | bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer( |
| 137 | // Static data can be passed with bgfx::makeRef |
| 138 | bgfx::makeRef(s_quadIndices, sizeof(s_quadIndices) ) |
| 139 | ); |
139 | 140 | |
140 | | // Create static index buffer. |
141 | | bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer( |
142 | | // Static data can be passed with bgfx::makeRef |
143 | | bgfx::makeRef(s_quadIndices, sizeof(s_quadIndices) ) |
144 | | ); |
| 141 | // Create particle program from shaders. |
| 142 | bgfx::ProgramHandle particleProgram = loadProgram("vs_particle", "fs_particle"); |
145 | 143 | |
146 | | // Create particle program from shaders. |
147 | | bgfx::ProgramHandle particleProgram = loadProgram("vs_particle", "fs_particle"); |
| 144 | // Setup compute buffers |
| 145 | bgfx::VertexDecl computeVertexDecl; |
| 146 | computeVertexDecl.begin() |
| 147 | .add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float) |
| 148 | .end(); |
148 | 149 | |
149 | | // Setup compute buffers |
150 | | bgfx::VertexDecl computeVertexDecl; |
151 | | computeVertexDecl.begin() |
152 | | .add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float) |
153 | | .end(); |
| 150 | const uint32_t threadGroupUpdateSize = 512; |
| 151 | const uint32_t maxParticleCount = 32 * 1024; |
154 | 152 | |
155 | | const uint32_t threadGroupUpdateSize = 512; |
156 | | const uint32_t maxParticleCount = 32 * 1024; |
| 153 | bgfx::DynamicVertexBufferHandle currPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
| 154 | bgfx::DynamicVertexBufferHandle currPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
| 155 | bgfx::DynamicVertexBufferHandle prevPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
| 156 | bgfx::DynamicVertexBufferHandle prevPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
157 | 157 | |
158 | | bgfx::DynamicVertexBufferHandle currPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
159 | | bgfx::DynamicVertexBufferHandle currPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
160 | | bgfx::DynamicVertexBufferHandle prevPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
161 | | bgfx::DynamicVertexBufferHandle prevPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); |
| 158 | bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv, 3); |
162 | 159 | |
163 | | bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv, 3); |
| 160 | bgfx::ShaderHandle initInstancesShader = loadShader("cs_init_instances"); |
| 161 | bgfx::ProgramHandle initInstancesProgram = bgfx::createProgram(initInstancesShader, true); |
| 162 | bgfx::ShaderHandle updateInstancesShader = loadShader("cs_update_instances"); |
| 163 | bgfx::ProgramHandle updateInstancesProgram = bgfx::createProgram(updateInstancesShader, true); |
164 | 164 | |
165 | | bgfx::ShaderHandle initInstancesShader = loadShader("cs_init_instances"); |
166 | | bgfx::ProgramHandle initInstancesProgram = bgfx::createProgram(initInstancesShader, true); |
167 | | bgfx::ShaderHandle updateInstancesShader = loadShader("cs_update_instances"); |
168 | | bgfx::ProgramHandle updateInstancesProgram = bgfx::createProgram(updateInstancesShader, true); |
| 165 | u_paramsDataStruct u_paramsData; |
| 166 | InitializeParams(0, &u_paramsData); |
169 | 167 | |
170 | | u_paramsDataStruct u_paramsData; |
171 | | InitializeParams(0, &u_paramsData); |
| 168 | bgfx::setUniform(u_params, &u_paramsData, 3); |
| 169 | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); |
| 170 | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write); |
| 171 | bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); |
172 | 172 | |
173 | | bgfx::setUniform(u_params, &u_paramsData, 3); |
174 | | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); |
175 | | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write); |
176 | | bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); |
| 173 | float view[16]; |
| 174 | float initialPos[3] = { 0.0f, 0.0f, -45.0f }; |
| 175 | cameraCreate(); |
| 176 | cameraSetPosition(initialPos); |
| 177 | cameraSetVerticalAngle(0.0f); |
| 178 | cameraGetViewMtx(view); |
177 | 179 | |
178 | | float view[16]; |
179 | | float initialPos[3] = { 0.0f, 0.0f, -45.0f }; |
180 | | cameraCreate(); |
181 | | cameraSetPosition(initialPos); |
182 | | cameraSetVerticalAngle(0.0f); |
183 | | cameraGetViewMtx(view); |
| 180 | int32_t scrollArea = 0; |
184 | 181 | |
185 | | int32_t scrollArea = 0; |
| 182 | entry::MouseState mouseState; |
| 183 | while (!entry::processEvents(width, height, debug, reset, &mouseState) ) |
| 184 | { |
| 185 | int64_t now = bx::getHPCounter(); |
| 186 | static int64_t last = now; |
| 187 | const int64_t frameTime = now - last; |
| 188 | last = now; |
| 189 | const double freq = double(bx::getHPFrequency() ); |
| 190 | const float deltaTime = float(frameTime/freq); |
186 | 191 | |
187 | | entry::MouseState mouseState; |
188 | | while (!entry::processEvents(width, height, debug, reset, &mouseState) ) |
189 | | { |
190 | | int64_t now = bx::getHPCounter(); |
191 | | static int64_t last = now; |
192 | | const int64_t frameTime = now - last; |
193 | | last = now; |
194 | | const double freq = double(bx::getHPFrequency() ); |
195 | | const float deltaTime = float(frameTime/freq); |
| 192 | // Set view 0 default viewport. |
| 193 | bgfx::setViewRect(0, 0, 0, width, height); |
196 | 194 | |
197 | | // Set view 0 default viewport. |
198 | | bgfx::setViewRect(0, 0, 0, width, height); |
| 195 | // Use debug font to print information about this example. |
| 196 | bgfx::dbgTextClear(); |
| 197 | bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/24-nbody"); |
| 198 | bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: N-body simulation with compute shaders using buffers."); |
199 | 199 | |
200 | | // Use debug font to print information about this example. |
201 | | bgfx::dbgTextClear(); |
202 | | bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/24-nbody"); |
203 | | bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: N-body simulation with compute shaders using buffers."); |
| 200 | imguiBeginFrame(mouseState.m_mx |
| 201 | , mouseState.m_my |
| 202 | , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) |
| 203 | | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) |
| 204 | , 0 |
| 205 | , width |
| 206 | , height |
| 207 | ); |
| 208 | imguiBeginScrollArea("Settings", width - width / 4 - 10, 10, width / 4, 500, &scrollArea); |
| 209 | imguiSlider("Random seed", u_paramsData.baseSeed, 0, 100); |
| 210 | int32_t shape = imguiChoose(u_paramsData.initialShape, "Point", "Sphere", "Box", "Donut"); |
| 211 | imguiSlider("Initial speed", u_paramsData.initialSpeed, 0.0f, 300.0f, 0.1f); |
| 212 | bool reset = imguiButton("Reset"); |
| 213 | imguiSeparatorLine(); |
| 214 | imguiSlider("Particle count (x512)", u_paramsData.dispatchSize, 1, 64); |
| 215 | imguiSlider("Gravity", u_paramsData.gravity, 0.0f, 0.3f, 0.001f); |
| 216 | imguiSlider("Damping", u_paramsData.damping, 0.0f, 1.0f, 0.01f); |
| 217 | imguiSlider("Max acceleration", u_paramsData.maxAccel, 0.0f, 100.0f, 0.01f); |
| 218 | imguiSlider("Time step", u_paramsData.timeStep, 0.0f, 0.02f, 0.0001f); |
| 219 | imguiSeparatorLine(); |
| 220 | imguiSlider("Particle intensity", u_paramsData.particleIntensity, 0.0f, 1.0f, 0.001f); |
| 221 | imguiSlider("Particle size", u_paramsData.particleSize, 0.0f, 1.0f, 0.001f); |
| 222 | imguiSlider("Particle power", u_paramsData.particlePower, 0.001f, 16.0f, 0.01f); |
| 223 | imguiEndScrollArea(); |
| 224 | imguiEndFrame(); |
204 | 225 | |
205 | | imguiBeginFrame(mouseState.m_mx |
206 | | , mouseState.m_my |
207 | | , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) |
208 | | | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) |
209 | | , 0 |
210 | | , width |
211 | | , height |
212 | | ); |
213 | | imguiBeginScrollArea("Settings", width - width / 4 - 10, 10, width / 4, 500, &scrollArea); |
214 | | imguiSlider("Random seed", u_paramsData.baseSeed, 0, 100); |
215 | | int32_t shape = imguiChoose(u_paramsData.initialShape, "Point", "Sphere", "Box", "Donut"); |
216 | | imguiSlider("Initial speed", u_paramsData.initialSpeed, 0.0f, 300.0f, 0.1f); |
217 | | bool defaults = imguiButton("Reset"); |
218 | | imguiSeparatorLine(); |
219 | | imguiSlider("Particle count (x512)", u_paramsData.dispatchSize, 1, 64); |
220 | | imguiSlider("Gravity", u_paramsData.gravity, 0.0f, 0.3f, 0.001f); |
221 | | imguiSlider("Damping", u_paramsData.damping, 0.0f, 1.0f, 0.01f); |
222 | | imguiSlider("Max acceleration", u_paramsData.maxAccel, 0.0f, 100.0f, 0.01f); |
223 | | imguiSlider("Time step", u_paramsData.timeStep, 0.0f, 0.02f, 0.0001f); |
224 | | imguiSeparatorLine(); |
225 | | imguiSlider("Particle intensity", u_paramsData.particleIntensity, 0.0f, 1.0f, 0.001f); |
226 | | imguiSlider("Particle size", u_paramsData.particleSize, 0.0f, 1.0f, 0.001f); |
227 | | imguiSlider("Particle power", u_paramsData.particlePower, 0.001f, 16.0f, 0.01f); |
228 | | imguiEndScrollArea(); |
229 | | imguiEndFrame(); |
| 226 | // Modify parameters and reset if shape is changed |
| 227 | if (shape != u_paramsData.initialShape) |
| 228 | { |
| 229 | reset = true; |
| 230 | InitializeParams(shape, &u_paramsData); |
| 231 | } |
230 | 232 | |
231 | | // Modify parameters and reset if shape is changed |
232 | | if (shape != u_paramsData.initialShape) |
233 | | { |
234 | | defaults = true; |
235 | | InitializeParams(shape, &u_paramsData); |
236 | | } |
237 | | |
238 | | if (defaults) |
239 | | { |
240 | | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); |
241 | | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write); |
242 | | bgfx::setUniform(u_params, &u_paramsData, 3); |
243 | | bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); |
244 | | } |
245 | | |
246 | | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Read); |
247 | | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Read); |
248 | | bgfx::setBuffer(2, prevPositionBuffer1, bgfx::Access::Write); |
249 | | bgfx::setBuffer(3, currPositionBuffer1, bgfx::Access::Write); |
| 233 | if (reset) |
| 234 | { |
| 235 | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); |
| 236 | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write); |
250 | 237 | bgfx::setUniform(u_params, &u_paramsData, 3); |
251 | | bgfx::dispatch(0, updateInstancesProgram, u_paramsData.dispatchSize, 1, 1); |
| 238 | bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); |
| 239 | } |
252 | 240 | |
253 | | bx::xchg(currPositionBuffer0, currPositionBuffer1); |
254 | | bx::xchg(prevPositionBuffer0, prevPositionBuffer1); |
| 241 | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Read); |
| 242 | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Read); |
| 243 | bgfx::setBuffer(2, prevPositionBuffer1, bgfx::Access::Write); |
| 244 | bgfx::setBuffer(3, currPositionBuffer1, bgfx::Access::Write); |
| 245 | bgfx::setUniform(u_params, &u_paramsData, 3); |
| 246 | bgfx::dispatch(0, updateInstancesProgram, u_paramsData.dispatchSize, 1, 1); |
255 | 247 | |
256 | | // Update camera. |
257 | | cameraUpdate(deltaTime, mouseState); |
258 | | cameraGetViewMtx(view); |
| 248 | bx::xchg(currPositionBuffer0, currPositionBuffer1); |
| 249 | bx::xchg(prevPositionBuffer0, prevPositionBuffer1); |
259 | 250 | |
260 | | // Set view and projection matrix for view 0. |
261 | | const bgfx::HMD* hmd = bgfx::getHMD(); |
262 | | if (NULL != hmd) |
263 | | { |
264 | | float viewHead[16]; |
265 | | float eye[3] = {}; |
266 | | bx::mtxQuatTranslationHMD(viewHead, hmd->eye[0].rotation, eye); |
| 251 | float view[16]; |
267 | 252 | |
268 | | float tmp[16]; |
269 | | bx::mtxMul(tmp, view, viewHead); |
| 253 | // Update camera. |
| 254 | cameraUpdate(deltaTime, mouseState); |
| 255 | cameraGetViewMtx(view); |
270 | 256 | |
271 | | float proj[16]; |
272 | | bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 10000.0f); |
| 257 | // Set view and projection matrix for view 0. |
| 258 | const bgfx::HMD* hmd = bgfx::getHMD(); |
| 259 | if (NULL != hmd) |
| 260 | { |
| 261 | float viewHead[16]; |
| 262 | float eye[3] = {}; |
| 263 | bx::mtxQuatTranslationHMD(viewHead, hmd->eye[0].rotation, eye); |
273 | 264 | |
274 | | bgfx::setViewTransform(0, tmp, proj); |
| 265 | float tmp[16]; |
| 266 | bx::mtxMul(tmp, view, viewHead); |
275 | 267 | |
276 | | // Set view 0 default viewport. |
277 | | // |
278 | | // Use HMD's width/height since HMD's internal frame buffer size |
279 | | // might be much larger than window size. |
280 | | bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height); |
281 | | } |
282 | | else |
283 | | { |
284 | | float proj[16]; |
285 | | bx::mtxProj(proj, 90.0f, float(width)/float(height), 0.1f, 10000.0f); |
286 | | bgfx::setViewTransform(0, view, proj); |
| 268 | float proj[16]; |
| 269 | bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 10000.0f); |
287 | 270 | |
288 | | // Set view 0 default viewport. |
289 | | bgfx::setViewRect(0, 0, 0, width, height); |
290 | | } |
| 271 | bgfx::setViewTransform(0, tmp, proj); |
291 | 272 | |
292 | | // Set vertex and fragment shaders. |
293 | | bgfx::setProgram(particleProgram); |
294 | | |
295 | | // Set vertex and index buffer. |
296 | | bgfx::setVertexBuffer(vbh); |
297 | | bgfx::setIndexBuffer(ibh); |
298 | | bgfx::setInstanceDataBuffer(currPositionBuffer0, 0, u_paramsData.dispatchSize * threadGroupUpdateSize); |
299 | | |
300 | | // Set render states. |
301 | | bgfx::setState(0 |
302 | | | BGFX_STATE_RGB_WRITE |
303 | | | BGFX_STATE_BLEND_ADD |
304 | | | BGFX_STATE_DEPTH_TEST_ALWAYS |
305 | | ); |
306 | | |
307 | | // Submit primitive for rendering to view 0. |
308 | | bgfx::submit(0); |
309 | | |
310 | | // Advance to next frame. Rendering thread will be kicked to |
311 | | // process submitted rendering primitives. |
312 | | bgfx::frame(); |
| 273 | // Set view 0 default viewport. |
| 274 | // |
| 275 | // Use HMD's width/height since HMD's internal frame buffer size |
| 276 | // might be much larger than window size. |
| 277 | bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height); |
313 | 278 | } |
314 | | |
315 | | // Cleanup. |
316 | | cameraDestroy(); |
317 | | imguiDestroy(); |
318 | | bgfx::destroyUniform(u_params); |
319 | | bgfx::destroyDynamicVertexBuffer(currPositionBuffer0); |
320 | | bgfx::destroyDynamicVertexBuffer(currPositionBuffer1); |
321 | | bgfx::destroyDynamicVertexBuffer(prevPositionBuffer0); |
322 | | bgfx::destroyDynamicVertexBuffer(prevPositionBuffer1); |
323 | | bgfx::destroyProgram(updateInstancesProgram); |
324 | | bgfx::destroyProgram(initInstancesProgram); |
325 | | bgfx::destroyIndexBuffer(ibh); |
326 | | bgfx::destroyVertexBuffer(vbh); |
327 | | bgfx::destroyProgram(particleProgram); |
328 | | } |
329 | | else |
330 | | { |
331 | | int64_t timeOffset = bx::getHPCounter(); |
332 | | |
333 | | entry::MouseState mouseState; |
334 | | while (!entry::processEvents(width, height, debug, reset, &mouseState) ) |
| 279 | else |
335 | 280 | { |
336 | | int64_t now = bx::getHPCounter(); |
337 | | float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) ); |
| 281 | float proj[16]; |
| 282 | bx::mtxProj(proj, 90.0f, float(width)/float(height), 0.1f, 10000.0f); |
| 283 | bgfx::setViewTransform(0, view, proj); |
338 | 284 | |
| 285 | // Set view 0 default viewport. |
339 | 286 | bgfx::setViewRect(0, 0, 0, width, height); |
| 287 | } |
340 | 288 | |
341 | | bgfx::dbgTextClear(); |
342 | | bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/24-nbody"); |
343 | | bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: N-body simulation with compute shaders using buffers."); |
| 289 | // Set vertex and fragment shaders. |
| 290 | bgfx::setProgram(particleProgram); |
344 | 291 | |
345 | | bool blink = uint32_t(time*3.0f)&1; |
346 | | bgfx::dbgTextPrintf(0, 5, blink ? 0x1f : 0x01, " Compute is not supported by GPU. "); |
| 292 | // Set vertex and index buffer. |
| 293 | bgfx::setVertexBuffer(vbh); |
| 294 | bgfx::setIndexBuffer(ibh); |
| 295 | bgfx::setInstanceDataBuffer(currPositionBuffer0, 0, u_paramsData.dispatchSize * threadGroupUpdateSize); |
347 | 296 | |
348 | | bgfx::submit(0); |
349 | | bgfx::frame(); |
350 | | } |
| 297 | // Set render states. |
| 298 | bgfx::setState(0 |
| 299 | | BGFX_STATE_RGB_WRITE |
| 300 | | BGFX_STATE_BLEND_ADD |
| 301 | | BGFX_STATE_DEPTH_TEST_ALWAYS |
| 302 | ); |
| 303 | |
| 304 | // Submit primitive for rendering to view 0. |
| 305 | bgfx::submit(0); |
| 306 | |
| 307 | // Advance to next frame. Rendering thread will be kicked to |
| 308 | // process submitted rendering primitives. |
| 309 | bgfx::frame(); |
351 | 310 | } |
352 | 311 | |
| 312 | // Cleanup. |
| 313 | cameraDestroy(); |
| 314 | imguiDestroy(); |
| 315 | bgfx::destroyUniform(u_params); |
| 316 | bgfx::destroyDynamicVertexBuffer(currPositionBuffer0); |
| 317 | bgfx::destroyDynamicVertexBuffer(currPositionBuffer1); |
| 318 | bgfx::destroyDynamicVertexBuffer(prevPositionBuffer0); |
| 319 | bgfx::destroyDynamicVertexBuffer(prevPositionBuffer1); |
| 320 | bgfx::destroyProgram(updateInstancesProgram); |
| 321 | bgfx::destroyProgram(initInstancesProgram); |
| 322 | bgfx::destroyIndexBuffer(ibh); |
| 323 | bgfx::destroyVertexBuffer(vbh); |
| 324 | bgfx::destroyProgram(particleProgram); |
| 325 | |
353 | 326 | // Shutdown bgfx. |
354 | 327 | bgfx::shutdown(); |
355 | 328 | |
trunk/3rdparty/bx/scripts/toolchain.lua
r245332 | r245333 | |
40 | 40 | allowed = { |
41 | 41 | { "vs2012-clang", "Clang 3.6" }, |
42 | 42 | { "vs2013-clang", "Clang 3.6" }, |
43 | | { "vs2012-xp", "Visual Studio 2012 targeting XP" }, |
44 | | { "vs2013-xp", "Visual Studio 2013 targeting XP" }, |
45 | | { "vs2015-xp", "Visual Studio 2015 targeting XP" }, |
| 43 | { "vs2012-xp", "Visual Studio 2012 targeting XP" }, |
| 44 | { "vs2013-xp", "Visual Studio 2013 targeting XP" }, |
46 | 45 | { "winphone8", "Windows Phone 8.0" }, |
47 | 46 | { "winphone81", "Windows Phone 8.1" }, |
48 | 47 | }, |
r245332 | r245333 | |
111 | 110 | premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++" |
112 | 111 | premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar" |
113 | 112 | location (path.join(_buildDir, "projects", _ACTION .. "-android-arm")) |
| 113 | end |
114 | 114 | |
115 | | elseif "android-mips" == _OPTIONS["gcc"] then |
| 115 | if "android-mips" == _OPTIONS["gcc"] then |
116 | 116 | |
117 | 117 | if not os.getenv("ANDROID_NDK_MIPS") or not os.getenv("ANDROID_NDK_ROOT") then |
118 | 118 | print("Set ANDROID_NDK_MIPS and ANDROID_NDK_ROOT envrionment variables.") |
r245332 | r245333 | |
122 | 122 | premake.gcc.cxx = "$(ANDROID_NDK_MIPS)/bin/mipsel-linux-android-g++" |
123 | 123 | premake.gcc.ar = "$(ANDROID_NDK_MIPS)/bin/mipsel-linux-android-ar" |
124 | 124 | location (path.join(_buildDir, "projects", _ACTION .. "-android-mips")) |
| 125 | end |
125 | 126 | |
126 | | elseif "android-x86" == _OPTIONS["gcc"] then |
| 127 | if "android-x86" == _OPTIONS["gcc"] then |
127 | 128 | |
128 | 129 | if not os.getenv("ANDROID_NDK_X86") or not os.getenv("ANDROID_NDK_ROOT") then |
129 | 130 | print("Set ANDROID_NDK_X86 and ANDROID_NDK_ROOT envrionment variables.") |
r245332 | r245333 | |
133 | 134 | premake.gcc.cxx = "$(ANDROID_NDK_X86)/bin/i686-linux-android-g++" |
134 | 135 | premake.gcc.ar = "$(ANDROID_NDK_X86)/bin/i686-linux-android-ar" |
135 | 136 | location (path.join(_buildDir, "projects", _ACTION .. "-android-x86")) |
| 137 | end |
136 | 138 | |
137 | | elseif "asmjs" == _OPTIONS["gcc"] then |
| 139 | if "asmjs" == _OPTIONS["gcc"] then |
138 | 140 | |
139 | 141 | if not os.getenv("EMSCRIPTEN") then |
140 | 142 | print("Set EMSCRIPTEN enviroment variables.") |
r245332 | r245333 | |
145 | 147 | premake.gcc.ar = "$(EMSCRIPTEN)/emar" |
146 | 148 | premake.gcc.llvm = true |
147 | 149 | location (path.join(_buildDir, "projects", _ACTION .. "-asmjs")) |
| 150 | end |
148 | 151 | |
149 | | elseif "freebsd" == _OPTIONS["gcc"] then |
| 152 | if "freebsd" == _OPTIONS["gcc"] then |
150 | 153 | location (path.join(_buildDir, "projects", _ACTION .. "-freebsd")) |
| 154 | end |
151 | 155 | |
152 | | elseif "ios-arm" == _OPTIONS["gcc"] then |
| 156 | if "ios-arm" == _OPTIONS["gcc"] then |
153 | 157 | premake.gcc.cc = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" |
154 | 158 | premake.gcc.cxx = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" |
155 | 159 | premake.gcc.ar = "ar" |
156 | 160 | location (path.join(_buildDir, "projects", _ACTION .. "-ios-arm")) |
| 161 | end |
157 | 162 | |
158 | | elseif "ios-simulator" == _OPTIONS["gcc"] then |
| 163 | if "ios-simulator" == _OPTIONS["gcc"] then |
159 | 164 | premake.gcc.cc = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" |
160 | 165 | premake.gcc.cxx = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" |
161 | 166 | premake.gcc.ar = "ar" |
162 | 167 | location (path.join(_buildDir, "projects", _ACTION .. "-ios-simulator")) |
| 168 | end |
163 | 169 | |
164 | | elseif "linux-gcc" == _OPTIONS["gcc"] then |
| 170 | if "linux-gcc" == _OPTIONS["gcc"] then |
165 | 171 | location (path.join(_buildDir, "projects", _ACTION .. "-linux")) |
| 172 | end |
166 | 173 | |
167 | | elseif "linux-clang" == _OPTIONS["gcc"] then |
| 174 | if "linux-clang" == _OPTIONS["gcc"] then |
168 | 175 | premake.gcc.cc = "clang" |
169 | 176 | premake.gcc.cxx = "clang++" |
170 | 177 | premake.gcc.ar = "ar" |
171 | 178 | location (path.join(_buildDir, "projects", _ACTION .. "-linux-clang")) |
| 179 | end |
172 | 180 | |
173 | | elseif "mingw-gcc" == _OPTIONS["gcc"] then |
| 181 | if "mingw-gcc" == _OPTIONS["gcc"] then |
174 | 182 | premake.gcc.cc = "$(MINGW)/bin/x86_64-w64-mingw32-gcc" |
175 | 183 | premake.gcc.cxx = "$(MINGW)/bin/x86_64-w64-mingw32-g++" |
176 | 184 | premake.gcc.ar = "$(MINGW)/bin/ar" |
177 | 185 | location (path.join(_buildDir, "projects", _ACTION .. "-mingw-gcc")) |
| 186 | end |
178 | 187 | |
179 | | elseif "mingw-clang" == _OPTIONS["gcc"] then |
| 188 | if "mingw-clang" == _OPTIONS["gcc"] then |
180 | 189 | premake.gcc.cc = "$(CLANG)/bin/clang" |
181 | 190 | premake.gcc.cxx = "$(CLANG)/bin/clang++" |
182 | 191 | premake.gcc.ar = "$(MINGW)/bin/ar" |
183 | 192 | -- premake.gcc.ar = "$(CLANG)/bin/llvm-ar" |
184 | 193 | -- premake.gcc.llvm = true |
185 | 194 | location (path.join(_buildDir, "projects", _ACTION .. "-mingw-clang")) |
| 195 | end |
186 | 196 | |
187 | | elseif "nacl" == _OPTIONS["gcc"] then |
| 197 | if "nacl" == _OPTIONS["gcc"] then |
188 | 198 | |
189 | 199 | if not os.getenv("NACL_SDK_ROOT") then |
190 | 200 | print("Set NACL_SDK_ROOT enviroment variables.") |
r245332 | r245333 | |
201 | 211 | premake.gcc.cxx = naclToolchain .. "g++" |
202 | 212 | premake.gcc.ar = naclToolchain .. "ar" |
203 | 213 | location (path.join(_buildDir, "projects", _ACTION .. "-nacl")) |
| 214 | end |
204 | 215 | |
205 | | elseif "nacl-arm" == _OPTIONS["gcc"] then |
| 216 | if "nacl-arm" == _OPTIONS["gcc"] then |
206 | 217 | |
207 | 218 | if not os.getenv("NACL_SDK_ROOT") then |
208 | 219 | print("Set NACL_SDK_ROOT enviroment variables.") |
r245332 | r245333 | |
219 | 230 | premake.gcc.cxx = naclToolchain .. "g++" |
220 | 231 | premake.gcc.ar = naclToolchain .. "ar" |
221 | 232 | location (path.join(_buildDir, "projects", _ACTION .. "-nacl-arm")) |
| 233 | end |
222 | 234 | |
223 | | elseif "osx" == _OPTIONS["gcc"] then |
224 | | |
| 235 | if "osx" == _OPTIONS["gcc"] then |
225 | 236 | if os.is("linux") then |
226 | 237 | local osxToolchain = "x86_64-apple-darwin13-" |
227 | 238 | premake.gcc.cc = osxToolchain .. "clang" |
r245332 | r245333 | |
229 | 240 | premake.gcc.ar = osxToolchain .. "ar" |
230 | 241 | end |
231 | 242 | location (path.join(_buildDir, "projects", _ACTION .. "-osx")) |
| 243 | end |
232 | 244 | |
233 | | elseif "pnacl" == _OPTIONS["gcc"] then |
| 245 | if "pnacl" == _OPTIONS["gcc"] then |
234 | 246 | |
235 | 247 | if not os.getenv("NACL_SDK_ROOT") then |
236 | 248 | print("Set NACL_SDK_ROOT enviroment variables.") |
r245332 | r245333 | |
247 | 259 | premake.gcc.cxx = naclToolchain .. "clang++" |
248 | 260 | premake.gcc.ar = naclToolchain .. "ar" |
249 | 261 | location (path.join(_buildDir, "projects", _ACTION .. "-pnacl")) |
| 262 | end |
250 | 263 | |
251 | | elseif "qnx-arm" == _OPTIONS["gcc"] then |
| 264 | if "qnx-arm" == _OPTIONS["gcc"] then |
252 | 265 | |
253 | 266 | if not os.getenv("QNX_HOST") then |
254 | 267 | print("Set QNX_HOST enviroment variables.") |
r245332 | r245333 | |
258 | 271 | premake.gcc.cxx = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-g++" |
259 | 272 | premake.gcc.ar = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-ar" |
260 | 273 | location (path.join(_buildDir, "projects", _ACTION .. "-qnx-arm")) |
| 274 | end |
261 | 275 | |
262 | | elseif "rpi" == _OPTIONS["gcc"] then |
| 276 | if "rpi" == _OPTIONS["gcc"] then |
263 | 277 | location (path.join(_buildDir, "projects", _ACTION .. "-rpi")) |
264 | 278 | end |
265 | 279 | elseif _ACTION == "vs2012" or _ACTION == "vs2013" or _ACTION == "vs2015" then |
r245332 | r245333 | |
267 | 281 | if (_ACTION .. "-clang") == _OPTIONS["vs"] then |
268 | 282 | premake.vstudio.toolset = ("LLVM-" .. _ACTION) |
269 | 283 | location (path.join(_buildDir, "projects", _ACTION .. "-clang")) |
| 284 | end |
270 | 285 | |
271 | | elseif "winphone8" == _OPTIONS["vs"] then |
| 286 | if "winphone8" == _OPTIONS["vs"] then |
272 | 287 | premake.vstudio.toolset = "v110_wp80" |
273 | 288 | location (path.join(_buildDir, "projects", _ACTION .. "-winphone8")) |
| 289 | end |
274 | 290 | |
275 | | elseif "winphone81" == _OPTIONS["vs"] then |
| 291 | if "winphone81" == _OPTIONS["vs"] then |
276 | 292 | premake.vstudio.toolset = "v120_wp81" |
277 | 293 | platforms { "ARM" } |
278 | 294 | location (path.join(_buildDir, "projects", _ACTION .. "-winphone81")) |
| 295 | end |
279 | 296 | |
280 | | elseif ("vs2012-xp") == _OPTIONS["vs"] then |
| 297 | if ("vs2012-xp") == _OPTIONS["vs"] then |
281 | 298 | premake.vstudio.toolset = ("v110_xp") |
282 | 299 | location (path.join(_buildDir, "projects", _ACTION .. "-xp")) |
| 300 | end |
283 | 301 | |
284 | | elseif ("vs2013-xp") == _OPTIONS["vs"] then |
| 302 | if ("vs2013-xp") == _OPTIONS["vs"] then |
285 | 303 | premake.vstudio.toolset = ("v120_xp") |
286 | 304 | location (path.join(_buildDir, "projects", _ACTION .. "-xp")) |
287 | | |
288 | | elseif ("vs2015-xp") == _OPTIONS["vs"] then |
289 | | premake.vstudio.toolset = ("v140_xp") |
290 | | location (path.join(_buildDir, "projects", _ACTION .. "-xp")) |
291 | 305 | end |
292 | 306 | |
293 | 307 | elseif _ACTION == "xcode4" then |
r245332 | r245333 | |
295 | 309 | if "osx" == _OPTIONS["xcode"] then |
296 | 310 | premake.xcode.toolset = "macosx" |
297 | 311 | location (path.join(_buildDir, "projects", _ACTION .. "-osx")) |
298 | | |
299 | | elseif "ios" == _OPTIONS["xcode"] then |
| 312 | end |
| 313 | if "ios" == _OPTIONS["xcode"] then |
300 | 314 | premake.xcode.toolset = "iphoneos" |
301 | 315 | location (path.join(_buildDir, "projects", _ACTION .. "-ios")) |
302 | 316 | end |
r245332 | r245333 | |
746 | 760 | configuration { "osx", "x32" } |
747 | 761 | targetdir (path.join(_buildDir, "osx32_clang/bin")) |
748 | 762 | objdir (path.join(_buildDir, "osx32_clang/obj")) |
749 | | --libdirs { path.join(_libDir, "lib/osx32_clang") } |
| 763 | libdirs { path.join(_libDir, "lib/osx32_clang") } |
750 | 764 | buildoptions { |
751 | 765 | "-m32", |
752 | 766 | } |
r245332 | r245333 | |
754 | 768 | configuration { "osx", "x64" } |
755 | 769 | targetdir (path.join(_buildDir, "osx64_clang/bin")) |
756 | 770 | objdir (path.join(_buildDir, "osx64_clang/obj")) |
757 | | --libdirs { path.join(_libDir, "lib/osx64_clang") } |
| 771 | libdirs { path.join(_libDir, "lib/osx64_clang") } |
758 | 772 | buildoptions { |
759 | 773 | "-m64", |
760 | 774 | } |