OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSLGLSLCodeGenerator.h" | 8 #include "SkSLGLSLCodeGenerator.h" |
9 | 9 |
10 #include "string.h" | 10 #include "string.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 fIndentation++; | 306 fIndentation++; |
307 for (const auto& f : intf.fVariable.fType.fields()) { | 307 for (const auto& f : intf.fVariable.fType.fields()) { |
308 this->writeModifiers(f.fModifiers); | 308 this->writeModifiers(f.fModifiers); |
309 this->writeType(*f.fType); | 309 this->writeType(*f.fType); |
310 this->writeLine(" " + f.fName + ";"); | 310 this->writeLine(" " + f.fName + ";"); |
311 } | 311 } |
312 fIndentation--; | 312 fIndentation--; |
313 this->writeLine("};"); | 313 this->writeLine("};"); |
314 } | 314 } |
315 | 315 |
316 void GLSLCodeGenerator::writeVarDeclaration(const VarDeclaration& decl) { | 316 void GLSLCodeGenerator::writeVarDeclarations(const VarDeclarations& decl) { |
317 ASSERT(decl.fVars.size() > 0); | 317 ASSERT(decl.fVars.size() > 0); |
318 this->writeModifiers(decl.fVars[0]->fModifiers); | 318 this->writeModifiers(decl.fVars[0].fVar->fModifiers); |
319 this->writeType(decl.fBaseType); | 319 this->writeType(decl.fBaseType); |
320 std::string separator = " "; | 320 std::string separator = " "; |
321 for (size_t i = 0; i < decl.fVars.size(); i++) { | 321 for (const auto& var : decl.fVars) { |
322 ASSERT(decl.fVars[i]->fModifiers == decl.fVars[0]->fModifiers); | 322 ASSERT(var.fVar->fModifiers == decl.fVars[0].fVar->fModifiers); |
323 this->write(separator); | 323 this->write(separator); |
324 separator = ", "; | 324 separator = ", "; |
325 this->write(decl.fVars[i]->fName); | 325 this->write(var.fVar->fName); |
326 for (const auto& size : decl.fSizes[i]) { | 326 for (const auto& size : var.fSizes) { |
327 this->write("["); | 327 this->write("["); |
328 this->writeExpression(*size, kTopLevel_Precedence); | 328 this->writeExpression(*size, kTopLevel_Precedence); |
329 this->write("]"); | 329 this->write("]"); |
330 } | 330 } |
331 if (decl.fValues[i]) { | 331 if (var.fValue) { |
332 this->write(" = "); | 332 this->write(" = "); |
333 this->writeExpression(*decl.fValues[i], kTopLevel_Precedence); | 333 this->writeExpression(*var.fValue, kTopLevel_Precedence); |
334 } | 334 } |
335 } | 335 } |
336 this->write(";"); | 336 this->write(";"); |
337 } | 337 } |
338 | 338 |
339 void GLSLCodeGenerator::writeStatement(const Statement& s) { | 339 void GLSLCodeGenerator::writeStatement(const Statement& s) { |
340 switch (s.fKind) { | 340 switch (s.fKind) { |
341 case Statement::kBlock_Kind: | 341 case Statement::kBlock_Kind: |
342 this->writeBlock((Block&) s); | 342 this->writeBlock((Block&) s); |
343 break; | 343 break; |
344 case Statement::kExpression_Kind: | 344 case Statement::kExpression_Kind: |
345 this->writeExpression(*((ExpressionStatement&) s).fExpression, kTopL
evel_Precedence); | 345 this->writeExpression(*((ExpressionStatement&) s).fExpression, kTopL
evel_Precedence); |
346 this->write(";"); | 346 this->write(";"); |
347 break; | 347 break; |
348 case Statement::kReturn_Kind: | 348 case Statement::kReturn_Kind: |
349 this->writeReturnStatement((ReturnStatement&) s); | 349 this->writeReturnStatement((ReturnStatement&) s); |
350 break; | 350 break; |
351 case Statement::kVarDeclaration_Kind: | 351 case Statement::kVarDeclarations_Kind: |
352 this->writeVarDeclaration(*((VarDeclarationStatement&) s).fDeclarati
on); | 352 this->writeVarDeclarations(*((VarDeclarationsStatement&) s).fDeclara
tion); |
353 break; | 353 break; |
354 case Statement::kIf_Kind: | 354 case Statement::kIf_Kind: |
355 this->writeIfStatement((IfStatement&) s); | 355 this->writeIfStatement((IfStatement&) s); |
356 break; | 356 break; |
357 case Statement::kFor_Kind: | 357 case Statement::kFor_Kind: |
358 this->writeForStatement((ForStatement&) s); | 358 this->writeForStatement((ForStatement&) s); |
359 break; | 359 break; |
360 case Statement::kWhile_Kind: | 360 case Statement::kWhile_Kind: |
361 this->writeWhileStatement((WhileStatement&) s); | 361 this->writeWhileStatement((WhileStatement&) s); |
362 break; | 362 break; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (fCaps.fStandard == GLCaps::kGLES_Standard) { | 448 if (fCaps.fStandard == GLCaps::kGLES_Standard) { |
449 this->write(" es"); | 449 this->write(" es"); |
450 } | 450 } |
451 this->writeLine(); | 451 this->writeLine(); |
452 for (const auto& e : program.fElements) { | 452 for (const auto& e : program.fElements) { |
453 switch (e->fKind) { | 453 switch (e->fKind) { |
454 case ProgramElement::kExtension_Kind: | 454 case ProgramElement::kExtension_Kind: |
455 this->writeExtension((Extension&) *e); | 455 this->writeExtension((Extension&) *e); |
456 break; | 456 break; |
457 case ProgramElement::kVar_Kind: { | 457 case ProgramElement::kVar_Kind: { |
458 VarDeclaration& decl = (VarDeclaration&) *e; | 458 VarDeclarations& decl = (VarDeclarations&) *e; |
459 if (decl.fVars.size() > 0 && decl.fVars[0]->fModifiers.fLayout.f
Builtin == -1) { | 459 if (decl.fVars.size() > 0 && |
460 this->writeVarDeclaration(decl); | 460 decl.fVars[0].fVar->fModifiers.fLayout.fBuiltin == -1) { |
| 461 this->writeVarDeclarations(decl); |
461 this->writeLine(); | 462 this->writeLine(); |
462 } | 463 } |
463 break; | 464 break; |
464 } | 465 } |
465 case ProgramElement::kInterfaceBlock_Kind: | 466 case ProgramElement::kInterfaceBlock_Kind: |
466 this->writeInterfaceBlock((InterfaceBlock&) *e); | 467 this->writeInterfaceBlock((InterfaceBlock&) *e); |
467 break; | 468 break; |
468 case ProgramElement::kFunction_Kind: | 469 case ProgramElement::kFunction_Kind: |
469 this->writeFunction((FunctionDefinition&) *e); | 470 this->writeFunction((FunctionDefinition&) *e); |
470 break; | 471 break; |
471 default: | 472 default: |
472 printf("%s\n", e->description().c_str()); | 473 printf("%s\n", e->description().c_str()); |
473 ABORT("unsupported program element"); | 474 ABORT("unsupported program element"); |
474 } | 475 } |
475 } | 476 } |
476 fOut = nullptr; | 477 fOut = nullptr; |
477 } | 478 } |
478 | 479 |
479 } | 480 } |
OLD | NEW |