| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 | 32 |
| 33 // This is the Soap Bubble sample / demo. It runs as a native client NPAPI | 33 // This is the Soap Bubble sample / demo. It runs as a native client NPAPI |
| 34 // plug-in. | 34 // plug-in. |
| 35 | 35 |
| 36 #include <math.h> | 36 #include <math.h> |
| 37 #include <stdint.h> | 37 #include <stdint.h> |
| 38 #ifdef __native_demo__ | 38 #ifdef __native_demo__ |
| 39 #include <sys/nacl_syscalls.h> | 39 #include <sys/nacl_syscalls.h> |
| 40 #else | 40 #else |
| 41 #include "native_client/service_runtime/nrd_xfer_lib/nrd_all_modules.h" | 41 #include "native_client/src/shared/imc/nacl_imc.h" |
| 42 #endif | 42 #endif |
| 43 #include "command_buffer/common/cross/gapi_interface.h" | 43 #include "command_buffer/common/cross/gapi_interface.h" |
| 44 #include "command_buffer/common/cross/rpc_imc.h" | 44 #include "command_buffer/common/cross/rpc_imc.h" |
| 45 #include "command_buffer/client/cross/cmd_buffer_helper.h" | 45 #include "command_buffer/client/cross/cmd_buffer_helper.h" |
| 46 #include "command_buffer/client/cross/buffer_sync_proxy.h" | 46 #include "command_buffer/client/cross/buffer_sync_proxy.h" |
| 47 #include "command_buffer/client/cross/fenced_allocator.h" | 47 #include "command_buffer/client/cross/fenced_allocator.h" |
| 48 #include "command_buffer/samples/bubble/utils.h" | 48 #include "command_buffer/samples/bubble/utils.h" |
| 49 #include "command_buffer/samples/bubble/iridescence_texture.h" | 49 #include "command_buffer/samples/bubble/iridescence_texture.h" |
| 50 #include "command_buffer/samples/bubble/perlin_noise.h" | 50 #include "command_buffer/samples/bubble/perlin_noise.h" |
| 51 #include "third_party/vectormath/files/vectormathlibrary/include/vectormath/scal
ar/cpp/vectormath_aos.h" // NOLINT | 51 #include "third_party/vectormath/files/vectormathlibrary/include/vectormath/scal
ar/cpp/vectormath_aos.h" // NOLINT |
| 52 | 52 |
| 53 #include "native_client/intermodule_comm/nacl_imc.h" | 53 #include "native_client/src/shared/npruntime/nacl_npapi.h" |
| 54 #include "native_client/tools/npapi_runtime/nacl_npapi.h" | |
| 55 | 54 |
| 56 // Cube map data is hard-coded in cubemap.cc as a byte array. | 55 // Cube map data is hard-coded in cubemap.cc as a byte array. |
| 57 // Format is 64x64xBRGA, D3D face ordering (+X, -X, +Y, -Y, +Z, -Z). | 56 // Format is 64x64xBRGA, D3D face ordering (+X, -X, +Y, -Y, +Z, -Z). |
| 58 extern unsigned char g_cubemap_data[]; | 57 extern unsigned char g_cubemap_data[]; |
| 59 const unsigned int kCubeMapWidth = 64; | 58 const unsigned int kCubeMapWidth = 64; |
| 60 const unsigned int kCubeMapHeight = 64; | 59 const unsigned int kCubeMapHeight = 64; |
| 61 const unsigned int kCubeMapFaceSize = kCubeMapWidth * kCubeMapHeight * 4; | 60 const unsigned int kCubeMapFaceSize = kCubeMapWidth * kCubeMapHeight * 4; |
| 62 | 61 |
| 63 // Define this to debug command buffers: it will call Finish() and check for a | 62 // Define this to debug command buffers: it will call Finish() and check for a |
| 64 // parse error. If there was one, it will warn about it in the console window. | 63 // parse error. If there was one, it will warn about it in the console window. |
| 65 // #define DEBUG_CMD | 64 // #define DEBUG_CMD |
| 66 #ifdef DEBUG_CMD | 65 #ifdef DEBUG_CMD |
| 67 #define CHECK_ERROR(HELPER) do { \ | 66 #define CHECK_ERROR(HELPER) do { \ |
| 68 HELPER->Finish(); \ | 67 HELPER->Finish(); \ |
| 69 BufferSyncInterface::ParseError error = \ | 68 BufferSyncInterface::ParseError error = \ |
| 70 HELPER->interface()->GetParseError(); \ | 69 HELPER->interface()->GetParseError(); \ |
| 71 if (error != BufferSyncInterface::PARSE_NO_ERROR) { \ | 70 if (error != BufferSyncInterface::kParseNoError) { \ |
| 72 printf("CMD error %d at %s:%d\n", error, __FILE__, __LINE__); \ | 71 printf("CMD error %d at %s:%d\n", error, __FILE__, __LINE__); \ |
| 73 } \ | 72 } \ |
| 74 } while (false) | 73 } while (false) |
| 75 #else | 74 #else |
| 76 #define CHECK_ERROR(HELPER) do { } while (false) | 75 #define CHECK_ERROR(HELPER) do { } while (false) |
| 77 #endif | 76 #endif |
| 78 | 77 |
| 79 namespace Vectormath { | 78 namespace Vectormath { |
| 80 namespace Aos { | 79 namespace Aos { |
| 81 | 80 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 float depth, | 114 float depth, |
| 116 unsigned int stencil) { | 115 unsigned int stencil) { |
| 117 CommandBufferEntry args[7]; | 116 CommandBufferEntry args[7]; |
| 118 args[0].value_uint32 = buffers; | 117 args[0].value_uint32 = buffers; |
| 119 args[1].value_float = color.red; | 118 args[1].value_float = color.red; |
| 120 args[2].value_float = color.green; | 119 args[2].value_float = color.green; |
| 121 args[3].value_float = color.blue; | 120 args[3].value_float = color.blue; |
| 122 args[4].value_float = color.alpha; | 121 args[4].value_float = color.alpha; |
| 123 args[5].value_float = depth; | 122 args[5].value_float = depth; |
| 124 args[6].value_uint32 = stencil; | 123 args[6].value_uint32 = stencil; |
| 125 cmd_buffer->AddCommand(command_buffer::CLEAR, 7, args); | 124 cmd_buffer->AddCommand(command_buffer::kClear, 7, args); |
| 126 CHECK_ERROR(cmd_buffer); | 125 CHECK_ERROR(cmd_buffer); |
| 127 } | 126 } |
| 128 | 127 |
| 129 // Adds a SetViewport command into the buffer. | 128 // Adds a SetViewport command into the buffer. |
| 130 // Parameters: | 129 // Parameters: |
| 131 // cmd_buffer: the command buffer helper. | 130 // cmd_buffer: the command buffer helper. |
| 132 // x, y, width, height: the dimensions of the Viewport. | 131 // x, y, width, height: the dimensions of the Viewport. |
| 133 // z_near, z_far: the near and far clip plane distances. | 132 // z_near, z_far: the near and far clip plane distances. |
| 134 void SetViewportCmd(CommandBufferHelper *cmd_buffer, | 133 void SetViewportCmd(CommandBufferHelper *cmd_buffer, |
| 135 unsigned int x, | 134 unsigned int x, |
| 136 unsigned int y, | 135 unsigned int y, |
| 137 unsigned int width, | 136 unsigned int width, |
| 138 unsigned int height, | 137 unsigned int height, |
| 139 float z_near, | 138 float z_near, |
| 140 float z_far) { | 139 float z_far) { |
| 141 CommandBufferEntry args[6]; | 140 CommandBufferEntry args[6]; |
| 142 args[0].value_uint32 = x; | 141 args[0].value_uint32 = x; |
| 143 args[1].value_uint32 = y; | 142 args[1].value_uint32 = y; |
| 144 args[2].value_uint32 = width; | 143 args[2].value_uint32 = width; |
| 145 args[3].value_uint32 = height; | 144 args[3].value_uint32 = height; |
| 146 args[4].value_float = z_near; | 145 args[4].value_float = z_near; |
| 147 args[5].value_float = z_far; | 146 args[5].value_float = z_far; |
| 148 cmd_buffer->AddCommand(command_buffer::SET_VIEWPORT, 6, args); | 147 cmd_buffer->AddCommand(command_buffer::kSetViewport, 6, args); |
| 149 CHECK_ERROR(cmd_buffer); | 148 CHECK_ERROR(cmd_buffer); |
| 150 } | 149 } |
| 151 | 150 |
| 152 // Copy a data buffer to args, for IMMEDIATE commands. Returns the number of | 151 // Copy a data buffer to args, for IMMEDIATE commands. Returns the number of |
| 153 // args used. | 152 // args used. |
| 154 unsigned int CopyToArgs(CommandBufferEntry *args, | 153 unsigned int CopyToArgs(CommandBufferEntry *args, |
| 155 const void *data, | 154 const void *data, |
| 156 size_t size) { | 155 size_t size) { |
| 157 memcpy(args, data, size); | 156 memcpy(args, data, size); |
| 158 const unsigned int arg_size = sizeof(args[0]); | 157 const unsigned int arg_size = sizeof(args[0]); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 *texture++ = value; | 303 *texture++ = value; |
| 305 *texture++ = value; | 304 *texture++ = value; |
| 306 *texture++ = value; | 305 *texture++ = value; |
| 307 *texture++ = value; | 306 *texture++ = value; |
| 308 } | 307 } |
| 309 } | 308 } |
| 310 } | 309 } |
| 311 | 310 |
| 312 // Gets current time in microseconds. | 311 // Gets current time in microseconds. |
| 313 uint64_t GetTimeUsec() { | 312 uint64_t GetTimeUsec() { |
| 314 struct timeval tv; | 313 return 0ULL; |
| 315 gettimeofday(&tv, NULL); | 314 // struct timeval tv; |
| 316 return tv.tv_sec * 1000000ULL + tv.tv_usec; | 315 // gettimeofday(&tv, NULL); |
| 316 // return tv.tv_sec * 1000000ULL + tv.tv_usec; |
| 317 } | 317 } |
| 318 | 318 |
| 319 class BubbleDemo { | 319 class BubbleDemo { |
| 320 public: | 320 public: |
| 321 BubbleDemo(); | 321 BubbleDemo(); |
| 322 ~BubbleDemo() {} | 322 ~BubbleDemo() {} |
| 323 | 323 |
| 324 // Creates the socket pair for the connection. | 324 // Creates the socket pair for the connection. |
| 325 nacl::HtpHandle CreateSockets(); | 325 nacl::HtpHandle CreateSockets(); |
| 326 | 326 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 MakeIridescenceTexture(kTexWidth, kTexHeight, kRefractionIndex, | 478 MakeIridescenceTexture(kTexWidth, kTexHeight, kRefractionIndex, |
| 479 kRedWavelength, iridescence_texture_); | 479 kRedWavelength, iridescence_texture_); |
| 480 | 480 |
| 481 // Clear the buffers. | 481 // Clear the buffers. |
| 482 RGBA color = {0.f, 0.f, 0.f, 1.f}; | 482 RGBA color = {0.f, 0.f, 0.f, 1.f}; |
| 483 ClearCmd(helper_.get(), GAPIInterface::COLOR | GAPIInterface::DEPTH, color, | 483 ClearCmd(helper_.get(), GAPIInterface::COLOR | GAPIInterface::DEPTH, color, |
| 484 1.f, 0); | 484 1.f, 0); |
| 485 | 485 |
| 486 // AddCommand copies the args, so it is safe to re-use args across various | 486 // AddCommand copies the args, so it is safe to re-use args across various |
| 487 // calls. | 487 // calls. |
| 488 // 20 is the largest command we use (SET_PARAM_DATA_IMMEDIATE for matrices). | 488 // 20 is the largest command we use (SetParamDataImmediate for matrices). |
| 489 CommandBufferEntry args[20]; | 489 CommandBufferEntry args[20]; |
| 490 | 490 |
| 491 // Create geometry arrays and structures | 491 // Create geometry arrays and structures |
| 492 args[0].value_uint32 = vertex_buffer_id_; | 492 args[0].value_uint32 = vertex_buffer_id_; |
| 493 args[1].value_uint32 = kVertexBufferSize; // size | 493 args[1].value_uint32 = kVertexBufferSize; // size |
| 494 args[2].value_uint32 = 0; // flags | 494 args[2].value_uint32 = 0; // flags |
| 495 helper_->AddCommand(CREATE_VERTEX_BUFFER, 3, args); | 495 helper_->AddCommand(CreateVertexBuffer, 3, args); |
| 496 CHECK_ERROR(helper_); | 496 CHECK_ERROR(helper_); |
| 497 | 497 |
| 498 args[0].value_uint32 = vertex_buffer_id_; | 498 args[0].value_uint32 = vertex_buffer_id_; |
| 499 args[1].value_uint32 = 0; // offset in VB | 499 args[1].value_uint32 = 0; // offset in VB |
| 500 args[2].value_uint32 = kVertexBufferSize; // size | 500 args[2].value_uint32 = kVertexBufferSize; // size |
| 501 args[3].value_uint32 = shm_id_; // shm | 501 args[3].value_uint32 = shm_id_; // shm |
| 502 args[4].value_uint32 = allocator_->GetOffset(vertices_); // offset in shm | 502 args[4].value_uint32 = allocator_->GetOffset(vertices_); // offset in shm |
| 503 helper_->AddCommand(SET_VERTEX_BUFFER_DATA, 5, args); | 503 helper_->AddCommand(SetVertexBufferData, 5, args); |
| 504 CHECK_ERROR(helper_); | 504 CHECK_ERROR(helper_); |
| 505 | 505 |
| 506 args[0].value_uint32 = index_buffer_id_; | 506 args[0].value_uint32 = index_buffer_id_; |
| 507 args[1].value_uint32 = kIndexBufferSize; // size | 507 args[1].value_uint32 = kIndexBufferSize; // size |
| 508 args[2].value_uint32 = index_buffer::INDEX_32BIT; // flags | 508 args[2].value_uint32 = index_buffer::INDEX_32BIT; // flags |
| 509 helper_->AddCommand(CREATE_INDEX_BUFFER, 3, args); | 509 helper_->AddCommand(CreateIndexBuffer, 3, args); |
| 510 CHECK_ERROR(helper_); | 510 CHECK_ERROR(helper_); |
| 511 | 511 |
| 512 args[0].value_uint32 = index_buffer_id_; | 512 args[0].value_uint32 = index_buffer_id_; |
| 513 args[1].value_uint32 = 0; // offset in IB | 513 args[1].value_uint32 = 0; // offset in IB |
| 514 args[2].value_uint32 = kIndexBufferSize; // size | 514 args[2].value_uint32 = kIndexBufferSize; // size |
| 515 args[3].value_uint32 = shm_id_; // shm | 515 args[3].value_uint32 = shm_id_; // shm |
| 516 args[4].value_uint32 = allocator_->GetOffset(indices_); // offset in shm | 516 args[4].value_uint32 = allocator_->GetOffset(indices_); // offset in shm |
| 517 helper_->AddCommand(SET_INDEX_BUFFER_DATA, 5, args); | 517 helper_->AddCommand(SetIndexBufferData, 5, args); |
| 518 CHECK_ERROR(helper_); | 518 CHECK_ERROR(helper_); |
| 519 | 519 |
| 520 args[0].value_uint32 = vertex_struct_id_; | 520 args[0].value_uint32 = vertex_struct_id_; |
| 521 args[1].value_uint32 = 3; // input count | 521 args[1].value_uint32 = 3; // input count |
| 522 helper_->AddCommand(CREATE_VERTEX_STRUCT, 2, args); | 522 helper_->AddCommand(CreateVertexStruct, 2, args); |
| 523 CHECK_ERROR(helper_); | 523 CHECK_ERROR(helper_); |
| 524 | 524 |
| 525 // Set POSITION input stream | 525 // Set POSITION input stream |
| 526 args[0].value_uint32 = vertex_struct_id_; | 526 args[0].value_uint32 = vertex_struct_id_; |
| 527 args[1].value_uint32 = 0; // input | 527 args[1].value_uint32 = 0; // input |
| 528 args[2].value_uint32 = vertex_buffer_id_; // buffer | 528 args[2].value_uint32 = vertex_buffer_id_; // buffer |
| 529 args[3].value_uint32 = 0; // offset | 529 args[3].value_uint32 = 0; // offset |
| 530 args[4].value_uint32 = | 530 args[4].value_uint32 = |
| 531 set_vertex_input_cmd::Stride::MakeValue(sizeof(CustomVertex)) | | 531 set_vertex_input_cmd::Stride::MakeValue(sizeof(CustomVertex)) | |
| 532 set_vertex_input_cmd::Type::MakeValue(vertex_struct::FLOAT3) | | 532 set_vertex_input_cmd::Type::MakeValue(vertex_struct::FLOAT3) | |
| 533 set_vertex_input_cmd::Semantic::MakeValue(vertex_struct::POSITION) | | 533 set_vertex_input_cmd::Semantic::MakeValue(vertex_struct::POSITION) | |
| 534 set_vertex_input_cmd::SemanticIndex::MakeValue(0); | 534 set_vertex_input_cmd::SemanticIndex::MakeValue(0); |
| 535 helper_->AddCommand(SET_VERTEX_INPUT, 5, args); | 535 helper_->AddCommand(SetVertexInput, 5, args); |
| 536 CHECK_ERROR(helper_); | 536 CHECK_ERROR(helper_); |
| 537 | 537 |
| 538 // Set NORMAL input stream | 538 // Set NORMAL input stream |
| 539 args[1].value_uint32 = 1; // input | 539 args[1].value_uint32 = 1; // input |
| 540 args[3].value_uint32 = 12; // offset | 540 args[3].value_uint32 = 12; // offset |
| 541 args[4].value_uint32 = | 541 args[4].value_uint32 = |
| 542 set_vertex_input_cmd::Stride::MakeValue(sizeof(CustomVertex)) | | 542 set_vertex_input_cmd::Stride::MakeValue(sizeof(CustomVertex)) | |
| 543 set_vertex_input_cmd::Type::MakeValue(vertex_struct::FLOAT3) | | 543 set_vertex_input_cmd::Type::MakeValue(vertex_struct::FLOAT3) | |
| 544 set_vertex_input_cmd::Semantic::MakeValue(vertex_struct::NORMAL) | | 544 set_vertex_input_cmd::Semantic::MakeValue(vertex_struct::NORMAL) | |
| 545 set_vertex_input_cmd::SemanticIndex::MakeValue(0); | 545 set_vertex_input_cmd::SemanticIndex::MakeValue(0); |
| 546 helper_->AddCommand(SET_VERTEX_INPUT, 5, args); | 546 helper_->AddCommand(SetVertexInput, 5, args); |
| 547 CHECK_ERROR(helper_); | 547 CHECK_ERROR(helper_); |
| 548 | 548 |
| 549 // Set TEXCOORD0 input stream | 549 // Set TEXCOORD0 input stream |
| 550 args[1].value_uint32 = 2; // input | 550 args[1].value_uint32 = 2; // input |
| 551 args[3].value_uint32 = 24; // offset | 551 args[3].value_uint32 = 24; // offset |
| 552 args[4].value_uint32 = | 552 args[4].value_uint32 = |
| 553 set_vertex_input_cmd::Stride::MakeValue(sizeof(CustomVertex)) | | 553 set_vertex_input_cmd::Stride::MakeValue(sizeof(CustomVertex)) | |
| 554 set_vertex_input_cmd::Type::MakeValue(vertex_struct::FLOAT2) | | 554 set_vertex_input_cmd::Type::MakeValue(vertex_struct::FLOAT2) | |
| 555 set_vertex_input_cmd::Semantic::MakeValue(vertex_struct::TEX_COORD) | | 555 set_vertex_input_cmd::Semantic::MakeValue(vertex_struct::TEX_COORD) | |
| 556 set_vertex_input_cmd::SemanticIndex::MakeValue(0); | 556 set_vertex_input_cmd::SemanticIndex::MakeValue(0); |
| 557 helper_->AddCommand(SET_VERTEX_INPUT, 5, args); | 557 helper_->AddCommand(SetVertexInput, 5, args); |
| 558 CHECK_ERROR(helper_); | 558 CHECK_ERROR(helper_); |
| 559 | 559 |
| 560 // Create a 2D texture. | 560 // Create a 2D texture. |
| 561 args[0].value_uint32 = noise_texture_id_; | 561 args[0].value_uint32 = noise_texture_id_; |
| 562 args[1].value_uint32 = | 562 args[1].value_uint32 = |
| 563 create_texture_2d_cmd::Width::MakeValue(kTexWidth) | | 563 create_texture_2d_cmd::Width::MakeValue(kTexWidth) | |
| 564 create_texture_2d_cmd::Height::MakeValue(kTexHeight); | 564 create_texture_2d_cmd::Height::MakeValue(kTexHeight); |
| 565 args[2].value_uint32 = | 565 args[2].value_uint32 = |
| 566 create_texture_2d_cmd::Levels::MakeValue(0) | | 566 create_texture_2d_cmd::Levels::MakeValue(0) | |
| 567 create_texture_2d_cmd::Format::MakeValue(texture::ARGB8) | | 567 create_texture_2d_cmd::Format::MakeValue(texture::ARGB8) | |
| 568 create_texture_2d_cmd::Flags::MakeValue(0); | 568 create_texture_2d_cmd::Flags::MakeValue(0); |
| 569 helper_->AddCommand(CREATE_TEXTURE_2D, 3, args); | 569 helper_->AddCommand(CreateTexture2d, 3, args); |
| 570 CHECK_ERROR(helper_); | 570 CHECK_ERROR(helper_); |
| 571 | 571 |
| 572 args[0].value_uint32 = noise_texture_id_; | 572 args[0].value_uint32 = noise_texture_id_; |
| 573 args[1].value_uint32 = | 573 args[1].value_uint32 = |
| 574 set_texture_data_cmd::X::MakeValue(0) | | 574 set_texture_data_cmd::X::MakeValue(0) | |
| 575 set_texture_data_cmd::Y::MakeValue(0); | 575 set_texture_data_cmd::Y::MakeValue(0); |
| 576 args[2].value_uint32 = | 576 args[2].value_uint32 = |
| 577 set_texture_data_cmd::Width::MakeValue(kTexWidth) | | 577 set_texture_data_cmd::Width::MakeValue(kTexWidth) | |
| 578 set_texture_data_cmd::Height::MakeValue(kTexHeight); | 578 set_texture_data_cmd::Height::MakeValue(kTexHeight); |
| 579 args[3].value_uint32 = | 579 args[3].value_uint32 = |
| 580 set_texture_data_cmd::Z::MakeValue(0) | | 580 set_texture_data_cmd::Z::MakeValue(0) | |
| 581 set_texture_data_cmd::Depth::MakeValue(1); | 581 set_texture_data_cmd::Depth::MakeValue(1); |
| 582 args[4].value_uint32 = set_texture_data_cmd::Level::MakeValue(0); | 582 args[4].value_uint32 = set_texture_data_cmd::Level::MakeValue(0); |
| 583 args[5].value_uint32 = kTexWidth * 4; // row_pitch | 583 args[5].value_uint32 = kTexWidth * 4; // row_pitch |
| 584 args[6].value_uint32 = 0; // slice_pitch | 584 args[6].value_uint32 = 0; // slice_pitch |
| 585 args[7].value_uint32 = kTexSize; // size | 585 args[7].value_uint32 = kTexSize; // size |
| 586 args[8].value_uint32 = shm_id_; | 586 args[8].value_uint32 = shm_id_; |
| 587 args[9].value_uint32 = allocator_->GetOffset(noise_texture_); | 587 args[9].value_uint32 = allocator_->GetOffset(noise_texture_); |
| 588 helper_->AddCommand(SET_TEXTURE_DATA, 10, args); | 588 helper_->AddCommand(SetTextureData, 10, args); |
| 589 CHECK_ERROR(helper_); | 589 CHECK_ERROR(helper_); |
| 590 | 590 |
| 591 args[0].value_uint32 = noise_sampler_id_; | 591 args[0].value_uint32 = noise_sampler_id_; |
| 592 helper_->AddCommand(CREATE_SAMPLER, 1, args); | 592 helper_->AddCommand(CreateSampler, 1, args); |
| 593 CHECK_ERROR(helper_); | 593 CHECK_ERROR(helper_); |
| 594 | 594 |
| 595 args[0].value_uint32 = noise_sampler_id_; | 595 args[0].value_uint32 = noise_sampler_id_; |
| 596 args[1].value_uint32 = noise_texture_id_; | 596 args[1].value_uint32 = noise_texture_id_; |
| 597 helper_->AddCommand(SET_SAMPLER_TEXTURE, 2, args); | 597 helper_->AddCommand(SetSamplerTexture, 2, args); |
| 598 CHECK_ERROR(helper_); | 598 CHECK_ERROR(helper_); |
| 599 | 599 |
| 600 args[0].value_uint32 = noise_sampler_id_; | 600 args[0].value_uint32 = noise_sampler_id_; |
| 601 args[1].value_uint32 = | 601 args[1].value_uint32 = |
| 602 set_sampler_states::AddressingU::MakeValue(sampler::WRAP) | | 602 set_sampler_states::AddressingU::MakeValue(sampler::WRAP) | |
| 603 set_sampler_states::AddressingV::MakeValue(sampler::WRAP) | | 603 set_sampler_states::AddressingV::MakeValue(sampler::WRAP) | |
| 604 set_sampler_states::AddressingW::MakeValue(sampler::WRAP) | | 604 set_sampler_states::AddressingW::MakeValue(sampler::WRAP) | |
| 605 set_sampler_states::MagFilter::MakeValue(sampler::LINEAR) | | 605 set_sampler_states::MagFilter::MakeValue(sampler::LINEAR) | |
| 606 set_sampler_states::MinFilter::MakeValue(sampler::LINEAR) | | 606 set_sampler_states::MinFilter::MakeValue(sampler::LINEAR) | |
| 607 set_sampler_states::MipFilter::MakeValue(sampler::NONE) | | 607 set_sampler_states::MipFilter::MakeValue(sampler::NONE) | |
| 608 set_sampler_states::MaxAnisotropy::MakeValue(1); | 608 set_sampler_states::MaxAnisotropy::MakeValue(1); |
| 609 helper_->AddCommand(SET_SAMPLER_STATES, 2, args); | 609 helper_->AddCommand(SetSamplerStates, 2, args); |
| 610 CHECK_ERROR(helper_); | 610 CHECK_ERROR(helper_); |
| 611 | 611 |
| 612 // Create a 2D texture. | 612 // Create a 2D texture. |
| 613 args[0].value_uint32 = iridescence_texture_id_; | 613 args[0].value_uint32 = iridescence_texture_id_; |
| 614 args[1].value_uint32 = | 614 args[1].value_uint32 = |
| 615 create_texture_2d_cmd::Width::MakeValue(kTexWidth) | | 615 create_texture_2d_cmd::Width::MakeValue(kTexWidth) | |
| 616 create_texture_2d_cmd::Height::MakeValue(kTexHeight); | 616 create_texture_2d_cmd::Height::MakeValue(kTexHeight); |
| 617 args[2].value_uint32 = | 617 args[2].value_uint32 = |
| 618 create_texture_2d_cmd::Levels::MakeValue(0) | | 618 create_texture_2d_cmd::Levels::MakeValue(0) | |
| 619 create_texture_2d_cmd::Format::MakeValue(texture::ARGB8) | | 619 create_texture_2d_cmd::Format::MakeValue(texture::ARGB8) | |
| 620 create_texture_2d_cmd::Flags::MakeValue(0); | 620 create_texture_2d_cmd::Flags::MakeValue(0); |
| 621 helper_->AddCommand(CREATE_TEXTURE_2D, 3, args); | 621 helper_->AddCommand(CreateTexture2d, 3, args); |
| 622 CHECK_ERROR(helper_); | 622 CHECK_ERROR(helper_); |
| 623 | 623 |
| 624 args[0].value_uint32 = iridescence_texture_id_; | 624 args[0].value_uint32 = iridescence_texture_id_; |
| 625 args[1].value_uint32 = | 625 args[1].value_uint32 = |
| 626 set_texture_data_cmd::X::MakeValue(0) | | 626 set_texture_data_cmd::X::MakeValue(0) | |
| 627 set_texture_data_cmd::Y::MakeValue(0); | 627 set_texture_data_cmd::Y::MakeValue(0); |
| 628 args[2].value_uint32 = | 628 args[2].value_uint32 = |
| 629 set_texture_data_cmd::Width::MakeValue(kTexWidth) | | 629 set_texture_data_cmd::Width::MakeValue(kTexWidth) | |
| 630 set_texture_data_cmd::Height::MakeValue(kTexHeight); | 630 set_texture_data_cmd::Height::MakeValue(kTexHeight); |
| 631 args[3].value_uint32 = | 631 args[3].value_uint32 = |
| 632 set_texture_data_cmd::Z::MakeValue(0) | | 632 set_texture_data_cmd::Z::MakeValue(0) | |
| 633 set_texture_data_cmd::Depth::MakeValue(1); | 633 set_texture_data_cmd::Depth::MakeValue(1); |
| 634 args[4].value_uint32 = set_texture_data_cmd::Level::MakeValue(0); | 634 args[4].value_uint32 = set_texture_data_cmd::Level::MakeValue(0); |
| 635 args[5].value_uint32 = kTexWidth * 4; // row_pitch | 635 args[5].value_uint32 = kTexWidth * 4; // row_pitch |
| 636 args[6].value_uint32 = 0; // slice_pitch | 636 args[6].value_uint32 = 0; // slice_pitch |
| 637 args[7].value_uint32 = kTexSize; // size | 637 args[7].value_uint32 = kTexSize; // size |
| 638 args[8].value_uint32 = shm_id_; | 638 args[8].value_uint32 = shm_id_; |
| 639 args[9].value_uint32 = allocator_->GetOffset(iridescence_texture_); | 639 args[9].value_uint32 = allocator_->GetOffset(iridescence_texture_); |
| 640 helper_->AddCommand(SET_TEXTURE_DATA, 10, args); | 640 helper_->AddCommand(SetTextureData, 10, args); |
| 641 CHECK_ERROR(helper_); | 641 CHECK_ERROR(helper_); |
| 642 | 642 |
| 643 args[0].value_uint32 = iridescence_sampler_id_; | 643 args[0].value_uint32 = iridescence_sampler_id_; |
| 644 helper_->AddCommand(CREATE_SAMPLER, 1, args); | 644 helper_->AddCommand(CreateSampler, 1, args); |
| 645 CHECK_ERROR(helper_); | 645 CHECK_ERROR(helper_); |
| 646 | 646 |
| 647 args[0].value_uint32 = iridescence_sampler_id_; | 647 args[0].value_uint32 = iridescence_sampler_id_; |
| 648 args[1].value_uint32 = iridescence_texture_id_; | 648 args[1].value_uint32 = iridescence_texture_id_; |
| 649 helper_->AddCommand(SET_SAMPLER_TEXTURE, 2, args); | 649 helper_->AddCommand(SetSamplerTexture, 2, args); |
| 650 CHECK_ERROR(helper_); | 650 CHECK_ERROR(helper_); |
| 651 | 651 |
| 652 args[0].value_uint32 = iridescence_sampler_id_; | 652 args[0].value_uint32 = iridescence_sampler_id_; |
| 653 args[1].value_uint32 = | 653 args[1].value_uint32 = |
| 654 set_sampler_states::AddressingU::MakeValue(sampler::CLAMP_TO_EDGE) | | 654 set_sampler_states::AddressingU::MakeValue(sampler::CLAMP_TO_EDGE) | |
| 655 set_sampler_states::AddressingV::MakeValue(sampler::CLAMP_TO_EDGE) | | 655 set_sampler_states::AddressingV::MakeValue(sampler::CLAMP_TO_EDGE) | |
| 656 set_sampler_states::AddressingW::MakeValue(sampler::CLAMP_TO_EDGE) | | 656 set_sampler_states::AddressingW::MakeValue(sampler::CLAMP_TO_EDGE) | |
| 657 set_sampler_states::MagFilter::MakeValue(sampler::LINEAR) | | 657 set_sampler_states::MagFilter::MakeValue(sampler::LINEAR) | |
| 658 set_sampler_states::MinFilter::MakeValue(sampler::LINEAR) | | 658 set_sampler_states::MinFilter::MakeValue(sampler::LINEAR) | |
| 659 set_sampler_states::MipFilter::MakeValue(sampler::NONE) | | 659 set_sampler_states::MipFilter::MakeValue(sampler::NONE) | |
| 660 set_sampler_states::MaxAnisotropy::MakeValue(1); | 660 set_sampler_states::MaxAnisotropy::MakeValue(1); |
| 661 helper_->AddCommand(SET_SAMPLER_STATES, 2, args); | 661 helper_->AddCommand(SetSamplerStates, 2, args); |
| 662 CHECK_ERROR(helper_); | 662 CHECK_ERROR(helper_); |
| 663 | 663 |
| 664 // Create a Cubemap texture. | 664 // Create a Cubemap texture. |
| 665 args[0].value_uint32 = cubemap_id_; | 665 args[0].value_uint32 = cubemap_id_; |
| 666 args[1].value_uint32 = | 666 args[1].value_uint32 = |
| 667 create_texture_cube_cmd::Side::MakeValue(kCubeMapWidth); | 667 create_texture_cube_cmd::Side::MakeValue(kCubeMapWidth); |
| 668 args[2].value_uint32 = | 668 args[2].value_uint32 = |
| 669 create_texture_cube_cmd::Levels::MakeValue(0) | | 669 create_texture_cube_cmd::Levels::MakeValue(0) | |
| 670 create_texture_cube_cmd::Format::MakeValue(texture::ARGB8) | | 670 create_texture_cube_cmd::Format::MakeValue(texture::ARGB8) | |
| 671 create_texture_cube_cmd::Flags::MakeValue(0); | 671 create_texture_cube_cmd::Flags::MakeValue(0); |
| 672 helper_->AddCommand(CREATE_TEXTURE_CUBE, 3, args); | 672 helper_->AddCommand(CreateTextureCube, 3, args); |
| 673 CHECK_ERROR(helper_); | 673 CHECK_ERROR(helper_); |
| 674 | 674 |
| 675 for (unsigned int face = 0; face < 6; ++face) { | 675 for (unsigned int face = 0; face < 6; ++face) { |
| 676 void *data = allocator_->Alloc(kCubeMapFaceSize); | 676 void *data = allocator_->Alloc(kCubeMapFaceSize); |
| 677 memcpy(data, g_cubemap_data + face*kCubeMapFaceSize, kCubeMapFaceSize); | 677 memcpy(data, g_cubemap_data + face*kCubeMapFaceSize, kCubeMapFaceSize); |
| 678 args[0].value_uint32 = cubemap_id_; | 678 args[0].value_uint32 = cubemap_id_; |
| 679 args[1].value_uint32 = | 679 args[1].value_uint32 = |
| 680 set_texture_data_cmd::X::MakeValue(0) | | 680 set_texture_data_cmd::X::MakeValue(0) | |
| 681 set_texture_data_cmd::Y::MakeValue(0); | 681 set_texture_data_cmd::Y::MakeValue(0); |
| 682 args[2].value_uint32 = | 682 args[2].value_uint32 = |
| 683 set_texture_data_cmd::Width::MakeValue(kCubeMapWidth) | | 683 set_texture_data_cmd::Width::MakeValue(kCubeMapWidth) | |
| 684 set_texture_data_cmd::Height::MakeValue(kCubeMapHeight); | 684 set_texture_data_cmd::Height::MakeValue(kCubeMapHeight); |
| 685 args[3].value_uint32 = | 685 args[3].value_uint32 = |
| 686 set_texture_data_cmd::Z::MakeValue(0) | | 686 set_texture_data_cmd::Z::MakeValue(0) | |
| 687 set_texture_data_cmd::Depth::MakeValue(1); | 687 set_texture_data_cmd::Depth::MakeValue(1); |
| 688 args[4].value_uint32 = | 688 args[4].value_uint32 = |
| 689 set_texture_data_cmd::Level::MakeValue(0) | | 689 set_texture_data_cmd::Level::MakeValue(0) | |
| 690 set_texture_data_cmd::Face::MakeValue(face); | 690 set_texture_data_cmd::Face::MakeValue(face); |
| 691 args[5].value_uint32 = kCubeMapWidth * 4; // row_pitch | 691 args[5].value_uint32 = kCubeMapWidth * 4; // row_pitch |
| 692 args[6].value_uint32 = 0; // slice_pitch | 692 args[6].value_uint32 = 0; // slice_pitch |
| 693 args[7].value_uint32 = kCubeMapFaceSize; // size | 693 args[7].value_uint32 = kCubeMapFaceSize; // size |
| 694 args[8].value_uint32 = shm_id_; | 694 args[8].value_uint32 = shm_id_; |
| 695 args[9].value_uint32 = allocator_->GetOffset(data); | 695 args[9].value_uint32 = allocator_->GetOffset(data); |
| 696 helper_->AddCommand(SET_TEXTURE_DATA, 10, args); | 696 helper_->AddCommand(SetTextureData, 10, args); |
| 697 CHECK_ERROR(helper_); | 697 CHECK_ERROR(helper_); |
| 698 allocator_->FreePendingToken(data, helper_->InsertToken()); | 698 allocator_->FreePendingToken(data, helper_->InsertToken()); |
| 699 } | 699 } |
| 700 | 700 |
| 701 args[0].value_uint32 = cubemap_sampler_id_; | 701 args[0].value_uint32 = cubemap_sampler_id_; |
| 702 helper_->AddCommand(CREATE_SAMPLER, 1, args); | 702 helper_->AddCommand(CreateSampler, 1, args); |
| 703 CHECK_ERROR(helper_); | 703 CHECK_ERROR(helper_); |
| 704 | 704 |
| 705 args[0].value_uint32 = cubemap_sampler_id_; | 705 args[0].value_uint32 = cubemap_sampler_id_; |
| 706 args[1].value_uint32 = cubemap_id_; | 706 args[1].value_uint32 = cubemap_id_; |
| 707 helper_->AddCommand(SET_SAMPLER_TEXTURE, 2, args); | 707 helper_->AddCommand(SetSamplerTexture, 2, args); |
| 708 CHECK_ERROR(helper_); | 708 CHECK_ERROR(helper_); |
| 709 | 709 |
| 710 args[0].value_uint32 = cubemap_sampler_id_; | 710 args[0].value_uint32 = cubemap_sampler_id_; |
| 711 args[1].value_uint32 = | 711 args[1].value_uint32 = |
| 712 set_sampler_states::AddressingU::MakeValue(sampler::CLAMP_TO_EDGE) | | 712 set_sampler_states::AddressingU::MakeValue(sampler::CLAMP_TO_EDGE) | |
| 713 set_sampler_states::AddressingV::MakeValue(sampler::CLAMP_TO_EDGE) | | 713 set_sampler_states::AddressingV::MakeValue(sampler::CLAMP_TO_EDGE) | |
| 714 set_sampler_states::AddressingW::MakeValue(sampler::CLAMP_TO_EDGE) | | 714 set_sampler_states::AddressingW::MakeValue(sampler::CLAMP_TO_EDGE) | |
| 715 set_sampler_states::MagFilter::MakeValue(sampler::LINEAR) | | 715 set_sampler_states::MagFilter::MakeValue(sampler::LINEAR) | |
| 716 set_sampler_states::MinFilter::MakeValue(sampler::LINEAR) | | 716 set_sampler_states::MinFilter::MakeValue(sampler::LINEAR) | |
| 717 set_sampler_states::MipFilter::MakeValue(sampler::NONE) | | 717 set_sampler_states::MipFilter::MakeValue(sampler::NONE) | |
| 718 set_sampler_states::MaxAnisotropy::MakeValue(1); | 718 set_sampler_states::MaxAnisotropy::MakeValue(1); |
| 719 helper_->AddCommand(SET_SAMPLER_STATES, 2, args); | 719 helper_->AddCommand(SetSamplerStates, 2, args); |
| 720 CHECK_ERROR(helper_); | 720 CHECK_ERROR(helper_); |
| 721 | 721 |
| 722 // Create the effect, and parameters. | 722 // Create the effect, and parameters. |
| 723 void *data = allocator_->Alloc(sizeof(effect_data)); | 723 void *data = allocator_->Alloc(sizeof(effect_data)); |
| 724 memcpy(data, effect_data, sizeof(effect_data)); | 724 memcpy(data, effect_data, sizeof(effect_data)); |
| 725 args[0].value_uint32 = effect_id_; | 725 args[0].value_uint32 = effect_id_; |
| 726 args[1].value_uint32 = sizeof(effect_data); // size | 726 args[1].value_uint32 = sizeof(effect_data); // size |
| 727 args[2].value_uint32 = shm_id_; // shm | 727 args[2].value_uint32 = shm_id_; // shm |
| 728 args[3].value_uint32 = allocator_->GetOffset(data); // offset in shm | 728 args[3].value_uint32 = allocator_->GetOffset(data); // offset in shm |
| 729 helper_->AddCommand(CREATE_EFFECT, 4, args); | 729 helper_->AddCommand(CreateEffect, 4, args); |
| 730 CHECK_ERROR(helper_); | 730 CHECK_ERROR(helper_); |
| 731 allocator_->FreePendingToken(data, helper_->InsertToken()); | 731 allocator_->FreePendingToken(data, helper_->InsertToken()); |
| 732 | 732 |
| 733 { | 733 { |
| 734 const char param_name[] = "noise_sampler"; | 734 const char param_name[] = "noise_sampler"; |
| 735 args[0].value_uint32 = noise_sampler_param_id_; | 735 args[0].value_uint32 = noise_sampler_param_id_; |
| 736 args[1].value_uint32 = effect_id_; | 736 args[1].value_uint32 = effect_id_; |
| 737 args[2].value_uint32 = sizeof(param_name); | 737 args[2].value_uint32 = sizeof(param_name); |
| 738 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 738 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 739 sizeof(param_name)); | 739 sizeof(param_name)); |
| 740 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 740 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 741 CHECK_ERROR(helper_); | 741 CHECK_ERROR(helper_); |
| 742 } | 742 } |
| 743 | 743 |
| 744 { | 744 { |
| 745 const char param_name[] = "iridescence_sampler"; | 745 const char param_name[] = "iridescence_sampler"; |
| 746 args[0].value_uint32 = iridescence_sampler_param_id_; | 746 args[0].value_uint32 = iridescence_sampler_param_id_; |
| 747 args[1].value_uint32 = effect_id_; | 747 args[1].value_uint32 = effect_id_; |
| 748 args[2].value_uint32 = sizeof(param_name); | 748 args[2].value_uint32 = sizeof(param_name); |
| 749 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 749 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 750 sizeof(param_name)); | 750 sizeof(param_name)); |
| 751 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 751 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 752 CHECK_ERROR(helper_); | 752 CHECK_ERROR(helper_); |
| 753 } | 753 } |
| 754 | 754 |
| 755 { | 755 { |
| 756 const char param_name[] = "env_sampler"; | 756 const char param_name[] = "env_sampler"; |
| 757 args[0].value_uint32 = cubemap_sampler_param_id_; | 757 args[0].value_uint32 = cubemap_sampler_param_id_; |
| 758 args[1].value_uint32 = effect_id_; | 758 args[1].value_uint32 = effect_id_; |
| 759 args[2].value_uint32 = sizeof(param_name); | 759 args[2].value_uint32 = sizeof(param_name); |
| 760 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 760 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 761 sizeof(param_name)); | 761 sizeof(param_name)); |
| 762 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 762 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 763 CHECK_ERROR(helper_); | 763 CHECK_ERROR(helper_); |
| 764 } | 764 } |
| 765 | 765 |
| 766 { | 766 { |
| 767 const char param_name[] = "worldViewProj"; | 767 const char param_name[] = "worldViewProj"; |
| 768 args[0].value_uint32 = mvp_param_id_; | 768 args[0].value_uint32 = mvp_param_id_; |
| 769 args[1].value_uint32 = effect_id_; | 769 args[1].value_uint32 = effect_id_; |
| 770 args[2].value_uint32 = sizeof(param_name); | 770 args[2].value_uint32 = sizeof(param_name); |
| 771 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 771 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 772 sizeof(param_name)); | 772 sizeof(param_name)); |
| 773 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 773 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 774 CHECK_ERROR(helper_); | 774 CHECK_ERROR(helper_); |
| 775 } | 775 } |
| 776 | 776 |
| 777 { | 777 { |
| 778 const char param_name[] = "world"; | 778 const char param_name[] = "world"; |
| 779 args[0].value_uint32 = world_param_id_; | 779 args[0].value_uint32 = world_param_id_; |
| 780 args[1].value_uint32 = effect_id_; | 780 args[1].value_uint32 = effect_id_; |
| 781 args[2].value_uint32 = sizeof(param_name); | 781 args[2].value_uint32 = sizeof(param_name); |
| 782 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 782 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 783 sizeof(param_name)); | 783 sizeof(param_name)); |
| 784 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 784 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 785 CHECK_ERROR(helper_); | 785 CHECK_ERROR(helper_); |
| 786 } | 786 } |
| 787 | 787 |
| 788 { | 788 { |
| 789 const char param_name[] = "worldIT"; | 789 const char param_name[] = "worldIT"; |
| 790 args[0].value_uint32 = worldIT_param_id_; | 790 args[0].value_uint32 = worldIT_param_id_; |
| 791 args[1].value_uint32 = effect_id_; | 791 args[1].value_uint32 = effect_id_; |
| 792 args[2].value_uint32 = sizeof(param_name); | 792 args[2].value_uint32 = sizeof(param_name); |
| 793 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 793 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 794 sizeof(param_name)); | 794 sizeof(param_name)); |
| 795 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 795 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 796 CHECK_ERROR(helper_); | 796 CHECK_ERROR(helper_); |
| 797 } | 797 } |
| 798 | 798 |
| 799 { | 799 { |
| 800 const char param_name[] = "eye"; | 800 const char param_name[] = "eye"; |
| 801 args[0].value_uint32 = eye_param_id_; | 801 args[0].value_uint32 = eye_param_id_; |
| 802 args[1].value_uint32 = effect_id_; | 802 args[1].value_uint32 = effect_id_; |
| 803 args[2].value_uint32 = sizeof(param_name); | 803 args[2].value_uint32 = sizeof(param_name); |
| 804 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 804 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 805 sizeof(param_name)); | 805 sizeof(param_name)); |
| 806 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 806 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 807 CHECK_ERROR(helper_); | 807 CHECK_ERROR(helper_); |
| 808 } | 808 } |
| 809 | 809 |
| 810 { | 810 { |
| 811 const char param_name[] = "thickness_params"; | 811 const char param_name[] = "thickness_params"; |
| 812 args[0].value_uint32 = thickness_param_id_; | 812 args[0].value_uint32 = thickness_param_id_; |
| 813 args[1].value_uint32 = effect_id_; | 813 args[1].value_uint32 = effect_id_; |
| 814 args[2].value_uint32 = sizeof(param_name); | 814 args[2].value_uint32 = sizeof(param_name); |
| 815 unsigned int arg_count = CopyToArgs(args + 3, param_name, | 815 unsigned int arg_count = CopyToArgs(args + 3, param_name, |
| 816 sizeof(param_name)); | 816 sizeof(param_name)); |
| 817 helper_->AddCommand(CREATE_PARAM_BY_NAME_IMMEDIATE, 3 + arg_count, args); | 817 helper_->AddCommand(CreateParamByNameImmediate, 3 + arg_count, args); |
| 818 CHECK_ERROR(helper_); | 818 CHECK_ERROR(helper_); |
| 819 } | 819 } |
| 820 | 820 |
| 821 // Bind textures to the parameters | 821 // Bind textures to the parameters |
| 822 args[0].value_uint32 = noise_sampler_param_id_; | 822 args[0].value_uint32 = noise_sampler_param_id_; |
| 823 args[1].value_uint32 = sizeof(Uint32); // NOLINT | 823 args[1].value_uint32 = sizeof(Uint32); // NOLINT |
| 824 args[2].value_uint32 = noise_sampler_id_; | 824 args[2].value_uint32 = noise_sampler_id_; |
| 825 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 3, args); | 825 helper_->AddCommand(SetParamDataImmediate, 3, args); |
| 826 CHECK_ERROR(helper_); | 826 CHECK_ERROR(helper_); |
| 827 | 827 |
| 828 args[0].value_uint32 = iridescence_sampler_param_id_; | 828 args[0].value_uint32 = iridescence_sampler_param_id_; |
| 829 args[1].value_uint32 = sizeof(Uint32); // NOLINT | 829 args[1].value_uint32 = sizeof(Uint32); // NOLINT |
| 830 args[2].value_uint32 = iridescence_sampler_id_; | 830 args[2].value_uint32 = iridescence_sampler_id_; |
| 831 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 3, args); | 831 helper_->AddCommand(SetParamDataImmediate, 3, args); |
| 832 CHECK_ERROR(helper_); | 832 CHECK_ERROR(helper_); |
| 833 | 833 |
| 834 args[0].value_uint32 = cubemap_sampler_param_id_; | 834 args[0].value_uint32 = cubemap_sampler_param_id_; |
| 835 args[1].value_uint32 = sizeof(Uint32); // NOLINT | 835 args[1].value_uint32 = sizeof(Uint32); // NOLINT |
| 836 args[2].value_uint32 = cubemap_sampler_id_; | 836 args[2].value_uint32 = cubemap_sampler_id_; |
| 837 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 3, args); | 837 helper_->AddCommand(SetParamDataImmediate, 3, args); |
| 838 CHECK_ERROR(helper_); | 838 CHECK_ERROR(helper_); |
| 839 | 839 |
| 840 // Create our random bubbles. | 840 // Create our random bubbles. |
| 841 for (unsigned int i = 0; i < kBubbleCount; ++i) { | 841 for (unsigned int i = 0; i < kBubbleCount; ++i) { |
| 842 Bubble bubble; | 842 Bubble bubble; |
| 843 bubble.position = math::Point3(Randf(-6.f, 6.f, &seed_), | 843 bubble.position = math::Point3(Randf(-6.f, 6.f, &seed_), |
| 844 Randf(-6.f, 6.f, &seed_), | 844 Randf(-6.f, 6.f, &seed_), |
| 845 Randf(-6.f, 6.f, &seed_)); | 845 Randf(-6.f, 6.f, &seed_)); |
| 846 bubble.rotation_speed = math::Vector3(Randf(-.1f, .1f, &seed_), | 846 bubble.rotation_speed = math::Vector3(Randf(-.1f, .1f, &seed_), |
| 847 Randf(-.1f, .1f, &seed_), | 847 Randf(-.1f, .1f, &seed_), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 math::Matrix4 model = | 893 math::Matrix4 model = |
| 894 math::Matrix4::translation(math::Vector3(bubble.position)) * | 894 math::Matrix4::translation(math::Vector3(bubble.position)) * |
| 895 math::Matrix4::scale(math::Vector3(bubble.scale, bubble.scale, | 895 math::Matrix4::scale(math::Vector3(bubble.scale, bubble.scale, |
| 896 bubble.scale)) * | 896 bubble.scale)) * |
| 897 math::Matrix4::rotationZYX(rotation); | 897 math::Matrix4::rotationZYX(rotation); |
| 898 math::Matrix4 modelIT = math::inverse(math::transpose(model)); | 898 math::Matrix4 modelIT = math::inverse(math::transpose(model)); |
| 899 math::Matrix4 mvp = proj * view * model; | 899 math::Matrix4 mvp = proj * view * model; |
| 900 | 900 |
| 901 // AddCommand copies the args, so it is safe to re-use args across various | 901 // AddCommand copies the args, so it is safe to re-use args across various |
| 902 // calls. | 902 // calls. |
| 903 // 20 is the largest command we use (SET_PARAM_DATA_IMMEDIATE for matrices). | 903 // 20 is the largest command we use (SetParamDataImmediate for matrices). |
| 904 CommandBufferEntry args[20]; | 904 CommandBufferEntry args[20]; |
| 905 | 905 |
| 906 args[0].value_uint32 = vertex_struct_id_; | 906 args[0].value_uint32 = vertex_struct_id_; |
| 907 helper_->AddCommand(SET_VERTEX_STRUCT, 1, args); | 907 helper_->AddCommand(SetVertexStruct, 1, args); |
| 908 CHECK_ERROR(helper_); | 908 CHECK_ERROR(helper_); |
| 909 | 909 |
| 910 args[0].value_uint32 = mvp_param_id_; | 910 args[0].value_uint32 = mvp_param_id_; |
| 911 args[1].value_uint32 = sizeof(mvp); | 911 args[1].value_uint32 = sizeof(mvp); |
| 912 unsigned int arg_count = CopyToArgs(args + 2, &mvp, sizeof(mvp)); | 912 unsigned int arg_count = CopyToArgs(args + 2, &mvp, sizeof(mvp)); |
| 913 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 2 + arg_count, args); | 913 helper_->AddCommand(SetParamDataImmediate, 2 + arg_count, args); |
| 914 CHECK_ERROR(helper_); | 914 CHECK_ERROR(helper_); |
| 915 | 915 |
| 916 args[0].value_uint32 = world_param_id_; | 916 args[0].value_uint32 = world_param_id_; |
| 917 args[1].value_uint32 = sizeof(model); | 917 args[1].value_uint32 = sizeof(model); |
| 918 arg_count = CopyToArgs(args + 2, &model, sizeof(model)); | 918 arg_count = CopyToArgs(args + 2, &model, sizeof(model)); |
| 919 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 2 + arg_count, args); | 919 helper_->AddCommand(SetParamDataImmediate, 2 + arg_count, args); |
| 920 CHECK_ERROR(helper_); | 920 CHECK_ERROR(helper_); |
| 921 | 921 |
| 922 args[0].value_uint32 = worldIT_param_id_; | 922 args[0].value_uint32 = worldIT_param_id_; |
| 923 args[1].value_uint32 = sizeof(modelIT); | 923 args[1].value_uint32 = sizeof(modelIT); |
| 924 arg_count = CopyToArgs(args + 2, &modelIT, sizeof(modelIT)); | 924 arg_count = CopyToArgs(args + 2, &modelIT, sizeof(modelIT)); |
| 925 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 2 + arg_count, args); | 925 helper_->AddCommand(SetParamDataImmediate, 2 + arg_count, args); |
| 926 CHECK_ERROR(helper_); | 926 CHECK_ERROR(helper_); |
| 927 | 927 |
| 928 args[0].value_uint32 = eye_param_id_; | 928 args[0].value_uint32 = eye_param_id_; |
| 929 args[1].value_uint32 = sizeof(eye); | 929 args[1].value_uint32 = sizeof(eye); |
| 930 arg_count = CopyToArgs(args + 2, &eye, sizeof(eye)); | 930 arg_count = CopyToArgs(args + 2, &eye, sizeof(eye)); |
| 931 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 2 + arg_count, args); | 931 helper_->AddCommand(SetParamDataImmediate, 2 + arg_count, args); |
| 932 CHECK_ERROR(helper_); | 932 CHECK_ERROR(helper_); |
| 933 | 933 |
| 934 args[0].value_uint32 = | 934 args[0].value_uint32 = |
| 935 set_blending::ColorSrcFunc::MakeValue(GAPIInterface::BLEND_FUNC_ONE) | | 935 set_blending::ColorSrcFunc::MakeValue(GAPIInterface::BLEND_FUNC_ONE) | |
| 936 set_blending::ColorDstFunc::MakeValue( | 936 set_blending::ColorDstFunc::MakeValue( |
| 937 GAPIInterface::BLEND_FUNC_SRC_ALPHA) | | 937 GAPIInterface::BLEND_FUNC_SRC_ALPHA) | |
| 938 set_blending::ColorEq::MakeValue(GAPIInterface::BLEND_EQ_ADD) | | 938 set_blending::ColorEq::MakeValue(GAPIInterface::BLEND_EQ_ADD) | |
| 939 set_blending::SeparateAlpha::MakeValue(0) | | 939 set_blending::SeparateAlpha::MakeValue(0) | |
| 940 set_blending::Enable::MakeValue(1); | 940 set_blending::Enable::MakeValue(1); |
| 941 helper_->AddCommand(SET_BLENDING, 1, args); | 941 helper_->AddCommand(SetBlending, 1, args); |
| 942 CHECK_ERROR(helper_); | 942 CHECK_ERROR(helper_); |
| 943 | 943 |
| 944 args[0].value_uint32 = effect_id_; | 944 args[0].value_uint32 = effect_id_; |
| 945 helper_->AddCommand(SET_EFFECT, 1, args); | 945 helper_->AddCommand(SetEffect, 1, args); |
| 946 CHECK_ERROR(helper_); | 946 CHECK_ERROR(helper_); |
| 947 | 947 |
| 948 // Draw back faces first. | 948 // Draw back faces first. |
| 949 args[0].value_uint32 = | 949 args[0].value_uint32 = |
| 950 set_polygon_raster::FillMode::MakeValue( | 950 set_polygon_raster::FillMode::MakeValue( |
| 951 GAPIInterface::POLYGON_MODE_FILL) | | 951 GAPIInterface::POLYGON_MODE_FILL) | |
| 952 set_polygon_raster::CullMode::MakeValue(GAPIInterface::CULL_CCW); | 952 set_polygon_raster::CullMode::MakeValue(GAPIInterface::CULL_CCW); |
| 953 helper_->AddCommand(SET_POLYGON_RASTER, 1, args); | 953 helper_->AddCommand(SetPolygonRaster, 1, args); |
| 954 CHECK_ERROR(helper_); | 954 CHECK_ERROR(helper_); |
| 955 | 955 |
| 956 args[0].value_uint32 = thickness_param_id_; | 956 args[0].value_uint32 = thickness_param_id_; |
| 957 args[1].value_uint32 = 4*sizeof(float); // NOLINT | 957 args[1].value_uint32 = 4*sizeof(float); // NOLINT |
| 958 args[2].value_float = bubble.thickness_falloff; | 958 args[2].value_float = bubble.thickness_falloff; |
| 959 args[3].value_float = bubble.base_thickness; | 959 args[3].value_float = bubble.base_thickness; |
| 960 args[4].value_float = bubble.noise_ratio; | 960 args[4].value_float = bubble.noise_ratio; |
| 961 args[5].value_float = .5f; // back face attenuation | 961 args[5].value_float = .5f; // back face attenuation |
| 962 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 6, args); | 962 helper_->AddCommand(SetParamDataImmediate, 6, args); |
| 963 CHECK_ERROR(helper_); | 963 CHECK_ERROR(helper_); |
| 964 | 964 |
| 965 args[0].value_uint32 = GAPIInterface::TRIANGLES; | 965 args[0].value_uint32 = GAPIInterface::TRIANGLES; |
| 966 args[1].value_uint32 = index_buffer_id_; | 966 args[1].value_uint32 = index_buffer_id_; |
| 967 args[2].value_uint32 = 0; // first | 967 args[2].value_uint32 = 0; // first |
| 968 args[3].value_uint32 = kIndexCount/3; // primitive count | 968 args[3].value_uint32 = kIndexCount/3; // primitive count |
| 969 args[4].value_uint32 = 0; // min index | 969 args[4].value_uint32 = 0; // min index |
| 970 args[5].value_uint32 = kVertexCount-1; // max index | 970 args[5].value_uint32 = kVertexCount-1; // max index |
| 971 helper_->AddCommand(DRAW_INDEXED, 6, args); | 971 helper_->AddCommand(DrawIndexed, 6, args); |
| 972 CHECK_ERROR(helper_); | 972 CHECK_ERROR(helper_); |
| 973 | 973 |
| 974 // Then front faces. | 974 // Then front faces. |
| 975 args[0].value_uint32 = | 975 args[0].value_uint32 = |
| 976 set_polygon_raster::FillMode::MakeValue( | 976 set_polygon_raster::FillMode::MakeValue( |
| 977 GAPIInterface::POLYGON_MODE_FILL) | | 977 GAPIInterface::POLYGON_MODE_FILL) | |
| 978 set_polygon_raster::CullMode::MakeValue(GAPIInterface::CULL_CW); | 978 set_polygon_raster::CullMode::MakeValue(GAPIInterface::CULL_CW); |
| 979 helper_->AddCommand(SET_POLYGON_RASTER, 1, args); | 979 helper_->AddCommand(SetPolygonRaster, 1, args); |
| 980 CHECK_ERROR(helper_); | 980 CHECK_ERROR(helper_); |
| 981 | 981 |
| 982 args[0].value_uint32 = thickness_param_id_; | 982 args[0].value_uint32 = thickness_param_id_; |
| 983 args[1].value_uint32 = 4*sizeof(float); // NOLINT | 983 args[1].value_uint32 = 4*sizeof(float); // NOLINT |
| 984 args[2].value_float = bubble.thickness_falloff; | 984 args[2].value_float = bubble.thickness_falloff; |
| 985 args[3].value_float = bubble.base_thickness; | 985 args[3].value_float = bubble.base_thickness; |
| 986 args[4].value_float = bubble.noise_ratio; | 986 args[4].value_float = bubble.noise_ratio; |
| 987 args[5].value_float = 1.f; | 987 args[5].value_float = 1.f; |
| 988 helper_->AddCommand(SET_PARAM_DATA_IMMEDIATE, 6, args); | 988 helper_->AddCommand(SetParamDataImmediate, 6, args); |
| 989 CHECK_ERROR(helper_); | 989 CHECK_ERROR(helper_); |
| 990 | 990 |
| 991 args[0].value_uint32 = GAPIInterface::TRIANGLES; | 991 args[0].value_uint32 = GAPIInterface::TRIANGLES; |
| 992 args[1].value_uint32 = index_buffer_id_; | 992 args[1].value_uint32 = index_buffer_id_; |
| 993 args[2].value_uint32 = 0; // first | 993 args[2].value_uint32 = 0; // first |
| 994 args[3].value_uint32 = kIndexCount/3; // primitive count | 994 args[3].value_uint32 = kIndexCount/3; // primitive count |
| 995 args[4].value_uint32 = 0; // min index | 995 args[4].value_uint32 = 0; // min index |
| 996 args[5].value_uint32 = kVertexCount-1; // max index | 996 args[5].value_uint32 = kVertexCount-1; // max index |
| 997 helper_->AddCommand(DRAW_INDEXED, 6, args); | 997 helper_->AddCommand(DrawIndexed, 6, args); |
| 998 CHECK_ERROR(helper_); | 998 CHECK_ERROR(helper_); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 void BubbleDemo::Render() { | 1001 void BubbleDemo::Render() { |
| 1002 uint64_t time_usec = GetTimeUsec() - start_time_; | 1002 uint64_t time_usec = GetTimeUsec() - start_time_; |
| 1003 time_ = time_usec * 1.e-6f; | 1003 time_ = time_usec * 1.e-6f; |
| 1004 // Camera path | 1004 // Camera path |
| 1005 float r = 20.f; | 1005 float r = 20.f; |
| 1006 float theta = time_ / 4.f; | 1006 float theta = time_ / 4.f; |
| 1007 float phi = 2 * theta; | 1007 float phi = 2 * theta; |
| 1008 math::Point3 eye(r * cosf(theta), r / 3.f * sinf(phi), r * sinf(theta)); | 1008 math::Point3 eye(r * cosf(theta), r / 3.f * sinf(phi), r * sinf(theta)); |
| 1009 math::Point3 target(0.f, 0.f, 0.f); | 1009 math::Point3 target(0.f, 0.f, 0.f); |
| 1010 math::Vector3 up(0.f, 1.f, 0.f); | 1010 math::Vector3 up(0.f, 1.f, 0.f); |
| 1011 math::Matrix4 proj = | 1011 math::Matrix4 proj = |
| 1012 math::CreatePerspectiveMatrix(kPi / 4.f, 1.f, .1f, 10000.f); | 1012 math::CreatePerspectiveMatrix(kPi / 4.f, 1.f, .1f, 10000.f); |
| 1013 math::Matrix4 view = math::Matrix4::lookAt(eye, target, up); | 1013 math::Matrix4 view = math::Matrix4::lookAt(eye, target, up); |
| 1014 | 1014 |
| 1015 helper_->AddCommand(BEGIN_FRAME, 0 , NULL); | 1015 helper_->AddCommand(BeginFrame, 0 , NULL); |
| 1016 CHECK_ERROR(helper_); | 1016 CHECK_ERROR(helper_); |
| 1017 RGBA color = {0.2f, 0.2f, 0.2f, 1.f}; | 1017 RGBA color = {0.2f, 0.2f, 0.2f, 1.f}; |
| 1018 ClearCmd(helper_.get(), GAPIInterface::COLOR | GAPIInterface::DEPTH, color, | 1018 ClearCmd(helper_.get(), GAPIInterface::COLOR | GAPIInterface::DEPTH, color, |
| 1019 1.f, 0); | 1019 1.f, 0); |
| 1020 | 1020 |
| 1021 // Sort bubbles back-to-front. | 1021 // Sort bubbles back-to-front. |
| 1022 std::sort(bubbles_.begin(), bubbles_.end(), BubbleSorter(view)); | 1022 std::sort(bubbles_.begin(), bubbles_.end(), BubbleSorter(view)); |
| 1023 // Then render them all. | 1023 // Then render them all. |
| 1024 for (unsigned int i = 0; i < bubbles_.size(); ++i) { | 1024 for (unsigned int i = 0; i < bubbles_.size(); ++i) { |
| 1025 const Bubble &bubble = bubbles_[i]; | 1025 const Bubble &bubble = bubbles_[i]; |
| 1026 DrawBubble(view, proj, bubble, time_ * 2.f * kPi * bubble.rotation_speed); | 1026 DrawBubble(view, proj, bubble, time_ * 2.f * kPi * bubble.rotation_speed); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 helper_->AddCommand(END_FRAME, 0 , NULL); | 1029 helper_->AddCommand(EndFrame, 0 , NULL); |
| 1030 CHECK_ERROR(helper_); | 1030 CHECK_ERROR(helper_); |
| 1031 helper_->Flush(); | 1031 helper_->Flush(); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 } // namespace command_buffer | 1034 } // namespace command_buffer |
| 1035 } // namespace o3d | 1035 } // namespace o3d |
| 1036 | 1036 |
| 1037 // Scriptable object for the plug-in, provides the glue with the browser. | 1037 // Scriptable object for the plug-in, provides the glue with the browser. |
| 1038 // Creates a BubbleDemo object and delegates calls to it. | 1038 // Creates a BubbleDemo object and delegates calls to it. |
| 1039 class Plugin : public NPObject { | 1039 class Plugin : public NPObject { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 } | 1257 } |
| 1258 return NPERR_GENERIC_ERROR; | 1258 return NPERR_GENERIC_ERROR; |
| 1259 } | 1259 } |
| 1260 | 1260 |
| 1261 int main(int argc, char **argv) { | 1261 int main(int argc, char **argv) { |
| 1262 printf("Bubble demo\n"); | 1262 printf("Bubble demo\n"); |
| 1263 NaClNP_Init(&argc, argv); | 1263 NaClNP_Init(&argc, argv); |
| 1264 NaClNP_MainLoop(0); | 1264 NaClNP_MainLoop(0); |
| 1265 return 0; | 1265 return 0; |
| 1266 } | 1266 } |
| OLD | NEW |