| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 EffectParamGL::~EffectParamGL() { | 56 EffectParamGL::~EffectParamGL() { |
| 57 if (effect_) | 57 if (effect_) |
| 58 effect_->UnlinkParam(this); | 58 effect_->UnlinkParam(this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 static effect_param::DataType CgTypeToCBType(CGtype cg_type) { | 61 static effect_param::DataType CgTypeToCBType(CGtype cg_type) { |
| 62 switch (cg_type) { | 62 switch (cg_type) { |
| 63 case CG_FLOAT: | 63 case CG_FLOAT: |
| 64 case CG_FLOAT1: | 64 case CG_FLOAT1: |
| 65 return effect_param::FLOAT1; | 65 return effect_param::kFloat1; |
| 66 case CG_FLOAT2: | 66 case CG_FLOAT2: |
| 67 return effect_param::FLOAT2; | 67 return effect_param::kFloat2; |
| 68 case CG_FLOAT3: | 68 case CG_FLOAT3: |
| 69 return effect_param::FLOAT3; | 69 return effect_param::kFloat3; |
| 70 case CG_FLOAT4: | 70 case CG_FLOAT4: |
| 71 return effect_param::FLOAT4; | 71 return effect_param::kFloat4; |
| 72 case CG_INT: | 72 case CG_INT: |
| 73 case CG_INT1: | 73 case CG_INT1: |
| 74 return effect_param::INT; | 74 return effect_param::kInt; |
| 75 case CG_BOOL: | 75 case CG_BOOL: |
| 76 case CG_BOOL1: | 76 case CG_BOOL1: |
| 77 return effect_param::BOOL; | 77 return effect_param::kBool; |
| 78 case CG_FLOAT4x4: | 78 case CG_FLOAT4x4: |
| 79 return effect_param::MATRIX4; | 79 return effect_param::kMatrix4; |
| 80 case CG_SAMPLER: | 80 case CG_SAMPLER: |
| 81 case CG_SAMPLER1D: | 81 case CG_SAMPLER1D: |
| 82 case CG_SAMPLER2D: | 82 case CG_SAMPLER2D: |
| 83 case CG_SAMPLER3D: | 83 case CG_SAMPLER3D: |
| 84 case CG_SAMPLERCUBE: | 84 case CG_SAMPLERCUBE: |
| 85 return effect_param::SAMPLER; | 85 return effect_param::kSampler; |
| 86 case CG_TEXTURE: | 86 case CG_TEXTURE: |
| 87 return effect_param::TEXTURE; | 87 return effect_param::kTexture; |
| 88 default : { | 88 default : { |
| 89 DLOG(INFO) << "Cannot convert CGtype " | 89 DLOG(INFO) << "Cannot convert CGtype " |
| 90 << cgGetTypeString(cg_type) | 90 << cgGetTypeString(cg_type) |
| 91 << " to a Param type."; | 91 << " to a Param type."; |
| 92 return effect_param::UNKNOWN; | 92 return effect_param::kUnknown; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 EffectParamGL *EffectParamGL::Create(EffectGL *effect, | 97 EffectParamGL *EffectParamGL::Create(EffectGL *effect, |
| 98 unsigned int index) { | 98 unsigned int index) { |
| 99 DCHECK(effect); | 99 DCHECK(effect); |
| 100 const EffectGL::LowLevelParam &low_level_param = | 100 const EffectGL::LowLevelParam &low_level_param = |
| 101 effect->low_level_params_[index]; | 101 effect->low_level_params_[index]; |
| 102 CGparameter cg_param = EffectGL::GetEitherCgParameter(low_level_param); | 102 CGparameter cg_param = EffectGL::GetEitherCgParameter(low_level_param); |
| 103 CGtype cg_type = cgGetParameterType(cg_param); | 103 CGtype cg_type = cgGetParameterType(cg_param); |
| 104 if (cg_type == CG_ARRAY) { | 104 if (cg_type == CG_ARRAY) { |
| 105 cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); | 105 cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); |
| 106 } | 106 } |
| 107 effect_param::DataType type = CgTypeToCBType(cg_type); | 107 effect_param::DataType type = CgTypeToCBType(cg_type); |
| 108 | 108 |
| 109 if (type == effect_param::UNKNOWN) | 109 if (type == effect_param::kUnknown) |
| 110 return NULL; | 110 return NULL; |
| 111 return new EffectParamGL(type, effect, index); | 111 return new EffectParamGL(type, effect, index); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Fills the Desc structure, appending name and semantic if any, and if enough | 114 // Fills the Desc structure, appending name and semantic if any, and if enough |
| 115 // room is available in the buffer. | 115 // room is available in the buffer. |
| 116 bool EffectParamGL::GetDesc(unsigned int size, void *data) { | 116 bool EffectParamGL::GetDesc(unsigned int size, void *data) { |
| 117 using effect_param::Desc; | 117 using effect_param::Desc; |
| 118 if (size < sizeof(Desc)) // NOLINT | 118 if (size < sizeof(Desc)) // NOLINT |
| 119 return false; | 119 return false; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return false; | 170 return false; |
| 171 } | 171 } |
| 172 | 172 |
| 173 CGparameter vp_param = low_level_param.vp_param; | 173 CGparameter vp_param = low_level_param.vp_param; |
| 174 CGparameter fp_param = low_level_param.fp_param; | 174 CGparameter fp_param = low_level_param.fp_param; |
| 175 effect_param::DataType type = data_type(); | 175 effect_param::DataType type = data_type(); |
| 176 if (size < effect_param::GetDataSize(type)) | 176 if (size < effect_param::GetDataSize(type)) |
| 177 return false; | 177 return false; |
| 178 | 178 |
| 179 switch (type) { | 179 switch (type) { |
| 180 case effect_param::FLOAT1: | 180 case effect_param::kFloat1: |
| 181 if (vp_param) | 181 if (vp_param) |
| 182 cgSetParameter1f(vp_param, *static_cast<const float *>(data)); | 182 cgSetParameter1f(vp_param, *static_cast<const float *>(data)); |
| 183 if (fp_param) | 183 if (fp_param) |
| 184 cgSetParameter1f(fp_param, *static_cast<const float *>(data)); | 184 cgSetParameter1f(fp_param, *static_cast<const float *>(data)); |
| 185 break; | 185 break; |
| 186 case effect_param::FLOAT2: | 186 case effect_param::kFloat2: |
| 187 if (vp_param) | 187 if (vp_param) |
| 188 cgSetParameter2fv(vp_param, static_cast<const float *>(data)); | 188 cgSetParameter2fv(vp_param, static_cast<const float *>(data)); |
| 189 if (fp_param) | 189 if (fp_param) |
| 190 cgSetParameter2fv(fp_param, static_cast<const float *>(data)); | 190 cgSetParameter2fv(fp_param, static_cast<const float *>(data)); |
| 191 break; | 191 break; |
| 192 case effect_param::FLOAT3: | 192 case effect_param::kFloat3: |
| 193 if (vp_param) | 193 if (vp_param) |
| 194 cgSetParameter3fv(vp_param, static_cast<const float *>(data)); | 194 cgSetParameter3fv(vp_param, static_cast<const float *>(data)); |
| 195 if (fp_param) | 195 if (fp_param) |
| 196 cgSetParameter3fv(fp_param, static_cast<const float *>(data)); | 196 cgSetParameter3fv(fp_param, static_cast<const float *>(data)); |
| 197 break; | 197 break; |
| 198 case effect_param::FLOAT4: | 198 case effect_param::kFloat4: |
| 199 if (vp_param) | 199 if (vp_param) |
| 200 cgSetParameter4fv(vp_param, static_cast<const float *>(data)); | 200 cgSetParameter4fv(vp_param, static_cast<const float *>(data)); |
| 201 if (fp_param) | 201 if (fp_param) |
| 202 cgSetParameter4fv(fp_param, static_cast<const float *>(data)); | 202 cgSetParameter4fv(fp_param, static_cast<const float *>(data)); |
| 203 break; | 203 break; |
| 204 case effect_param::MATRIX4: | 204 case effect_param::kMatrix4: |
| 205 if (vp_param) | 205 if (vp_param) |
| 206 cgSetMatrixParameterfr(vp_param, static_cast<const float *>(data)); | 206 cgSetMatrixParameterfr(vp_param, static_cast<const float *>(data)); |
| 207 if (fp_param) | 207 if (fp_param) |
| 208 cgSetMatrixParameterfr(fp_param, static_cast<const float *>(data)); | 208 cgSetMatrixParameterfr(fp_param, static_cast<const float *>(data)); |
| 209 break; | 209 break; |
| 210 case effect_param::INT: | 210 case effect_param::kInt: |
| 211 if (vp_param) cgSetParameter1i(vp_param, *static_cast<const int *>(data)); | 211 if (vp_param) cgSetParameter1i(vp_param, *static_cast<const int *>(data)); |
| 212 if (fp_param) cgSetParameter1i(fp_param, *static_cast<const int *>(data)); | 212 if (fp_param) cgSetParameter1i(fp_param, *static_cast<const int *>(data)); |
| 213 break; | 213 break; |
| 214 case effect_param::BOOL: { | 214 case effect_param::kBool: { |
| 215 int bool_value = *static_cast<const bool *>(data)?1:0; | 215 int bool_value = *static_cast<const bool *>(data)?1:0; |
| 216 if (vp_param) cgSetParameter1i(vp_param, bool_value); | 216 if (vp_param) cgSetParameter1i(vp_param, bool_value); |
| 217 if (fp_param) cgSetParameter1i(fp_param, bool_value); | 217 if (fp_param) cgSetParameter1i(fp_param, bool_value); |
| 218 break; | 218 break; |
| 219 } | 219 } |
| 220 case effect_param::SAMPLER: { | 220 case effect_param::kSampler: { |
| 221 DCHECK_GE(low_level_param.sampler_ids.size(), 1); | 221 DCHECK_GE(low_level_param.sampler_ids.size(), 1); |
| 222 low_level_param.sampler_ids[0] = *static_cast<const ResourceID *>(data); | 222 low_level_param.sampler_ids[0] = *static_cast<const ResourceId *>(data); |
| 223 if (effect_ == gapi->current_effect()) { | 223 if (effect_ == gapi->current_effect()) { |
| 224 gapi->DirtyEffect(); | 224 gapi->DirtyEffect(); |
| 225 } | 225 } |
| 226 break; | 226 break; |
| 227 } | 227 } |
| 228 default: | 228 default: |
| 229 DLOG(ERROR) << "Invalid parameter type."; | 229 DLOG(ERROR) << "Invalid parameter type."; |
| 230 return false; | 230 return false; |
| 231 } | 231 } |
| 232 return true; | 232 return true; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 continue; | 438 continue; |
| 439 const char *name = cgGetParameterName(cg_param); | 439 const char *name = cgGetParameterName(cg_param); |
| 440 if (!name) | 440 if (!name) |
| 441 continue; | 441 continue; |
| 442 | 442 |
| 443 CGtype cg_type = cgGetParameterType(cg_param); | 443 CGtype cg_type = cgGetParameterType(cg_param); |
| 444 | 444 |
| 445 int num_elements; | 445 int num_elements; |
| 446 if (cg_type == CG_ARRAY) { | 446 if (cg_type == CG_ARRAY) { |
| 447 num_elements = cgGetArraySize(cg_param, 0); | 447 num_elements = cgGetArraySize(cg_param, 0); |
| 448 // Substitute the first element's type for our type.» | 448 // Substitute the first element's type for our type. |
| 449 cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); | 449 cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); |
| 450 } else { | 450 } else { |
| 451 num_elements = 0; | 451 num_elements = 0; |
| 452 } | 452 } |
| 453 | 453 |
| 454 int index = GetLowLevelParamIndexByName(name); | 454 int index = GetLowLevelParamIndexByName(name); |
| 455 if (index < 0) { | 455 if (index < 0) { |
| 456 LowLevelParam param; | 456 LowLevelParam param; |
| 457 param.name = name; | 457 param.name = name; |
| 458 param.vp_param = NULL; | 458 param.vp_param = NULL; |
| 459 param.fp_param = NULL; | 459 param.fp_param = NULL; |
| 460 param.num_elements = num_elements; | 460 param.num_elements = num_elements; |
| 461 | 461 |
| 462 index = low_level_params_.size(); | 462 index = low_level_params_.size(); |
| 463 if (cg_type == CG_SAMPLER || | 463 if (cg_type == CG_SAMPLER || |
| 464 cg_type == CG_SAMPLER1D || | 464 cg_type == CG_SAMPLER1D || |
| 465 cg_type == CG_SAMPLER2D || | 465 cg_type == CG_SAMPLER2D || |
| 466 cg_type == CG_SAMPLER3D || | 466 cg_type == CG_SAMPLER3D || |
| 467 cg_type == CG_SAMPLERCUBE) { | 467 cg_type == CG_SAMPLERCUBE) { |
| 468 sampler_params_.push_back(index); | 468 sampler_params_.push_back(index); |
| 469 if (num_elements == 0) { | 469 if (num_elements == 0) { |
| 470 param.sampler_ids.push_back(kInvalidResource); | 470 param.sampler_ids.push_back(kInvalidResource); |
| 471 } else { | 471 } else { |
| 472 param.sampler_ids.resize(num_elements); | 472 param.sampler_ids.resize(num_elements); |
| 473 std::vector<ResourceID>::iterator iter; | 473 std::vector<ResourceId>::iterator iter; |
| 474 for (iter = param.sampler_ids.begin(); | 474 for (iter = param.sampler_ids.begin(); |
| 475 iter != param.sampler_ids.end(); | 475 iter != param.sampler_ids.end(); |
| 476 ++iter) { | 476 ++iter) { |
| 477 *iter = kInvalidResource; | 477 *iter = kInvalidResource; |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 low_level_params_.push_back(param); | 481 low_level_params_.push_back(param); |
| 482 } | 482 } |
| 483 | 483 |
| 484 if (vp) { | 484 if (vp) { |
| 485 low_level_params_[index].vp_param = cg_param; | 485 low_level_params_[index].vp_param = cg_param; |
| 486 } else { | 486 } else { |
| 487 low_level_params_[index].fp_param = cg_param; | 487 low_level_params_[index].fp_param = cg_param; |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 | 491 |
| 492 typedef std::pair<String, effect_stream::Desc> SemanticMapElement; | 492 typedef std::pair<String, effect_stream::Desc> SemanticMapElement; |
| 493 typedef std::map<String, effect_stream::Desc> SemanticMap; | 493 typedef std::map<String, effect_stream::Desc> SemanticMap; |
| 494 | 494 |
| 495 // The map batween the semantics on vertex program varying parameters names | 495 // The map batween the semantics on vertex program varying parameters names |
| 496 // and vertex attribute indices under the VP_30 profile. | 496 // and vertex attribute indices under the VP_30 profile. |
| 497 // TODO(gman): remove this. |
| 497 SemanticMapElement semantic_map_array[] = { | 498 SemanticMapElement semantic_map_array[] = { |
| 498 SemanticMapElement("POSITION", | 499 SemanticMapElement("POSITION", |
| 499 effect_stream::Desc(vertex_struct::POSITION, 0)), | 500 effect_stream::Desc(vertex_struct::kPosition, 0)), |
| 500 SemanticMapElement("ATTR0", | 501 SemanticMapElement("ATTR0", |
| 501 effect_stream::Desc(vertex_struct::POSITION, 0)), | 502 effect_stream::Desc(vertex_struct::kPosition, 0)), |
| 502 SemanticMapElement("BLENDWEIGHT", | 503 SemanticMapElement("BLENDWEIGHT", |
| 503 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 504 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 504 SemanticMapElement("ATTR1", | 505 SemanticMapElement("ATTR1", |
| 505 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 506 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 506 SemanticMapElement("NORMAL", | 507 SemanticMapElement("NORMAL", |
| 507 effect_stream::Desc(vertex_struct::NORMAL, 0)), | 508 effect_stream::Desc(vertex_struct::kNormal, 0)), |
| 508 SemanticMapElement("ATTR2", | 509 SemanticMapElement("ATTR2", |
| 509 effect_stream::Desc(vertex_struct::NORMAL, 0)), | 510 effect_stream::Desc(vertex_struct::kNormal, 0)), |
| 510 SemanticMapElement("COLOR0", | 511 SemanticMapElement("COLOR0", |
| 511 effect_stream::Desc(vertex_struct::COLOR, 0)), | 512 effect_stream::Desc(vertex_struct::kColor, 0)), |
| 512 SemanticMapElement("DIFFUSE", | 513 SemanticMapElement("DIFFUSE", |
| 513 effect_stream::Desc(vertex_struct::COLOR, 0)), | 514 effect_stream::Desc(vertex_struct::kColor, 0)), |
| 514 SemanticMapElement("ATTR3", | 515 SemanticMapElement("ATTR3", |
| 515 effect_stream::Desc(vertex_struct::COLOR, 0)), | 516 effect_stream::Desc(vertex_struct::kColor, 0)), |
| 516 SemanticMapElement("COLOR1", | 517 SemanticMapElement("COLOR1", |
| 517 effect_stream::Desc(vertex_struct::COLOR, 1)), | 518 effect_stream::Desc(vertex_struct::kColor, 1)), |
| 518 SemanticMapElement("SPECULAR", | 519 SemanticMapElement("SPECULAR", |
| 519 effect_stream::Desc(vertex_struct::COLOR, 1)), | 520 effect_stream::Desc(vertex_struct::kColor, 1)), |
| 520 SemanticMapElement("ATTR4", | 521 SemanticMapElement("ATTR4", |
| 521 effect_stream::Desc(vertex_struct::COLOR, 1)), | 522 effect_stream::Desc(vertex_struct::kColor, 1)), |
| 522 SemanticMapElement("TESSFACTOR", | 523 SemanticMapElement("TESSFACTOR", |
| 523 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 524 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 524 SemanticMapElement("FOGCOORD", | 525 SemanticMapElement("FOGCOORD", |
| 525 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 526 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 526 SemanticMapElement("ATTR5", | 527 SemanticMapElement("ATTR5", |
| 527 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 528 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 528 SemanticMapElement("PSIZE", | 529 SemanticMapElement("PSIZE", |
| 529 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 530 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 530 SemanticMapElement("ATTR6", | 531 SemanticMapElement("ATTR6", |
| 531 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 532 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 532 SemanticMapElement("BLENDINDICES", | 533 SemanticMapElement("BLENDINDICES", |
| 533 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 534 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 534 SemanticMapElement("ATTR7", | 535 SemanticMapElement("ATTR7", |
| 535 effect_stream::Desc(vertex_struct::UNKNOWN_SEMANTIC, 0)), | 536 effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), |
| 536 SemanticMapElement("TEXCOORD0", | 537 SemanticMapElement("TEXCOORD0", |
| 537 effect_stream::Desc(vertex_struct::TEX_COORD, 0)), | 538 effect_stream::Desc(vertex_struct::kTexCoord, 0)), |
| 538 SemanticMapElement("ATTR8", | 539 SemanticMapElement("ATTR8", |
| 539 effect_stream::Desc(vertex_struct::TEX_COORD, 0)), | 540 effect_stream::Desc(vertex_struct::kTexCoord, 0)), |
| 540 SemanticMapElement("TEXCOORD1", | 541 SemanticMapElement("TEXCOORD1", |
| 541 effect_stream::Desc(vertex_struct::TEX_COORD, 1)), | 542 effect_stream::Desc(vertex_struct::kTexCoord, 1)), |
| 542 SemanticMapElement("ATTR9", | 543 SemanticMapElement("ATTR9", |
| 543 effect_stream::Desc(vertex_struct::TEX_COORD, 1)), | 544 effect_stream::Desc(vertex_struct::kTexCoord, 1)), |
| 544 SemanticMapElement("TEXCOORD2", | 545 SemanticMapElement("TEXCOORD2", |
| 545 effect_stream::Desc(vertex_struct::TEX_COORD, 2)), | 546 effect_stream::Desc(vertex_struct::kTexCoord, 2)), |
| 546 SemanticMapElement("ATTR10", | 547 SemanticMapElement("ATTR10", |
| 547 effect_stream::Desc(vertex_struct::TEX_COORD, 2)), | 548 effect_stream::Desc(vertex_struct::kTexCoord, 2)), |
| 548 SemanticMapElement("TEXCOORD3", | 549 SemanticMapElement("TEXCOORD3", |
| 549 effect_stream::Desc(vertex_struct::TEX_COORD, 3)), | 550 effect_stream::Desc(vertex_struct::kTexCoord, 3)), |
| 550 SemanticMapElement("ATTR11", | 551 SemanticMapElement("ATTR11", |
| 551 effect_stream::Desc(vertex_struct::TEX_COORD, 3)), | 552 effect_stream::Desc(vertex_struct::kTexCoord, 3)), |
| 552 SemanticMapElement("TEXCOORD4", | 553 SemanticMapElement("TEXCOORD4", |
| 553 effect_stream::Desc(vertex_struct::TEX_COORD, 4)), | 554 effect_stream::Desc(vertex_struct::kTexCoord, 4)), |
| 554 SemanticMapElement("ATTR12", | 555 SemanticMapElement("ATTR12", |
| 555 effect_stream::Desc(vertex_struct::TEX_COORD, 4)), | 556 effect_stream::Desc(vertex_struct::kTexCoord, 4)), |
| 556 SemanticMapElement("TEXCOORD5", | 557 SemanticMapElement("TEXCOORD5", |
| 557 effect_stream::Desc(vertex_struct::TEX_COORD, 5)), | 558 effect_stream::Desc(vertex_struct::kTexCoord, 5)), |
| 558 SemanticMapElement("ATTR13", | 559 SemanticMapElement("ATTR13", |
| 559 effect_stream::Desc(vertex_struct::TEX_COORD, 5)), | 560 effect_stream::Desc(vertex_struct::kTexCoord, 5)), |
| 560 SemanticMapElement("TEXCOORD6", | 561 SemanticMapElement("TEXCOORD6", |
| 561 effect_stream::Desc(vertex_struct::TEX_COORD, 6)), | 562 effect_stream::Desc(vertex_struct::kTexCoord, 6)), |
| 562 SemanticMapElement("TANGENT", | 563 SemanticMapElement("TANGENT", |
| 563 effect_stream::Desc(vertex_struct::TEX_COORD, 6)), | 564 effect_stream::Desc(vertex_struct::kTexCoord, 6)), |
| 564 SemanticMapElement("ATTR14", | 565 SemanticMapElement("ATTR14", |
| 565 effect_stream::Desc(vertex_struct::TEX_COORD, 7)), | 566 effect_stream::Desc(vertex_struct::kTexCoord, 7)), |
| 566 SemanticMapElement("TEXCOORD7", | 567 SemanticMapElement("TEXCOORD7", |
| 567 effect_stream::Desc(vertex_struct::TEX_COORD, 7)), | 568 effect_stream::Desc(vertex_struct::kTexCoord, 7)), |
| 568 SemanticMapElement("BINORMAL", | 569 SemanticMapElement("BINORMAL", |
| 569 effect_stream::Desc(vertex_struct::TEX_COORD, 8)), | 570 effect_stream::Desc(vertex_struct::kTexCoord, 8)), |
| 570 SemanticMapElement("ATTR15", | 571 SemanticMapElement("ATTR15", |
| 571 effect_stream::Desc(vertex_struct::TEX_COORD, 8)) | 572 effect_stream::Desc(vertex_struct::kTexCoord, 8)) |
| 572 }; | 573 }; |
| 573 | 574 |
| 574 static SemanticMap semantic_map(semantic_map_array, | 575 static SemanticMap semantic_map(semantic_map_array, |
| 575 semantic_map_array + | 576 semantic_map_array + |
| 576 arraysize(semantic_map_array)); | 577 arraysize(semantic_map_array)); |
| 577 | 578 |
| 578 void EffectGL::Initialize() { | 579 void EffectGL::Initialize() { |
| 579 AddLowLevelParams(vertex_program_, CG_PROGRAM, true); | 580 AddLowLevelParams(vertex_program_, CG_PROGRAM, true); |
| 580 AddLowLevelParams(vertex_program_, CG_GLOBAL, true); | 581 AddLowLevelParams(vertex_program_, CG_GLOBAL, true); |
| 581 AddLowLevelParams(fragment_program_, CG_PROGRAM, false); | 582 AddLowLevelParams(fragment_program_, CG_PROGRAM, false); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 597 CGenum direction = cgGetParameterDirection(cg_param); | 598 CGenum direction = cgGetParameterDirection(cg_param); |
| 598 if (direction != CG_IN) | 599 if (direction != CG_IN) |
| 599 continue; | 600 continue; |
| 600 const char* cg_semantic = cgGetParameterSemantic(cg_param); | 601 const char* cg_semantic = cgGetParameterSemantic(cg_param); |
| 601 if (cg_semantic == NULL) | 602 if (cg_semantic == NULL) |
| 602 continue; | 603 continue; |
| 603 | 604 |
| 604 SemanticMap::iterator iter = semantic_map.find(String(cg_semantic)); | 605 SemanticMap::iterator iter = semantic_map.find(String(cg_semantic)); |
| 605 if (iter == semantic_map.end()) { | 606 if (iter == semantic_map.end()) { |
| 606 streams_.push_back(effect_stream::Desc( | 607 streams_.push_back(effect_stream::Desc( |
| 607 vertex_struct::UNKNOWN_SEMANTIC, 0)); | 608 vertex_struct::kUnknownSemantic, 0)); |
| 608 } else { | 609 } else { |
| 609 streams_.push_back(iter->second); | 610 streams_.push_back(iter->second); |
| 610 } | 611 } |
| 611 } | 612 } |
| 612 } | 613 } |
| 613 | 614 |
| 614 // Begins rendering with the effect, setting all the appropriate states. | 615 // Begins rendering with the effect, setting all the appropriate states. |
| 615 bool EffectGL::Begin(GAPIGL *gapi) { | 616 bool EffectGL::Begin(GAPIGL *gapi) { |
| 616 cgGLBindProgram(vertex_program_); | 617 cgGLBindProgram(vertex_program_); |
| 617 cgGLBindProgram(fragment_program_); | 618 cgGLBindProgram(fragment_program_); |
| 618 | 619 |
| 619 // sampler->ApplyStates will mess with the texture binding on unit 0, so we | 620 // sampler->ApplyStates will mess with the texture binding on unit 0, so we |
| 620 // do 2 passes. | 621 // do 2 passes. |
| 621 // First to set the sampler states on the texture | 622 // First to set the sampler states on the texture |
| 622 for (unsigned int i = 0; i < sampler_params_.size(); ++i) { | 623 for (unsigned int i = 0; i < sampler_params_.size(); ++i) { |
| 623 unsigned int param_index = sampler_params_[i]; | 624 unsigned int param_index = sampler_params_[i]; |
| 624 std::vector<ResourceID> &ids = low_level_params_[param_index].sampler_ids; | 625 std::vector<ResourceId> &ids = low_level_params_[param_index].sampler_ids; |
| 625 for (std::vector<ResourceID>::iterator iter = ids.begin(); | 626 for (std::vector<ResourceId>::iterator iter = ids.begin(); |
| 626 iter != ids.end(); | 627 iter != ids.end(); |
| 627 ++iter) { | 628 ++iter) { |
| 628 ResourceID id = *iter; | 629 ResourceId id = *iter; |
| 629 if (id != kInvalidResource) { | 630 if (id != kInvalidResource) { |
| 630 SamplerGL *sampler = gapi->GetSampler(id); | 631 SamplerGL *sampler = gapi->GetSampler(id); |
| 631 if (!sampler->ApplyStates(gapi)) { | 632 if (!sampler->ApplyStates(gapi)) { |
| 632 return false; | 633 return false; |
| 633 } | 634 } |
| 634 } | 635 } |
| 635 } | 636 } |
| 636 } | 637 } |
| 637 // Second to enable/disable the sampler params. | 638 // Second to enable/disable the sampler params. |
| 638 for (unsigned int i = 0; i < sampler_params_.size(); ++i) { | 639 for (unsigned int i = 0; i < sampler_params_.size(); ++i) { |
| 639 unsigned int param_index = sampler_params_[i]; | 640 unsigned int param_index = sampler_params_[i]; |
| 640 const LowLevelParam &ll_param = low_level_params_[param_index]; | 641 const LowLevelParam &ll_param = low_level_params_[param_index]; |
| 641 std::vector<ResourceID> &ids = low_level_params_[param_index].sampler_ids; | 642 std::vector<ResourceId> &ids = low_level_params_[param_index].sampler_ids; |
| 642 // TODO(petersont): Rewrite the following so it handles arrays of samplers | 643 // TODO(petersont): Rewrite the following so it handles arrays of samplers |
| 643 // instead of simply bailing. | 644 // instead of simply bailing. |
| 644 if (cgGetParameterType(ll_param.fp_param) == CG_ARRAY) | 645 if (cgGetParameterType(ll_param.fp_param) == CG_ARRAY) |
| 645 return false; | 646 return false; |
| 646 for (std::vector<ResourceID>::iterator iter = ids.begin(); | 647 for (std::vector<ResourceId>::iterator iter = ids.begin(); |
| 647 iter != ids.end(); | 648 iter != ids.end(); |
| 648 ++iter) { | 649 ++iter) { |
| 649 ResourceID id = *iter; | 650 ResourceId id = *iter; |
| 650 if (id != kInvalidResource) { | 651 if (id != kInvalidResource) { |
| 651 SamplerGL *sampler = gapi->GetSampler(id); | 652 SamplerGL *sampler = gapi->GetSampler(id); |
| 652 GLuint gl_texture = sampler->gl_texture(); | 653 GLuint gl_texture = sampler->gl_texture(); |
| 653 cgGLSetTextureParameter(ll_param.fp_param, gl_texture); | 654 cgGLSetTextureParameter(ll_param.fp_param, gl_texture); |
| 654 cgGLEnableTextureParameter(ll_param.fp_param); | 655 cgGLEnableTextureParameter(ll_param.fp_param); |
| 655 } else { | 656 } else { |
| 656 cgGLSetTextureParameter(ll_param.fp_param, 0); | 657 cgGLSetTextureParameter(ll_param.fp_param, 0); |
| 657 cgGLDisableTextureParameter(ll_param.fp_param); | 658 cgGLDisableTextureParameter(ll_param.fp_param); |
| 658 } | 659 } |
| 659 } | 660 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 699 } |
| 699 | 700 |
| 700 // Gets a handle to the selected parameter, and wraps it into an | 701 // Gets a handle to the selected parameter, and wraps it into an |
| 701 // EffectParamGL if successful. | 702 // EffectParamGL if successful. |
| 702 EffectParamGL *EffectGL::CreateParamByName(const char *name) { | 703 EffectParamGL *EffectGL::CreateParamByName(const char *name) { |
| 703 int index = GetLowLevelParamIndexByName(name); | 704 int index = GetLowLevelParamIndexByName(name); |
| 704 if (index < 0) return NULL; | 705 if (index < 0) return NULL; |
| 705 return EffectParamGL::Create(this, index); | 706 return EffectParamGL::Create(this, index); |
| 706 } | 707 } |
| 707 | 708 |
| 708 BufferSyncInterface::ParseError GAPIGL::CreateEffect(ResourceID id, | 709 BufferSyncInterface::ParseError GAPIGL::CreateEffect(ResourceId id, |
| 709 unsigned int size, | 710 unsigned int size, |
| 710 const void *data) { | 711 const void *data) { |
| 711 if (id == current_effect_id_) DirtyEffect(); | 712 if (id == current_effect_id_) DirtyEffect(); |
| 712 // Even though Assign would Destroy the effect at id, we do it explicitly in | 713 // Even though Assign would Destroy the effect at id, we do it explicitly in |
| 713 // case the creation fails. | 714 // case the creation fails. |
| 714 effects_.Destroy(id); | 715 effects_.Destroy(id); |
| 715 // Data is vp_main \0 fp_main \0 effect_text. | 716 // Data is vp_main \0 fp_main \0 effect_text. |
| 716 String vertex_program_entry; | 717 String vertex_program_entry; |
| 717 String fragment_program_entry; | 718 String fragment_program_entry; |
| 718 String effect_code; | 719 String effect_code; |
| 719 if (!ParseEffectData(size, data, | 720 if (!ParseEffectData(size, data, |
| 720 &vertex_program_entry, | 721 &vertex_program_entry, |
| 721 &fragment_program_entry, | 722 &fragment_program_entry, |
| 722 &effect_code)) { | 723 &effect_code)) { |
| 723 return BufferSyncInterface::kParseInvalidArguments; | 724 return BufferSyncInterface::kParseInvalidArguments; |
| 724 } | 725 } |
| 725 EffectGL * effect = EffectGL::Create(this, effect_code, | 726 EffectGL * effect = EffectGL::Create(this, effect_code, |
| 726 vertex_program_entry, | 727 vertex_program_entry, |
| 727 fragment_program_entry); | 728 fragment_program_entry); |
| 728 if (!effect) return BufferSyncInterface::kParseInvalidArguments; | 729 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 729 effects_.Assign(id, effect); | 730 effects_.Assign(id, effect); |
| 730 return BufferSyncInterface::kParseNoError; | 731 return BufferSyncInterface::kParseNoError; |
| 731 } | 732 } |
| 732 | 733 |
| 733 BufferSyncInterface::ParseError GAPIGL::DestroyEffect(ResourceID id) { | 734 BufferSyncInterface::ParseError GAPIGL::DestroyEffect(ResourceId id) { |
| 734 if (id == current_effect_id_) DirtyEffect(); | 735 if (id == current_effect_id_) DirtyEffect(); |
| 735 return effects_.Destroy(id) ? | 736 return effects_.Destroy(id) ? |
| 736 BufferSyncInterface::kParseNoError : | 737 BufferSyncInterface::kParseNoError : |
| 737 BufferSyncInterface::kParseInvalidArguments; | 738 BufferSyncInterface::kParseInvalidArguments; |
| 738 } | 739 } |
| 739 | 740 |
| 740 BufferSyncInterface::ParseError GAPIGL::SetEffect(ResourceID id) { | 741 BufferSyncInterface::ParseError GAPIGL::SetEffect(ResourceId id) { |
| 741 DirtyEffect(); | 742 DirtyEffect(); |
| 742 current_effect_id_ = id; | 743 current_effect_id_ = id; |
| 743 return BufferSyncInterface::kParseNoError; | 744 return BufferSyncInterface::kParseNoError; |
| 744 } | 745 } |
| 745 | 746 |
| 746 BufferSyncInterface::ParseError GAPIGL::GetParamCount(ResourceID id, | 747 BufferSyncInterface::ParseError GAPIGL::GetParamCount(ResourceId id, |
| 747 unsigned int size, | 748 unsigned int size, |
| 748 void *data) { | 749 void *data) { |
| 749 EffectGL *effect = effects_.Get(id); | 750 EffectGL *effect = effects_.Get(id); |
| 750 if (!effect || size < sizeof(Uint32)) // NOLINT | 751 if (!effect || size < sizeof(Uint32)) // NOLINT |
| 751 return BufferSyncInterface::kParseInvalidArguments; | 752 return BufferSyncInterface::kParseInvalidArguments; |
| 752 *static_cast<Uint32 *>(data) = effect->GetParamCount(); | 753 *static_cast<Uint32 *>(data) = effect->GetParamCount(); |
| 753 return BufferSyncInterface::kParseNoError; | 754 return BufferSyncInterface::kParseNoError; |
| 754 } | 755 } |
| 755 | 756 |
| 756 BufferSyncInterface::ParseError GAPIGL::CreateParam(ResourceID param_id, | 757 BufferSyncInterface::ParseError GAPIGL::CreateParam(ResourceId param_id, |
| 757 ResourceID effect_id, | 758 ResourceId effect_id, |
| 758 unsigned int index) { | 759 unsigned int index) { |
| 759 EffectGL *effect = effects_.Get(effect_id); | 760 EffectGL *effect = effects_.Get(effect_id); |
| 760 if (!effect) return BufferSyncInterface::kParseInvalidArguments; | 761 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 761 EffectParamGL *param = effect->CreateParam(index); | 762 EffectParamGL *param = effect->CreateParam(index); |
| 762 if (!param) return BufferSyncInterface::kParseInvalidArguments; | 763 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 763 effect_params_.Assign(param_id, param); | 764 effect_params_.Assign(param_id, param); |
| 764 return BufferSyncInterface::kParseNoError; | 765 return BufferSyncInterface::kParseNoError; |
| 765 } | 766 } |
| 766 | 767 |
| 767 BufferSyncInterface::ParseError GAPIGL::CreateParamByName(ResourceID param_id, | 768 BufferSyncInterface::ParseError GAPIGL::CreateParamByName(ResourceId param_id, |
| 768 ResourceID effect_id, | 769 ResourceId effect_id, |
| 769 unsigned int size, | 770 unsigned int size, |
| 770 const void *name) { | 771 const void *name) { |
| 771 EffectGL *effect = effects_.Get(effect_id); | 772 EffectGL *effect = effects_.Get(effect_id); |
| 772 if (!effect) return BufferSyncInterface::kParseInvalidArguments; | 773 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 773 std::string string_name(static_cast<const char *>(name), size); | 774 std::string string_name(static_cast<const char *>(name), size); |
| 774 EffectParamGL *param = effect->CreateParamByName(string_name.c_str()); | 775 EffectParamGL *param = effect->CreateParamByName(string_name.c_str()); |
| 775 if (!param) return BufferSyncInterface::kParseInvalidArguments; | 776 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 776 effect_params_.Assign(param_id, param); | 777 effect_params_.Assign(param_id, param); |
| 777 return BufferSyncInterface::kParseNoError; | 778 return BufferSyncInterface::kParseNoError; |
| 778 } | 779 } |
| 779 | 780 |
| 780 BufferSyncInterface::ParseError GAPIGL::DestroyParam(ResourceID id) { | 781 BufferSyncInterface::ParseError GAPIGL::DestroyParam(ResourceId id) { |
| 781 return effect_params_.Destroy(id) ? | 782 return effect_params_.Destroy(id) ? |
| 782 BufferSyncInterface::kParseNoError : | 783 BufferSyncInterface::kParseNoError : |
| 783 BufferSyncInterface::kParseInvalidArguments; | 784 BufferSyncInterface::kParseInvalidArguments; |
| 784 } | 785 } |
| 785 | 786 |
| 786 BufferSyncInterface::ParseError GAPIGL::SetParamData(ResourceID id, | 787 BufferSyncInterface::ParseError GAPIGL::SetParamData(ResourceId id, |
| 787 unsigned int size, | 788 unsigned int size, |
| 788 const void *data) { | 789 const void *data) { |
| 789 EffectParamGL *param = effect_params_.Get(id); | 790 EffectParamGL *param = effect_params_.Get(id); |
| 790 if (!param) return BufferSyncInterface::kParseInvalidArguments; | 791 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 791 return param->SetData(this, size, data) ? | 792 return param->SetData(this, size, data) ? |
| 792 BufferSyncInterface::kParseNoError : | 793 BufferSyncInterface::kParseNoError : |
| 793 BufferSyncInterface::kParseInvalidArguments; | 794 BufferSyncInterface::kParseInvalidArguments; |
| 794 } | 795 } |
| 795 | 796 |
| 796 BufferSyncInterface::ParseError GAPIGL::GetParamDesc(ResourceID id, | 797 BufferSyncInterface::ParseError GAPIGL::GetParamDesc(ResourceId id, |
| 797 unsigned int size, | 798 unsigned int size, |
| 798 void *data) { | 799 void *data) { |
| 799 EffectParamGL *param = effect_params_.Get(id); | 800 EffectParamGL *param = effect_params_.Get(id); |
| 800 if (!param) return BufferSyncInterface::kParseInvalidArguments; | 801 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 801 return param->GetDesc(size, data) ? | 802 return param->GetDesc(size, data) ? |
| 802 BufferSyncInterface::kParseNoError : | 803 BufferSyncInterface::kParseNoError : |
| 803 BufferSyncInterface::kParseInvalidArguments; | 804 BufferSyncInterface::kParseInvalidArguments; |
| 804 } | 805 } |
| 805 | 806 |
| 806 BufferSyncInterface::ParseError GAPIGL::GetStreamCount( | 807 BufferSyncInterface::ParseError GAPIGL::GetStreamCount( |
| 807 ResourceID id, | 808 ResourceId id, |
| 808 unsigned int size, | 809 unsigned int size, |
| 809 void *data) { | 810 void *data) { |
| 810 EffectGL *effect = effects_.Get(id); | 811 EffectGL *effect = effects_.Get(id); |
| 811 if (!effect || size < sizeof(Uint32)) // NOLINT | 812 if (!effect || size < sizeof(Uint32)) // NOLINT |
| 812 return BufferSyncInterface::kParseInvalidArguments; | 813 return BufferSyncInterface::kParseInvalidArguments; |
| 813 *static_cast<Uint32 *>(data) = effect->GetStreamCount(); | 814 *static_cast<Uint32 *>(data) = effect->GetStreamCount(); |
| 814 return BufferSyncInterface::kParseNoError; | 815 return BufferSyncInterface::kParseNoError; |
| 815 } | 816 } |
| 816 | 817 |
| 817 BufferSyncInterface::ParseError GAPIGL::GetStreamDesc(ResourceID id, | 818 BufferSyncInterface::ParseError GAPIGL::GetStreamDesc(ResourceId id, |
| 818 unsigned int index, | 819 unsigned int index, |
| 819 unsigned int size, | 820 unsigned int size, |
| 820 void *data) { | 821 void *data) { |
| 821 EffectGL *effect = effects_.Get(id); | 822 EffectGL *effect = effects_.Get(id); |
| 822 if (!effect) return BufferSyncInterface::kParseInvalidArguments; | 823 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 823 return effect->GetStreamDesc(index, size, data) ? | 824 return effect->GetStreamDesc(index, size, data) ? |
| 824 BufferSyncInterface::kParseNoError : | 825 BufferSyncInterface::kParseNoError : |
| 825 BufferSyncInterface::kParseInvalidArguments; | 826 BufferSyncInterface::kParseInvalidArguments; |
| 826 } | 827 } |
| 827 | 828 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 840 DCHECK(validate_effect_); | 841 DCHECK(validate_effect_); |
| 841 DCHECK(!current_effect_); | 842 DCHECK(!current_effect_); |
| 842 current_effect_ = effects_.Get(current_effect_id_); | 843 current_effect_ = effects_.Get(current_effect_id_); |
| 843 if (!current_effect_) return false; | 844 if (!current_effect_) return false; |
| 844 validate_effect_ = false; | 845 validate_effect_ = false; |
| 845 return current_effect_->Begin(this); | 846 return current_effect_->Begin(this); |
| 846 } | 847 } |
| 847 | 848 |
| 848 } // namespace command_buffer | 849 } // namespace command_buffer |
| 849 } // namespace o3d | 850 } // namespace o3d |
| OLD | NEW |