| 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 // case the creation fails. | 527 // case the creation fails. |
| 528 effects_.Destroy(id); | 528 effects_.Destroy(id); |
| 529 // Data is vp_main \0 fp_main \0 effect_text. | 529 // Data is vp_main \0 fp_main \0 effect_text. |
| 530 String vertex_program_entry; | 530 String vertex_program_entry; |
| 531 String fragment_program_entry; | 531 String fragment_program_entry; |
| 532 String effect_code; | 532 String effect_code; |
| 533 if (!ParseEffectData(size, data, | 533 if (!ParseEffectData(size, data, |
| 534 &vertex_program_entry, | 534 &vertex_program_entry, |
| 535 &fragment_program_entry, | 535 &fragment_program_entry, |
| 536 &effect_code)) { | 536 &effect_code)) { |
| 537 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 537 return BufferSyncInterface::kParseInvalidArguments; |
| 538 } | 538 } |
| 539 EffectD3D9 * effect = EffectD3D9::Create(this, effect_code, | 539 EffectD3D9 * effect = EffectD3D9::Create(this, effect_code, |
| 540 vertex_program_entry, | 540 vertex_program_entry, |
| 541 fragment_program_entry); | 541 fragment_program_entry); |
| 542 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 542 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 543 effects_.Assign(id, effect); | 543 effects_.Assign(id, effect); |
| 544 return BufferSyncInterface::PARSE_NO_ERROR; | 544 return BufferSyncInterface::kParseNoError; |
| 545 } | 545 } |
| 546 | 546 |
| 547 // Destroys the Effect resource. | 547 // Destroys the Effect resource. |
| 548 // If destroying the current effect, dirty it. | 548 // If destroying the current effect, dirty it. |
| 549 BufferSyncInterface::ParseError GAPID3D9::DestroyEffect(ResourceID id) { | 549 BufferSyncInterface::ParseError GAPID3D9::DestroyEffect(ResourceID id) { |
| 550 if (id == current_effect_id_) DirtyEffect(); | 550 if (id == current_effect_id_) DirtyEffect(); |
| 551 return effects_.Destroy(id) ? | 551 return effects_.Destroy(id) ? |
| 552 BufferSyncInterface::PARSE_NO_ERROR : | 552 BufferSyncInterface::kParseNoError : |
| 553 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 553 BufferSyncInterface::kParseInvalidArguments; |
| 554 } | 554 } |
| 555 | 555 |
| 556 // Sets the current effect ID, dirtying the current effect. | 556 // Sets the current effect ID, dirtying the current effect. |
| 557 BufferSyncInterface::ParseError GAPID3D9::SetEffect(ResourceID id) { | 557 BufferSyncInterface::ParseError GAPID3D9::SetEffect(ResourceID id) { |
| 558 DirtyEffect(); | 558 DirtyEffect(); |
| 559 current_effect_id_ = id; | 559 current_effect_id_ = id; |
| 560 return BufferSyncInterface::PARSE_NO_ERROR; | 560 return BufferSyncInterface::kParseNoError; |
| 561 } | 561 } |
| 562 | 562 |
| 563 // Gets the param count from the effect and store it in the memory buffer. | 563 // Gets the param count from the effect and store it in the memory buffer. |
| 564 BufferSyncInterface::ParseError GAPID3D9::GetParamCount( | 564 BufferSyncInterface::ParseError GAPID3D9::GetParamCount( |
| 565 ResourceID id, | 565 ResourceID id, |
| 566 unsigned int size, | 566 unsigned int size, |
| 567 void *data) { | 567 void *data) { |
| 568 EffectD3D9 *effect = effects_.Get(id); | 568 EffectD3D9 *effect = effects_.Get(id); |
| 569 if (!effect || size < sizeof(Uint32)) // NOLINT | 569 if (!effect || size < sizeof(Uint32)) // NOLINT |
| 570 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 570 return BufferSyncInterface::kParseInvalidArguments; |
| 571 *static_cast<Uint32 *>(data) = effect->GetParamCount(); | 571 *static_cast<Uint32 *>(data) = effect->GetParamCount(); |
| 572 return BufferSyncInterface::PARSE_NO_ERROR; | 572 return BufferSyncInterface::kParseNoError; |
| 573 } | 573 } |
| 574 | 574 |
| 575 BufferSyncInterface::ParseError GAPID3D9::CreateParam( | 575 BufferSyncInterface::ParseError GAPID3D9::CreateParam( |
| 576 ResourceID param_id, | 576 ResourceID param_id, |
| 577 ResourceID effect_id, | 577 ResourceID effect_id, |
| 578 unsigned int index) { | 578 unsigned int index) { |
| 579 EffectD3D9 *effect = effects_.Get(effect_id); | 579 EffectD3D9 *effect = effects_.Get(effect_id); |
| 580 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 580 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 581 EffectParamD3D9 *param = effect->CreateParam(index); | 581 EffectParamD3D9 *param = effect->CreateParam(index); |
| 582 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 582 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 583 effect_params_.Assign(param_id, param); | 583 effect_params_.Assign(param_id, param); |
| 584 return BufferSyncInterface::PARSE_NO_ERROR; | 584 return BufferSyncInterface::kParseNoError; |
| 585 } | 585 } |
| 586 | 586 |
| 587 BufferSyncInterface::ParseError GAPID3D9::CreateParamByName( | 587 BufferSyncInterface::ParseError GAPID3D9::CreateParamByName( |
| 588 ResourceID param_id, | 588 ResourceID param_id, |
| 589 ResourceID effect_id, | 589 ResourceID effect_id, |
| 590 unsigned int size, | 590 unsigned int size, |
| 591 const void *name) { | 591 const void *name) { |
| 592 EffectD3D9 *effect = effects_.Get(effect_id); | 592 EffectD3D9 *effect = effects_.Get(effect_id); |
| 593 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 593 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 594 std::string string_name(static_cast<const char *>(name), size); | 594 std::string string_name(static_cast<const char *>(name), size); |
| 595 EffectParamD3D9 *param = effect->CreateParamByName(string_name.c_str()); | 595 EffectParamD3D9 *param = effect->CreateParamByName(string_name.c_str()); |
| 596 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 596 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 597 effect_params_.Assign(param_id, param); | 597 effect_params_.Assign(param_id, param); |
| 598 return BufferSyncInterface::PARSE_NO_ERROR; | 598 return BufferSyncInterface::kParseNoError; |
| 599 } | 599 } |
| 600 | 600 |
| 601 BufferSyncInterface::ParseError GAPID3D9::DestroyParam(ResourceID id) { | 601 BufferSyncInterface::ParseError GAPID3D9::DestroyParam(ResourceID id) { |
| 602 return effect_params_.Destroy(id) ? | 602 return effect_params_.Destroy(id) ? |
| 603 BufferSyncInterface::PARSE_NO_ERROR : | 603 BufferSyncInterface::kParseNoError : |
| 604 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 604 BufferSyncInterface::kParseInvalidArguments; |
| 605 } | 605 } |
| 606 | 606 |
| 607 BufferSyncInterface::ParseError GAPID3D9::SetParamData( | 607 BufferSyncInterface::ParseError GAPID3D9::SetParamData( |
| 608 ResourceID id, | 608 ResourceID id, |
| 609 unsigned int size, | 609 unsigned int size, |
| 610 const void *data) { | 610 const void *data) { |
| 611 EffectParamD3D9 *param = effect_params_.Get(id); | 611 EffectParamD3D9 *param = effect_params_.Get(id); |
| 612 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 612 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 613 return param->SetData(this, size, data) ? | 613 return param->SetData(this, size, data) ? |
| 614 BufferSyncInterface::PARSE_NO_ERROR : | 614 BufferSyncInterface::kParseNoError : |
| 615 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 615 BufferSyncInterface::kParseInvalidArguments; |
| 616 } | 616 } |
| 617 | 617 |
| 618 BufferSyncInterface::ParseError GAPID3D9::GetParamDesc( | 618 BufferSyncInterface::ParseError GAPID3D9::GetParamDesc( |
| 619 ResourceID id, | 619 ResourceID id, |
| 620 unsigned int size, | 620 unsigned int size, |
| 621 void *data) { | 621 void *data) { |
| 622 EffectParamD3D9 *param = effect_params_.Get(id); | 622 EffectParamD3D9 *param = effect_params_.Get(id); |
| 623 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 623 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 624 return param->GetDesc(size, data) ? | 624 return param->GetDesc(size, data) ? |
| 625 BufferSyncInterface::PARSE_NO_ERROR : | 625 BufferSyncInterface::kParseNoError : |
| 626 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 626 BufferSyncInterface::kParseInvalidArguments; |
| 627 } | 627 } |
| 628 | 628 |
| 629 // Gets the stream count from the effect and stores it in the memory buffer. | 629 // Gets the stream count from the effect and stores it in the memory buffer. |
| 630 BufferSyncInterface::ParseError GAPID3D9::GetStreamCount( | 630 BufferSyncInterface::ParseError GAPID3D9::GetStreamCount( |
| 631 ResourceID id, | 631 ResourceID id, |
| 632 unsigned int size, | 632 unsigned int size, |
| 633 void *data) { | 633 void *data) { |
| 634 EffectD3D9 *effect = effects_.Get(id); | 634 EffectD3D9 *effect = effects_.Get(id); |
| 635 if (!effect || size < sizeof(Uint32)) // NOLINT | 635 if (!effect || size < sizeof(Uint32)) // NOLINT |
| 636 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 636 return BufferSyncInterface::kParseInvalidArguments; |
| 637 *static_cast<Uint32 *>(data) = effect->GetStreamCount(); | 637 *static_cast<Uint32 *>(data) = effect->GetStreamCount(); |
| 638 return BufferSyncInterface::PARSE_NO_ERROR; | 638 return BufferSyncInterface::kParseNoError; |
| 639 } | 639 } |
| 640 | 640 |
| 641 BufferSyncInterface::ParseError GAPID3D9::GetStreamDesc( | 641 BufferSyncInterface::ParseError GAPID3D9::GetStreamDesc( |
| 642 ResourceID id, | 642 ResourceID id, |
| 643 unsigned int index, | 643 unsigned int index, |
| 644 unsigned int size, | 644 unsigned int size, |
| 645 void *data) { | 645 void *data) { |
| 646 EffectD3D9 *effect = effects_.Get(id); | 646 EffectD3D9 *effect = effects_.Get(id); |
| 647 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 647 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 648 return effect->GetStreamDesc(index, size, data) ? | 648 return effect->GetStreamDesc(index, size, data) ? |
| 649 BufferSyncInterface::PARSE_NO_ERROR : | 649 BufferSyncInterface::kParseNoError : |
| 650 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 650 BufferSyncInterface::kParseInvalidArguments; |
| 651 } | 651 } |
| 652 | 652 |
| 653 | 653 |
| 654 // If the current effect is valid, call End on it, and tag for revalidation. | 654 // If the current effect is valid, call End on it, and tag for revalidation. |
| 655 void GAPID3D9::DirtyEffect() { | 655 void GAPID3D9::DirtyEffect() { |
| 656 if (validate_effect_) return; | 656 if (validate_effect_) return; |
| 657 DCHECK(current_effect_); | 657 DCHECK(current_effect_); |
| 658 current_effect_->End(this); | 658 current_effect_->End(this); |
| 659 current_effect_ = NULL; | 659 current_effect_ = NULL; |
| 660 validate_effect_ = true; | 660 validate_effect_ = true; |
| 661 } | 661 } |
| 662 | 662 |
| 663 // Gets the current effect, and calls Begin on it (if successful). | 663 // Gets the current effect, and calls Begin on it (if successful). |
| 664 // Should only be called if the current effect is not valid. | 664 // Should only be called if the current effect is not valid. |
| 665 bool GAPID3D9::ValidateEffect() { | 665 bool GAPID3D9::ValidateEffect() { |
| 666 DCHECK(validate_effect_); | 666 DCHECK(validate_effect_); |
| 667 DCHECK(!current_effect_); | 667 DCHECK(!current_effect_); |
| 668 current_effect_ = effects_.Get(current_effect_id_); | 668 current_effect_ = effects_.Get(current_effect_id_); |
| 669 if (!current_effect_) return false; | 669 if (!current_effect_) return false; |
| 670 validate_effect_ = false; | 670 validate_effect_ = false; |
| 671 return current_effect_->Begin(this); | 671 return current_effect_->Begin(this); |
| 672 } | 672 } |
| 673 | 673 |
| 674 } // namespace command_buffer | 674 } // namespace command_buffer |
| 675 } // namespace o3d | 675 } // namespace o3d |
| OLD | NEW |