diff options
author | dan sinclair <dj2@everburning.com> | 2019-04-24 11:56:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-24 11:56:42 -0400 |
commit | bb89603891bb30c8e058439c79a21eae0758f0c9 (patch) | |
tree | 87dfa467ceb81065ed225d56a93374d6e7bd3e0b /src/amberscript/parser.cc | |
parent | 4736b0f710021856fdfbcbef1d7b685d7eb363c7 (diff) | |
download | amber-bb89603891bb30c8e058439c79a21eae0758f0c9.tar.gz |
[amberscript] Extend DRAW_ARRAYS parsing. (#487)
This CL extends the parsing of the DRAW_ARRAYS command to allow dropping
the COUNT and START_IDX parameters as per the spec.
Fixes #474, #475.
Diffstat (limited to 'src/amberscript/parser.cc')
-rw-r--r-- | src/amberscript/parser.cc | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc index e11252a..6babdc9 100644 --- a/src/amberscript/parser.cc +++ b/src/amberscript/parser.cc @@ -994,6 +994,9 @@ Result Parser::ParseRun() { if (!pipeline->IsGraphics()) return Result("RUN command requires graphics pipeline"); + if (pipeline->GetVertexBuffers().empty()) + return Result("RUN DRAW_ARRAY requires attached vertex buffer"); + token = tokenizer_->NextToken(); if (!token->IsString() || token->AsString() != "AS") return Result("missing AS for RUN command"); @@ -1009,35 +1012,55 @@ Result Parser::ParseRun() { return Result("invalid topology for RUN command: " + token->AsString()); token = tokenizer_->NextToken(); - if (!token->IsString() || token->AsString() != "START_IDX") - return Result("missing START_IDX for RUN command"); + uint32_t start_idx = 0; + uint32_t count = 0; + if (!token->IsEOS() && !token->IsEOL()) { + if (!token->IsString() || token->AsString() != "START_IDX") + return Result("missing START_IDX for RUN command"); - token = tokenizer_->NextToken(); - if (!token->IsInteger()) { - return Result("invalid START_IDX value for RUN command: " + - token->ToOriginalString()); - } - if (token->AsInt32() < 0) - return Result("START_IDX value must be >= 0 for RUN command"); - uint32_t start_idx = token->AsUint32(); + token = tokenizer_->NextToken(); + if (!token->IsInteger()) { + return Result("invalid START_IDX value for RUN command: " + + token->ToOriginalString()); + } + if (token->AsInt32() < 0) + return Result("START_IDX value must be >= 0 for RUN command"); + start_idx = token->AsUint32(); - token = tokenizer_->NextToken(); - if (!token->IsString() || token->AsString() != "COUNT") - return Result("missing COUNT for RUN command"); + token = tokenizer_->NextToken(); - token = tokenizer_->NextToken(); - if (!token->IsInteger()) { - return Result("invalid COUNT value for RUN command: " + - token->ToOriginalString()); + if (!token->IsEOS() && !token->IsEOL()) { + if (!token->IsString() || token->AsString() != "COUNT") + return Result("missing COUNT for RUN command"); + + token = tokenizer_->NextToken(); + if (!token->IsInteger()) { + return Result("invalid COUNT value for RUN command: " + + token->ToOriginalString()); + } + if (token->AsInt32() <= 0) + return Result("COUNT value must be > 0 for RUN command"); + + count = token->AsUint32(); + } + } + // If we get here then we never set count, as if count was set it must + // be > 0. + if (count == 0) { + count = + pipeline->GetVertexBuffers()[0].buffer->ElementCount() - start_idx; + } + + if (start_idx + count > + pipeline->GetVertexBuffers()[0].buffer->ElementCount()) { + return Result("START_IDX plus COUNT exceeds vertex buffer data size"); } - if (token->AsInt32() <= 0) - return Result("COUNT value must be > 0 for RUN command"); auto cmd = MakeUnique<DrawArraysCommand>(pipeline, PipelineData{}); cmd->SetLine(line); cmd->SetTopology(topo); cmd->SetFirstVertexIndex(start_idx); - cmd->SetVertexCount(token->AsUint32()); + cmd->SetVertexCount(count); command_list_.push_back(std::move(cmd)); return ValidateEndOfStatement("RUN command"); |