trunk/3rdparty/bgfx/examples/24-nbody/nbody.cpp
r245333 | r245334 | |
117 | 117 | , 0 |
118 | 118 | ); |
119 | 119 | |
120 | | // Imgui. |
121 | | imguiCreate(); |
| 120 | const bgfx::Caps* caps = bgfx::getCaps(); |
| 121 | const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE); |
122 | 122 | |
123 | | bgfx::VertexDecl quadVertexDecl; |
124 | | quadVertexDecl.begin() |
125 | | .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) |
126 | | .end(); |
| 123 | if (computeSupported) |
| 124 | { |
| 125 | // Imgui. |
| 126 | imguiCreate(); |
127 | 127 | |
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 | | ); |
| 128 | bgfx::VertexDecl quadVertexDecl; |
| 129 | quadVertexDecl.begin() |
| 130 | .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) |
| 131 | .end(); |
134 | 132 | |
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 | | ); |
| 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 | ); |
140 | 139 | |
141 | | // Create particle program from shaders. |
142 | | bgfx::ProgramHandle particleProgram = loadProgram("vs_particle", "fs_particle"); |
| 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 | ); |
143 | 145 | |
144 | | // Setup compute buffers |
145 | | bgfx::VertexDecl computeVertexDecl; |
146 | | computeVertexDecl.begin() |
147 | | .add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float) |
148 | | .end(); |
| 146 | // Create particle program from shaders. |
| 147 | bgfx::ProgramHandle particleProgram = loadProgram("vs_particle", "fs_particle"); |
149 | 148 | |
150 | | const uint32_t threadGroupUpdateSize = 512; |
151 | | const uint32_t maxParticleCount = 32 * 1024; |
| 149 | // Setup compute buffers |
| 150 | bgfx::VertexDecl computeVertexDecl; |
| 151 | computeVertexDecl.begin() |
| 152 | .add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float) |
| 153 | .end(); |
152 | 154 | |
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); |
| 155 | const uint32_t threadGroupUpdateSize = 512; |
| 156 | const uint32_t maxParticleCount = 32 * 1024; |
157 | 157 | |
158 | | bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv, 3); |
| 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); |
159 | 162 | |
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); |
| 163 | bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv, 3); |
164 | 164 | |
165 | | u_paramsDataStruct u_paramsData; |
166 | | InitializeParams(0, &u_paramsData); |
| 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); |
167 | 169 | |
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); |
| 170 | u_paramsDataStruct u_paramsData; |
| 171 | InitializeParams(0, &u_paramsData); |
172 | 172 | |
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); |
| 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); |
179 | 177 | |
180 | | int32_t scrollArea = 0; |
| 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); |
181 | 184 | |
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); |
| 185 | int32_t scrollArea = 0; |
191 | 186 | |
192 | | // Set view 0 default viewport. |
193 | | bgfx::setViewRect(0, 0, 0, width, height); |
| 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); |
194 | 196 | |
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."); |
| 197 | // Set view 0 default viewport. |
| 198 | bgfx::setViewRect(0, 0, 0, width, height); |
199 | 199 | |
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(); |
| 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."); |
225 | 204 | |
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 | | } |
| 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(); |
232 | 230 | |
233 | | if (reset) |
234 | | { |
235 | | bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); |
236 | | bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write); |
| 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); |
237 | 250 | bgfx::setUniform(u_params, &u_paramsData, 3); |
238 | | bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); |
239 | | } |
| 251 | bgfx::dispatch(0, updateInstancesProgram, u_paramsData.dispatchSize, 1, 1); |
240 | 252 | |
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); |
| 253 | bx::xchg(currPositionBuffer0, currPositionBuffer1); |
| 254 | bx::xchg(prevPositionBuffer0, prevPositionBuffer1); |
247 | 255 | |
248 | | bx::xchg(currPositionBuffer0, currPositionBuffer1); |
249 | | bx::xchg(prevPositionBuffer0, prevPositionBuffer1); |
| 256 | // Update camera. |
| 257 | cameraUpdate(deltaTime, mouseState); |
| 258 | cameraGetViewMtx(view); |
250 | 259 | |
251 | | float view[16]; |
| 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); |
252 | 267 | |
253 | | // Update camera. |
254 | | cameraUpdate(deltaTime, mouseState); |
255 | | cameraGetViewMtx(view); |
| 268 | float tmp[16]; |
| 269 | bx::mtxMul(tmp, view, viewHead); |
256 | 270 | |
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); |
| 271 | float proj[16]; |
| 272 | bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 10000.0f); |
264 | 273 | |
265 | | float tmp[16]; |
266 | | bx::mtxMul(tmp, view, viewHead); |
| 274 | bgfx::setViewTransform(0, tmp, proj); |
267 | 275 | |
268 | | float proj[16]; |
269 | | bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 10000.0f); |
| 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); |
270 | 287 | |
271 | | bgfx::setViewTransform(0, tmp, proj); |
| 288 | // Set view 0 default viewport. |
| 289 | bgfx::setViewRect(0, 0, 0, width, height); |
| 290 | } |
272 | 291 | |
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); |
| 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(); |
278 | 313 | } |
279 | | else |
| 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) ) |
280 | 335 | { |
281 | | float proj[16]; |
282 | | bx::mtxProj(proj, 90.0f, float(width)/float(height), 0.1f, 10000.0f); |
283 | | bgfx::setViewTransform(0, view, proj); |
| 336 | int64_t now = bx::getHPCounter(); |
| 337 | float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) ); |
284 | 338 | |
285 | | // Set view 0 default viewport. |
286 | 339 | bgfx::setViewRect(0, 0, 0, width, height); |
287 | | } |
288 | 340 | |
289 | | // Set vertex and fragment shaders. |
290 | | bgfx::setProgram(particleProgram); |
| 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."); |
291 | 344 | |
292 | | // Set vertex and index buffer. |
293 | | bgfx::setVertexBuffer(vbh); |
294 | | bgfx::setIndexBuffer(ibh); |
295 | | bgfx::setInstanceDataBuffer(currPositionBuffer0, 0, u_paramsData.dispatchSize * threadGroupUpdateSize); |
| 345 | bool blink = uint32_t(time*3.0f)&1; |
| 346 | bgfx::dbgTextPrintf(0, 5, blink ? 0x1f : 0x01, " Compute is not supported by GPU. "); |
296 | 347 | |
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(); |
| 348 | bgfx::submit(0); |
| 349 | bgfx::frame(); |
| 350 | } |
310 | 351 | } |
311 | 352 | |
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 | | |
326 | 353 | // Shutdown bgfx. |
327 | 354 | bgfx::shutdown(); |
328 | 355 | |
trunk/3rdparty/bx/scripts/toolchain.lua
r245333 | r245334 | |
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" }, |
| 43 | { "vs2012-xp", "Visual Studio 2012 targeting XP" }, |
| 44 | { "vs2013-xp", "Visual Studio 2013 targeting XP" }, |
| 45 | { "vs2015-xp", "Visual Studio 2015 targeting XP" }, |
45 | 46 | { "winphone8", "Windows Phone 8.0" }, |
46 | 47 | { "winphone81", "Windows Phone 8.1" }, |
47 | 48 | }, |
r245333 | r245334 | |
110 | 111 | premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++" |
111 | 112 | premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar" |
112 | 113 | location (path.join(_buildDir, "projects", _ACTION .. "-android-arm")) |
113 | | end |
114 | 114 | |
115 | | if "android-mips" == _OPTIONS["gcc"] then |
| 115 | elseif "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.") |
r245333 | r245334 | |
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 |
126 | 125 | |
127 | | if "android-x86" == _OPTIONS["gcc"] then |
| 126 | elseif "android-x86" == _OPTIONS["gcc"] then |
128 | 127 | |
129 | 128 | if not os.getenv("ANDROID_NDK_X86") or not os.getenv("ANDROID_NDK_ROOT") then |
130 | 129 | print("Set ANDROID_NDK_X86 and ANDROID_NDK_ROOT envrionment variables.") |
r245333 | r245334 | |
134 | 133 | premake.gcc.cxx = "$(ANDROID_NDK_X86)/bin/i686-linux-android-g++" |
135 | 134 | premake.gcc.ar = "$(ANDROID_NDK_X86)/bin/i686-linux-android-ar" |
136 | 135 | location (path.join(_buildDir, "projects", _ACTION .. "-android-x86")) |
137 | | end |
138 | 136 | |
139 | | if "asmjs" == _OPTIONS["gcc"] then |
| 137 | elseif "asmjs" == _OPTIONS["gcc"] then |
140 | 138 | |
141 | 139 | if not os.getenv("EMSCRIPTEN") then |
142 | 140 | print("Set EMSCRIPTEN enviroment variables.") |
r245333 | r245334 | |
147 | 145 | premake.gcc.ar = "$(EMSCRIPTEN)/emar" |
148 | 146 | premake.gcc.llvm = true |
149 | 147 | location (path.join(_buildDir, "projects", _ACTION .. "-asmjs")) |
150 | | end |
151 | 148 | |
152 | | if "freebsd" == _OPTIONS["gcc"] then |
| 149 | elseif "freebsd" == _OPTIONS["gcc"] then |
153 | 150 | location (path.join(_buildDir, "projects", _ACTION .. "-freebsd")) |
154 | | end |
155 | 151 | |
156 | | if "ios-arm" == _OPTIONS["gcc"] then |
| 152 | elseif "ios-arm" == _OPTIONS["gcc"] then |
157 | 153 | premake.gcc.cc = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" |
158 | 154 | premake.gcc.cxx = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" |
159 | 155 | premake.gcc.ar = "ar" |
160 | 156 | location (path.join(_buildDir, "projects", _ACTION .. "-ios-arm")) |
161 | | end |
162 | 157 | |
163 | | if "ios-simulator" == _OPTIONS["gcc"] then |
| 158 | elseif "ios-simulator" == _OPTIONS["gcc"] then |
164 | 159 | premake.gcc.cc = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" |
165 | 160 | premake.gcc.cxx = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" |
166 | 161 | premake.gcc.ar = "ar" |
167 | 162 | location (path.join(_buildDir, "projects", _ACTION .. "-ios-simulator")) |
168 | | end |
169 | 163 | |
170 | | if "linux-gcc" == _OPTIONS["gcc"] then |
| 164 | elseif "linux-gcc" == _OPTIONS["gcc"] then |
171 | 165 | location (path.join(_buildDir, "projects", _ACTION .. "-linux")) |
172 | | end |
173 | 166 | |
174 | | if "linux-clang" == _OPTIONS["gcc"] then |
| 167 | elseif "linux-clang" == _OPTIONS["gcc"] then |
175 | 168 | premake.gcc.cc = "clang" |
176 | 169 | premake.gcc.cxx = "clang++" |
177 | 170 | premake.gcc.ar = "ar" |
178 | 171 | location (path.join(_buildDir, "projects", _ACTION .. "-linux-clang")) |
179 | | end |
180 | 172 | |
181 | | if "mingw-gcc" == _OPTIONS["gcc"] then |
| 173 | elseif "mingw-gcc" == _OPTIONS["gcc"] then |
182 | 174 | premake.gcc.cc = "$(MINGW)/bin/x86_64-w64-mingw32-gcc" |
183 | 175 | premake.gcc.cxx = "$(MINGW)/bin/x86_64-w64-mingw32-g++" |
184 | 176 | premake.gcc.ar = "$(MINGW)/bin/ar" |
185 | 177 | location (path.join(_buildDir, "projects", _ACTION .. "-mingw-gcc")) |
186 | | end |
187 | 178 | |
188 | | if "mingw-clang" == _OPTIONS["gcc"] then |
| 179 | elseif "mingw-clang" == _OPTIONS["gcc"] then |
189 | 180 | premake.gcc.cc = "$(CLANG)/bin/clang" |
190 | 181 | premake.gcc.cxx = "$(CLANG)/bin/clang++" |
191 | 182 | premake.gcc.ar = "$(MINGW)/bin/ar" |
192 | 183 | -- premake.gcc.ar = "$(CLANG)/bin/llvm-ar" |
193 | 184 | -- premake.gcc.llvm = true |
194 | 185 | location (path.join(_buildDir, "projects", _ACTION .. "-mingw-clang")) |
195 | | end |
196 | 186 | |
197 | | if "nacl" == _OPTIONS["gcc"] then |
| 187 | elseif "nacl" == _OPTIONS["gcc"] then |
198 | 188 | |
199 | 189 | if not os.getenv("NACL_SDK_ROOT") then |
200 | 190 | print("Set NACL_SDK_ROOT enviroment variables.") |
r245333 | r245334 | |
211 | 201 | premake.gcc.cxx = naclToolchain .. "g++" |
212 | 202 | premake.gcc.ar = naclToolchain .. "ar" |
213 | 203 | location (path.join(_buildDir, "projects", _ACTION .. "-nacl")) |
214 | | end |
215 | 204 | |
216 | | if "nacl-arm" == _OPTIONS["gcc"] then |
| 205 | elseif "nacl-arm" == _OPTIONS["gcc"] then |
217 | 206 | |
218 | 207 | if not os.getenv("NACL_SDK_ROOT") then |
219 | 208 | print("Set NACL_SDK_ROOT enviroment variables.") |
r245333 | r245334 | |
230 | 219 | premake.gcc.cxx = naclToolchain .. "g++" |
231 | 220 | premake.gcc.ar = naclToolchain .. "ar" |
232 | 221 | location (path.join(_buildDir, "projects", _ACTION .. "-nacl-arm")) |
233 | | end |
234 | 222 | |
235 | | if "osx" == _OPTIONS["gcc"] then |
| 223 | elseif "osx" == _OPTIONS["gcc"] then |
| 224 | |
236 | 225 | if os.is("linux") then |
237 | 226 | local osxToolchain = "x86_64-apple-darwin13-" |
238 | 227 | premake.gcc.cc = osxToolchain .. "clang" |
r245333 | r245334 | |
240 | 229 | premake.gcc.ar = osxToolchain .. "ar" |
241 | 230 | end |
242 | 231 | location (path.join(_buildDir, "projects", _ACTION .. "-osx")) |
243 | | end |
244 | 232 | |
245 | | if "pnacl" == _OPTIONS["gcc"] then |
| 233 | elseif "pnacl" == _OPTIONS["gcc"] then |
246 | 234 | |
247 | 235 | if not os.getenv("NACL_SDK_ROOT") then |
248 | 236 | print("Set NACL_SDK_ROOT enviroment variables.") |
r245333 | r245334 | |
259 | 247 | premake.gcc.cxx = naclToolchain .. "clang++" |
260 | 248 | premake.gcc.ar = naclToolchain .. "ar" |
261 | 249 | location (path.join(_buildDir, "projects", _ACTION .. "-pnacl")) |
262 | | end |
263 | 250 | |
264 | | if "qnx-arm" == _OPTIONS["gcc"] then |
| 251 | elseif "qnx-arm" == _OPTIONS["gcc"] then |
265 | 252 | |
266 | 253 | if not os.getenv("QNX_HOST") then |
267 | 254 | print("Set QNX_HOST enviroment variables.") |
r245333 | r245334 | |
271 | 258 | premake.gcc.cxx = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-g++" |
272 | 259 | premake.gcc.ar = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-ar" |
273 | 260 | location (path.join(_buildDir, "projects", _ACTION .. "-qnx-arm")) |
274 | | end |
275 | 261 | |
276 | | if "rpi" == _OPTIONS["gcc"] then |
| 262 | elseif "rpi" == _OPTIONS["gcc"] then |
277 | 263 | location (path.join(_buildDir, "projects", _ACTION .. "-rpi")) |
278 | 264 | end |
279 | 265 | elseif _ACTION == "vs2012" or _ACTION == "vs2013" or _ACTION == "vs2015" then |
r245333 | r245334 | |
281 | 267 | if (_ACTION .. "-clang") == _OPTIONS["vs"] then |
282 | 268 | premake.vstudio.toolset = ("LLVM-" .. _ACTION) |
283 | 269 | location (path.join(_buildDir, "projects", _ACTION .. "-clang")) |
284 | | end |
285 | 270 | |
286 | | if "winphone8" == _OPTIONS["vs"] then |
| 271 | elseif "winphone8" == _OPTIONS["vs"] then |
287 | 272 | premake.vstudio.toolset = "v110_wp80" |
288 | 273 | location (path.join(_buildDir, "projects", _ACTION .. "-winphone8")) |
289 | | end |
290 | 274 | |
291 | | if "winphone81" == _OPTIONS["vs"] then |
| 275 | elseif "winphone81" == _OPTIONS["vs"] then |
292 | 276 | premake.vstudio.toolset = "v120_wp81" |
293 | 277 | platforms { "ARM" } |
294 | 278 | location (path.join(_buildDir, "projects", _ACTION .. "-winphone81")) |
295 | | end |
296 | 279 | |
297 | | if ("vs2012-xp") == _OPTIONS["vs"] then |
| 280 | elseif ("vs2012-xp") == _OPTIONS["vs"] then |
298 | 281 | premake.vstudio.toolset = ("v110_xp") |
299 | 282 | location (path.join(_buildDir, "projects", _ACTION .. "-xp")) |
300 | | end |
301 | 283 | |
302 | | if ("vs2013-xp") == _OPTIONS["vs"] then |
| 284 | elseif ("vs2013-xp") == _OPTIONS["vs"] then |
303 | 285 | premake.vstudio.toolset = ("v120_xp") |
304 | 286 | 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")) |
305 | 291 | end |
306 | 292 | |
307 | 293 | elseif _ACTION == "xcode4" then |
r245333 | r245334 | |
309 | 295 | if "osx" == _OPTIONS["xcode"] then |
310 | 296 | premake.xcode.toolset = "macosx" |
311 | 297 | location (path.join(_buildDir, "projects", _ACTION .. "-osx")) |
312 | | end |
313 | | if "ios" == _OPTIONS["xcode"] then |
| 298 | |
| 299 | elseif "ios" == _OPTIONS["xcode"] then |
314 | 300 | premake.xcode.toolset = "iphoneos" |
315 | 301 | location (path.join(_buildDir, "projects", _ACTION .. "-ios")) |
316 | 302 | end |
r245333 | r245334 | |
760 | 746 | configuration { "osx", "x32" } |
761 | 747 | targetdir (path.join(_buildDir, "osx32_clang/bin")) |
762 | 748 | objdir (path.join(_buildDir, "osx32_clang/obj")) |
763 | | libdirs { path.join(_libDir, "lib/osx32_clang") } |
| 749 | --libdirs { path.join(_libDir, "lib/osx32_clang") } |
764 | 750 | buildoptions { |
765 | 751 | "-m32", |
766 | 752 | } |
r245333 | r245334 | |
768 | 754 | configuration { "osx", "x64" } |
769 | 755 | targetdir (path.join(_buildDir, "osx64_clang/bin")) |
770 | 756 | objdir (path.join(_buildDir, "osx64_clang/obj")) |
771 | | libdirs { path.join(_libDir, "lib/osx64_clang") } |
| 757 | --libdirs { path.join(_libDir, "lib/osx64_clang") } |
772 | 758 | buildoptions { |
773 | 759 | "-m64", |
774 | 760 | } |