| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 VertexBufferGL::~VertexBufferGL() { | 42 VertexBufferGL::~VertexBufferGL() { |
| 43 glDeleteBuffers(1, &gl_buffer_); | 43 glDeleteBuffers(1, &gl_buffer_); |
| 44 CHECK_GL_ERROR(); | 44 CHECK_GL_ERROR(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Creates the GL buffer object. | 47 // Creates the GL buffer object. |
| 48 void VertexBufferGL::Create() { | 48 void VertexBufferGL::Create() { |
| 49 glGenBuffers(1, &gl_buffer_); | 49 glGenBuffers(1, &gl_buffer_); |
| 50 glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); | 50 glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); |
| 51 GLenum usage = | 51 GLenum usage = |
| 52 (flags() & vertex_buffer::DYNAMIC) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; | 52 (flags() & vertex_buffer::kDynamic) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; |
| 53 glBufferData(GL_ARRAY_BUFFER, size(), NULL, usage); | 53 glBufferData(GL_ARRAY_BUFFER, size(), NULL, usage); |
| 54 CHECK_GL_ERROR(); | 54 CHECK_GL_ERROR(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Sets the data into the GL buffer object. | 57 // Sets the data into the GL buffer object. |
| 58 bool VertexBufferGL::SetData(unsigned int offset, | 58 bool VertexBufferGL::SetData(unsigned int offset, |
| 59 unsigned int size, | 59 unsigned int size, |
| 60 const void *data) { | 60 const void *data) { |
| 61 if (!gl_buffer_) { | 61 if (!gl_buffer_) { |
| 62 LOG(ERROR) << "Calling SetData on a non-initialized VertexBufferGL."; | 62 LOG(ERROR) << "Calling SetData on a non-initialized VertexBufferGL."; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 | 92 |
| 93 IndexBufferGL::~IndexBufferGL() { | 93 IndexBufferGL::~IndexBufferGL() { |
| 94 glDeleteBuffers(1, &gl_buffer_); | 94 glDeleteBuffers(1, &gl_buffer_); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Creates the GL buffer object. | 97 // Creates the GL buffer object. |
| 98 void IndexBufferGL::Create() { | 98 void IndexBufferGL::Create() { |
| 99 glGenBuffers(1, &gl_buffer_); | 99 glGenBuffers(1, &gl_buffer_); |
| 100 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); | 100 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); |
| 101 GLenum usage = | 101 GLenum usage = |
| 102 (flags() & vertex_buffer::DYNAMIC) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; | 102 (flags() & vertex_buffer::kDynamic) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; |
| 103 glBufferData(GL_ELEMENT_ARRAY_BUFFER, size(), NULL, usage); | 103 glBufferData(GL_ELEMENT_ARRAY_BUFFER, size(), NULL, usage); |
| 104 CHECK_GL_ERROR(); | 104 CHECK_GL_ERROR(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Sets the data into the GL buffer object. | 107 // Sets the data into the GL buffer object. |
| 108 bool IndexBufferGL::SetData(unsigned int offset, | 108 bool IndexBufferGL::SetData(unsigned int offset, |
| 109 unsigned int size, | 109 unsigned int size, |
| 110 const void *data) { | 110 const void *data) { |
| 111 if (!gl_buffer_) { | 111 if (!gl_buffer_) { |
| 112 LOG(ERROR) << "Calling SetData on a non-initialized IndexBufferGL."; | 112 LOG(ERROR) << "Calling SetData on a non-initialized IndexBufferGL."; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); | 137 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); |
| 138 glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, data); | 138 glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, data); |
| 139 CHECK_GL_ERROR(); | 139 CHECK_GL_ERROR(); |
| 140 return true; | 140 return true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Sets the input element in the VertexStruct resource. | 143 // Sets the input element in the VertexStruct resource. |
| 144 void VertexStructGL::SetInput(unsigned int input_index, | 144 void VertexStructGL::SetInput(unsigned int input_index, |
| 145 ResourceID vertex_buffer_id, | 145 ResourceId vertex_buffer_id, |
| 146 unsigned int offset, | 146 unsigned int offset, |
| 147 unsigned int stride, | 147 unsigned int stride, |
| 148 vertex_struct::Type type, | 148 vertex_struct::Type type, |
| 149 vertex_struct::Semantic semantic, | 149 vertex_struct::Semantic semantic, |
| 150 unsigned int semantic_index) { | 150 unsigned int semantic_index) { |
| 151 Element &element = GetElement(input_index); | 151 Element &element = GetElement(input_index); |
| 152 element.vertex_buffer = vertex_buffer_id; | 152 element.vertex_buffer = vertex_buffer_id; |
| 153 element.offset = offset; | 153 element.offset = offset; |
| 154 element.stride = stride; | 154 element.stride = stride; |
| 155 element.type = type; | 155 element.type = type; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // 14 texture coordinate set 6 MultiTexCoord(TEXTURE6, ...) | 228 // 14 texture coordinate set 6 MultiTexCoord(TEXTURE6, ...) |
| 229 // 15 texture coordinate set 7 MultiTexCoord(TEXTURE7, ...) | 229 // 15 texture coordinate set 7 MultiTexCoord(TEXTURE7, ...) |
| 230 // 8+n texture coordinate set n MultiTexCoord(TEXTURE0+n, ...) | 230 // 8+n texture coordinate set n MultiTexCoord(TEXTURE0+n, ...) |
| 231 // | 231 // |
| 232 // Note: we only accept at most 8 texture coordinates for maximum compatibility | 232 // Note: we only accept at most 8 texture coordinates for maximum compatibility |
| 233 // with DirectX. | 233 // with DirectX. |
| 234 | 234 |
| 235 inline unsigned int GetAttribIndex(vertex_struct::Semantic semantic, | 235 inline unsigned int GetAttribIndex(vertex_struct::Semantic semantic, |
| 236 unsigned int semantic_index) { | 236 unsigned int semantic_index) { |
| 237 switch (semantic) { | 237 switch (semantic) { |
| 238 case vertex_struct::POSITION: | 238 case vertex_struct::kPosition: |
| 239 DCHECK_EQ(semantic_index, 0); | 239 DCHECK_EQ(semantic_index, 0); |
| 240 return 0; | 240 return 0; |
| 241 case vertex_struct::NORMAL: | 241 case vertex_struct::kNormal: |
| 242 DCHECK_EQ(semantic_index, 0); | 242 DCHECK_EQ(semantic_index, 0); |
| 243 return 2; | 243 return 2; |
| 244 case vertex_struct::COLOR: | 244 case vertex_struct::kColor: |
| 245 DCHECK_LT(semantic_index, 2); | 245 DCHECK_LT(semantic_index, 2); |
| 246 return 3 + semantic_index; | 246 return 3 + semantic_index; |
| 247 case vertex_struct::TEX_COORD: | 247 case vertex_struct::kTexCoord: |
| 248 DCHECK_LT(semantic_index, 8); | 248 DCHECK_LT(semantic_index, 8); |
| 249 return 8 + semantic_index; | 249 return 8 + semantic_index; |
| 250 default: | 250 default: |
| 251 DLOG(FATAL) << "Not reached."; | 251 DLOG(FATAL) << "Not reached."; |
| 252 return 0; | 252 return 0; |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 inline void ExtractSizeTypeNormalized(vertex_struct::Type type, | 256 inline void ExtractSizeTypeNormalized(vertex_struct::Type type, |
| 257 GLint *size, | 257 GLint *size, |
| 258 GLenum *gl_type, | 258 GLenum *gl_type, |
| 259 GLboolean *normalized) { | 259 GLboolean *normalized) { |
| 260 switch (type) { | 260 switch (type) { |
| 261 case vertex_struct::FLOAT1: | 261 case vertex_struct::kFloat1: |
| 262 case vertex_struct::FLOAT2: | 262 case vertex_struct::kFloat2: |
| 263 case vertex_struct::FLOAT3: | 263 case vertex_struct::kFloat3: |
| 264 case vertex_struct::FLOAT4: | 264 case vertex_struct::kFloat4: |
| 265 *size = type - vertex_struct::FLOAT1 + 1; | 265 *size = type - vertex_struct::kFloat1 + 1; |
| 266 *gl_type = GL_FLOAT; | 266 *gl_type = GL_FLOAT; |
| 267 *normalized = false; | 267 *normalized = false; |
| 268 break; | 268 break; |
| 269 case vertex_struct::UCHAR4N: | 269 case vertex_struct::kUChar4N: |
| 270 *size = 4; | 270 *size = 4; |
| 271 *gl_type = GL_UNSIGNED_BYTE; | 271 *gl_type = GL_UNSIGNED_BYTE; |
| 272 *normalized = true; | 272 *normalized = true; |
| 273 break; | 273 break; |
| 274 default: | 274 default: |
| 275 DLOG(FATAL) << "Not reached."; | 275 DLOG(FATAL) << "Not reached."; |
| 276 break; | 276 break; |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 298 AttribDesc &attrib = attribs_[index]; | 298 AttribDesc &attrib = attribs_[index]; |
| 299 attrib.vertex_buffer_id = element.vertex_buffer; | 299 attrib.vertex_buffer_id = element.vertex_buffer; |
| 300 ExtractSizeTypeNormalized(element.type, &attrib.size, &attrib.type, | 300 ExtractSizeTypeNormalized(element.type, &attrib.size, &attrib.type, |
| 301 &attrib.normalized); | 301 &attrib.normalized); |
| 302 attrib.stride = element.stride; | 302 attrib.stride = element.stride; |
| 303 attrib.offset = OffsetToPtrDiff(element.offset); | 303 attrib.offset = OffsetToPtrDiff(element.offset); |
| 304 } | 304 } |
| 305 dirty_ = false; | 305 dirty_ = false; |
| 306 } | 306 } |
| 307 | 307 |
| 308 BufferSyncInterface::ParseError GAPIGL::CreateVertexBuffer(ResourceID id, | 308 BufferSyncInterface::ParseError GAPIGL::CreateVertexBuffer(ResourceId id, |
| 309 unsigned int size, | 309 unsigned int size, |
| 310 unsigned int flags) { | 310 unsigned int flags) { |
| 311 VertexBufferGL *vertex_buffer = new VertexBufferGL(size, flags); | 311 VertexBufferGL *vertex_buffer = new VertexBufferGL(size, flags); |
| 312 vertex_buffer->Create(); | 312 vertex_buffer->Create(); |
| 313 vertex_buffers_.Assign(id, vertex_buffer); | 313 vertex_buffers_.Assign(id, vertex_buffer); |
| 314 return BufferSyncInterface::kParseNoError; | 314 return BufferSyncInterface::kParseNoError; |
| 315 } | 315 } |
| 316 | 316 |
| 317 BufferSyncInterface::ParseError GAPIGL::DestroyVertexBuffer(ResourceID id) { | 317 BufferSyncInterface::ParseError GAPIGL::DestroyVertexBuffer(ResourceId id) { |
| 318 return vertex_buffers_.Destroy(id) ? | 318 return vertex_buffers_.Destroy(id) ? |
| 319 BufferSyncInterface::kParseNoError : | 319 BufferSyncInterface::kParseNoError : |
| 320 BufferSyncInterface::kParseInvalidArguments; | 320 BufferSyncInterface::kParseInvalidArguments; |
| 321 } | 321 } |
| 322 | 322 |
| 323 BufferSyncInterface::ParseError GAPIGL::SetVertexBufferData(ResourceID id, | 323 BufferSyncInterface::ParseError GAPIGL::SetVertexBufferData(ResourceId id, |
| 324 unsigned int offset, | 324 unsigned int offset, |
| 325 unsigned int size, | 325 unsigned int size, |
| 326 const void *data) { | 326 const void *data) { |
| 327 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); | 327 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); |
| 328 if (!vertex_buffer) return BufferSyncInterface::kParseInvalidArguments; | 328 if (!vertex_buffer) return BufferSyncInterface::kParseInvalidArguments; |
| 329 return vertex_buffer->SetData(offset, size, data) ? | 329 return vertex_buffer->SetData(offset, size, data) ? |
| 330 BufferSyncInterface::kParseNoError : | 330 BufferSyncInterface::kParseNoError : |
| 331 BufferSyncInterface::kParseInvalidArguments; | 331 BufferSyncInterface::kParseInvalidArguments; |
| 332 } | 332 } |
| 333 | 333 |
| 334 BufferSyncInterface::ParseError GAPIGL::GetVertexBufferData(ResourceID id, | 334 BufferSyncInterface::ParseError GAPIGL::GetVertexBufferData(ResourceId id, |
| 335 unsigned int offset, | 335 unsigned int offset, |
| 336 unsigned int size, | 336 unsigned int size, |
| 337 void *data) { | 337 void *data) { |
| 338 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); | 338 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); |
| 339 if (!vertex_buffer) return BufferSyncInterface::kParseInvalidArguments; | 339 if (!vertex_buffer) return BufferSyncInterface::kParseInvalidArguments; |
| 340 return vertex_buffer->GetData(offset, size, data) ? | 340 return vertex_buffer->GetData(offset, size, data) ? |
| 341 BufferSyncInterface::kParseNoError : | 341 BufferSyncInterface::kParseNoError : |
| 342 BufferSyncInterface::kParseInvalidArguments; | 342 BufferSyncInterface::kParseInvalidArguments; |
| 343 } | 343 } |
| 344 | 344 |
| 345 BufferSyncInterface::ParseError GAPIGL::CreateIndexBuffer(ResourceID id, | 345 BufferSyncInterface::ParseError GAPIGL::CreateIndexBuffer(ResourceId id, |
| 346 unsigned int size, | 346 unsigned int size, |
| 347 unsigned int flags) { | 347 unsigned int flags) { |
| 348 IndexBufferGL *index_buffer = new IndexBufferGL(size, flags); | 348 IndexBufferGL *index_buffer = new IndexBufferGL(size, flags); |
| 349 index_buffer->Create(); | 349 index_buffer->Create(); |
| 350 index_buffers_.Assign(id, index_buffer); | 350 index_buffers_.Assign(id, index_buffer); |
| 351 return BufferSyncInterface::kParseNoError; | 351 return BufferSyncInterface::kParseNoError; |
| 352 } | 352 } |
| 353 | 353 |
| 354 BufferSyncInterface::ParseError GAPIGL::DestroyIndexBuffer(ResourceID id) { | 354 BufferSyncInterface::ParseError GAPIGL::DestroyIndexBuffer(ResourceId id) { |
| 355 return index_buffers_.Destroy(id) ? | 355 return index_buffers_.Destroy(id) ? |
| 356 BufferSyncInterface::kParseNoError : | 356 BufferSyncInterface::kParseNoError : |
| 357 BufferSyncInterface::kParseInvalidArguments; | 357 BufferSyncInterface::kParseInvalidArguments; |
| 358 } | 358 } |
| 359 | 359 |
| 360 BufferSyncInterface::ParseError GAPIGL::SetIndexBufferData(ResourceID id, | 360 BufferSyncInterface::ParseError GAPIGL::SetIndexBufferData(ResourceId id, |
| 361 unsigned int offset, | 361 unsigned int offset, |
| 362 unsigned int size, | 362 unsigned int size, |
| 363 const void *data) { | 363 const void *data) { |
| 364 IndexBufferGL *index_buffer = index_buffers_.Get(id); | 364 IndexBufferGL *index_buffer = index_buffers_.Get(id); |
| 365 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; | 365 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; |
| 366 return index_buffer->SetData(offset, size, data) ? | 366 return index_buffer->SetData(offset, size, data) ? |
| 367 BufferSyncInterface::kParseNoError : | 367 BufferSyncInterface::kParseNoError : |
| 368 BufferSyncInterface::kParseInvalidArguments; | 368 BufferSyncInterface::kParseInvalidArguments; |
| 369 } | 369 } |
| 370 | 370 |
| 371 BufferSyncInterface::ParseError GAPIGL::GetIndexBufferData(ResourceID id, | 371 BufferSyncInterface::ParseError GAPIGL::GetIndexBufferData(ResourceId id, |
| 372 unsigned int offset, | 372 unsigned int offset, |
| 373 unsigned int size, | 373 unsigned int size, |
| 374 void *data) { | 374 void *data) { |
| 375 IndexBufferGL *index_buffer = index_buffers_.Get(id); | 375 IndexBufferGL *index_buffer = index_buffers_.Get(id); |
| 376 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; | 376 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; |
| 377 return index_buffer->GetData(offset, size, data) ? | 377 return index_buffer->GetData(offset, size, data) ? |
| 378 BufferSyncInterface::kParseNoError : | 378 BufferSyncInterface::kParseNoError : |
| 379 BufferSyncInterface::kParseInvalidArguments; | 379 BufferSyncInterface::kParseInvalidArguments; |
| 380 } | 380 } |
| 381 | 381 |
| 382 BufferSyncInterface::ParseError GAPIGL::CreateVertexStruct( | 382 BufferSyncInterface::ParseError GAPIGL::CreateVertexStruct( |
| 383 ResourceID id, | 383 ResourceId id, |
| 384 unsigned int input_count) { | 384 unsigned int input_count) { |
| 385 if (id == current_vertex_struct_) validate_streams_ = true; | 385 if (id == current_vertex_struct_) validate_streams_ = true; |
| 386 VertexStructGL *vertex_struct = new VertexStructGL(input_count); | 386 VertexStructGL *vertex_struct = new VertexStructGL(input_count); |
| 387 vertex_structs_.Assign(id, vertex_struct); | 387 vertex_structs_.Assign(id, vertex_struct); |
| 388 return BufferSyncInterface::kParseNoError; | 388 return BufferSyncInterface::kParseNoError; |
| 389 } | 389 } |
| 390 | 390 |
| 391 BufferSyncInterface::ParseError GAPIGL::DestroyVertexStruct(ResourceID id) { | 391 BufferSyncInterface::ParseError GAPIGL::DestroyVertexStruct(ResourceId id) { |
| 392 if (id == current_vertex_struct_) validate_streams_ = true; | 392 if (id == current_vertex_struct_) validate_streams_ = true; |
| 393 return vertex_structs_.Destroy(id) ? | 393 return vertex_structs_.Destroy(id) ? |
| 394 BufferSyncInterface::kParseNoError : | 394 BufferSyncInterface::kParseNoError : |
| 395 BufferSyncInterface::kParseInvalidArguments; | 395 BufferSyncInterface::kParseInvalidArguments; |
| 396 } | 396 } |
| 397 | 397 |
| 398 BufferSyncInterface::ParseError GAPIGL::SetVertexInput( | 398 BufferSyncInterface::ParseError GAPIGL::SetVertexInput( |
| 399 ResourceID vertex_struct_id, | 399 ResourceId vertex_struct_id, |
| 400 unsigned int input_index, | 400 unsigned int input_index, |
| 401 ResourceID vertex_buffer_id, | 401 ResourceId vertex_buffer_id, |
| 402 unsigned int offset, | 402 unsigned int offset, |
| 403 unsigned int stride, | 403 unsigned int stride, |
| 404 vertex_struct::Type type, | 404 vertex_struct::Type type, |
| 405 vertex_struct::Semantic semantic, | 405 vertex_struct::Semantic semantic, |
| 406 unsigned int semantic_index) { | 406 unsigned int semantic_index) { |
| 407 switch (semantic) { | 407 switch (semantic) { |
| 408 case vertex_struct::POSITION: | 408 case vertex_struct::kPosition: |
| 409 if (semantic_index != 0) { | 409 if (semantic_index != 0) { |
| 410 return BufferSyncInterface::kParseInvalidArguments; | 410 return BufferSyncInterface::kParseInvalidArguments; |
| 411 } | 411 } |
| 412 break; | 412 break; |
| 413 case vertex_struct::NORMAL: | 413 case vertex_struct::kNormal: |
| 414 if (semantic_index != 0) { | 414 if (semantic_index != 0) { |
| 415 return BufferSyncInterface::kParseInvalidArguments; | 415 return BufferSyncInterface::kParseInvalidArguments; |
| 416 } | 416 } |
| 417 break; | 417 break; |
| 418 case vertex_struct::COLOR: | 418 case vertex_struct::kColor: |
| 419 if (semantic_index >= 2) { | 419 if (semantic_index >= 2) { |
| 420 return BufferSyncInterface::kParseInvalidArguments; | 420 return BufferSyncInterface::kParseInvalidArguments; |
| 421 } | 421 } |
| 422 break; | 422 break; |
| 423 case vertex_struct::TEX_COORD: | 423 case vertex_struct::kTexCoord: |
| 424 if (semantic_index >= 8) { | 424 if (semantic_index >= 8) { |
| 425 return BufferSyncInterface::kParseInvalidArguments; | 425 return BufferSyncInterface::kParseInvalidArguments; |
| 426 } | 426 } |
| 427 break; | 427 break; |
| 428 default: | 428 default: |
| 429 DLOG(FATAL) << "Not reached."; | 429 DLOG(FATAL) << "Not reached."; |
| 430 break; | 430 break; |
| 431 } | 431 } |
| 432 if (vertex_buffer_id == current_vertex_struct_) validate_streams_ = true; | 432 if (vertex_buffer_id == current_vertex_struct_) validate_streams_ = true; |
| 433 VertexStructGL *vertex_struct = vertex_structs_.Get(vertex_struct_id); | 433 VertexStructGL *vertex_struct = vertex_structs_.Get(vertex_struct_id); |
| 434 if (!vertex_struct || input_index >= vertex_struct->count()) | 434 if (!vertex_struct || input_index >= vertex_struct->count()) |
| 435 return BufferSyncInterface::kParseInvalidArguments; | 435 return BufferSyncInterface::kParseInvalidArguments; |
| 436 vertex_struct->SetInput(input_index, vertex_buffer_id, offset, stride, type, | 436 vertex_struct->SetInput(input_index, vertex_buffer_id, offset, stride, type, |
| 437 semantic, semantic_index); | 437 semantic, semantic_index); |
| 438 return BufferSyncInterface::kParseNoError; | 438 return BufferSyncInterface::kParseNoError; |
| 439 } | 439 } |
| 440 | 440 |
| 441 BufferSyncInterface::ParseError GAPIGL::SetVertexStruct(ResourceID id) { | 441 BufferSyncInterface::ParseError GAPIGL::SetVertexStruct(ResourceId id) { |
| 442 current_vertex_struct_ = id; | 442 current_vertex_struct_ = id; |
| 443 validate_streams_ = true; | 443 validate_streams_ = true; |
| 444 return BufferSyncInterface::kParseNoError; | 444 return BufferSyncInterface::kParseNoError; |
| 445 } | 445 } |
| 446 | 446 |
| 447 bool GAPIGL::ValidateStreams() { | 447 bool GAPIGL::ValidateStreams() { |
| 448 DCHECK(validate_streams_); | 448 DCHECK(validate_streams_); |
| 449 VertexStructGL *vertex_struct = vertex_structs_.Get(current_vertex_struct_); | 449 VertexStructGL *vertex_struct = vertex_structs_.Get(current_vertex_struct_); |
| 450 if (!vertex_struct) { | 450 if (!vertex_struct) { |
| 451 LOG(ERROR) << "Drawing with invalid streams."; | 451 LOG(ERROR) << "Drawing with invalid streams."; |
| 452 return false; | 452 return false; |
| 453 } | 453 } |
| 454 max_vertices_ = vertex_struct->SetStreams(this); | 454 max_vertices_ = vertex_struct->SetStreams(this); |
| 455 validate_streams_ = false; | 455 validate_streams_ = false; |
| 456 return max_vertices_ > 0; | 456 return max_vertices_ > 0; |
| 457 } | 457 } |
| 458 | 458 |
| 459 namespace { | 459 namespace { |
| 460 | 460 |
| 461 void PrimitiveTypeToGL(GAPIInterface::PrimitiveType primitive_type, | 461 void PrimitiveTypeToGL(command_buffer::PrimitiveType primitive_type, |
| 462 GLenum *gl_mode, | 462 GLenum *gl_mode, |
| 463 unsigned int *count) { | 463 unsigned int *count) { |
| 464 switch (primitive_type) { | 464 switch (primitive_type) { |
| 465 case GAPIInterface::POINTS: | 465 case command_buffer::kPoints: |
| 466 *gl_mode = GL_POINTS; | 466 *gl_mode = GL_POINTS; |
| 467 break; | 467 break; |
| 468 case GAPIInterface::LINES: | 468 case command_buffer::kLines: |
| 469 *gl_mode = GL_LINES; | 469 *gl_mode = GL_LINES; |
| 470 *count *= 2; | 470 *count *= 2; |
| 471 break; | 471 break; |
| 472 case GAPIInterface::LINE_STRIPS: | 472 case command_buffer::kLineStrips: |
| 473 *gl_mode = GL_LINE_STRIP; | 473 *gl_mode = GL_LINE_STRIP; |
| 474 ++*count; | 474 ++*count; |
| 475 break; | 475 break; |
| 476 case GAPIInterface::TRIANGLES: | 476 case command_buffer::kTriangles: |
| 477 *gl_mode = GL_TRIANGLES; | 477 *gl_mode = GL_TRIANGLES; |
| 478 *count *= 3; | 478 *count *= 3; |
| 479 break; | 479 break; |
| 480 case GAPIInterface::TRIANGLE_STRIPS: | 480 case command_buffer::kTriangleStrips: |
| 481 *gl_mode = GL_TRIANGLE_STRIP; | 481 *gl_mode = GL_TRIANGLE_STRIP; |
| 482 *count += 2; | 482 *count += 2; |
| 483 break; | 483 break; |
| 484 case GAPIInterface::TRIANGLE_FANS: | 484 case command_buffer::kTriangleFans: |
| 485 *gl_mode = GL_TRIANGLE_FAN; | 485 *gl_mode = GL_TRIANGLE_FAN; |
| 486 *count += 2; | 486 *count += 2; |
| 487 break; | 487 break; |
| 488 default: | 488 default: |
| 489 LOG(FATAL) << "Invalid primitive type"; | 489 LOG(FATAL) << "Invalid primitive type"; |
| 490 break; | 490 break; |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 } // anonymous namespace | 494 } // anonymous namespace |
| (...skipping 13 matching lines...) Expand all Loading... |
| 508 if (first + count > max_vertices_) { | 508 if (first + count > max_vertices_) { |
| 509 return BufferSyncInterface::kParseInvalidArguments; | 509 return BufferSyncInterface::kParseInvalidArguments; |
| 510 } | 510 } |
| 511 glDrawArrays(gl_mode, first, count); | 511 glDrawArrays(gl_mode, first, count); |
| 512 CHECK_GL_ERROR(); | 512 CHECK_GL_ERROR(); |
| 513 return BufferSyncInterface::kParseNoError; | 513 return BufferSyncInterface::kParseNoError; |
| 514 } | 514 } |
| 515 | 515 |
| 516 BufferSyncInterface::ParseError GAPIGL::DrawIndexed( | 516 BufferSyncInterface::ParseError GAPIGL::DrawIndexed( |
| 517 PrimitiveType primitive_type, | 517 PrimitiveType primitive_type, |
| 518 ResourceID index_buffer_id, | 518 ResourceId index_buffer_id, |
| 519 unsigned int first, | 519 unsigned int first, |
| 520 unsigned int count, | 520 unsigned int count, |
| 521 unsigned int min_index, | 521 unsigned int min_index, |
| 522 unsigned int max_index) { | 522 unsigned int max_index) { |
| 523 IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id); | 523 IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id); |
| 524 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; | 524 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; |
| 525 if (validate_effect_ && !ValidateEffect()) { | 525 if (validate_effect_ && !ValidateEffect()) { |
| 526 return BufferSyncInterface::kParseInvalidArguments; | 526 return BufferSyncInterface::kParseInvalidArguments; |
| 527 } | 527 } |
| 528 DCHECK(current_effect_); | 528 DCHECK(current_effect_); |
| 529 if (validate_streams_ && !ValidateStreams()) { | 529 if (validate_streams_ && !ValidateStreams()) { |
| 530 return BufferSyncInterface::kParseInvalidArguments; | 530 return BufferSyncInterface::kParseInvalidArguments; |
| 531 } | 531 } |
| 532 if ((min_index >= max_vertices_) || (max_index > max_vertices_)) { | 532 if ((min_index >= max_vertices_) || (max_index > max_vertices_)) { |
| 533 return BufferSyncInterface::kParseInvalidArguments; | 533 return BufferSyncInterface::kParseInvalidArguments; |
| 534 } | 534 } |
| 535 GLenum gl_mode = GL_POINTS; | 535 GLenum gl_mode = GL_POINTS; |
| 536 PrimitiveTypeToGL(primitive_type, &gl_mode, &count); | 536 PrimitiveTypeToGL(primitive_type, &gl_mode, &count); |
| 537 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer->gl_buffer()); | 537 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer->gl_buffer()); |
| 538 GLenum index_type = (index_buffer->flags() & index_buffer::INDEX_32BIT) ? | 538 GLenum index_type = (index_buffer->flags() & index_buffer::kIndex32Bit) ? |
| 539 GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; | 539 GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; |
| 540 GLuint index_size = (index_buffer->flags() & index_buffer::INDEX_32BIT) ? | 540 GLuint index_size = (index_buffer->flags() & index_buffer::kIndex32Bit) ? |
| 541 sizeof(GLuint) : sizeof(GLushort); // NOLINT | 541 sizeof(GLuint) : sizeof(GLushort); // NOLINT |
| 542 GLuint offset = first * index_size; | 542 GLuint offset = first * index_size; |
| 543 if (offset + count * index_size > index_buffer->size()) { | 543 if (offset + count * index_size > index_buffer->size()) { |
| 544 return BufferSyncInterface::kParseInvalidArguments; | 544 return BufferSyncInterface::kParseInvalidArguments; |
| 545 } | 545 } |
| 546 glDrawRangeElements(gl_mode, min_index, max_index, count, index_type, | 546 glDrawRangeElements(gl_mode, min_index, max_index, count, index_type, |
| 547 OffsetToPtr(offset)); | 547 OffsetToPtr(offset)); |
| 548 CHECK_GL_ERROR(); | 548 CHECK_GL_ERROR(); |
| 549 return BufferSyncInterface::kParseNoError; | 549 return BufferSyncInterface::kParseNoError; |
| 550 } | 550 } |
| 551 | 551 |
| 552 } // namespace command_buffer | 552 } // namespace command_buffer |
| 553 } // namespace o3d | 553 } // namespace o3d |
| OLD | NEW |