MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / MakeEffect

Method MakeEffect

extensions/olcPGEX_Shaders.h:487–535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485
486
487 olc::Effect Shade::MakeEffect(const olc::EffectConfig& premade)
488 {
489 // Construct Vertex Shader
490 std::string sVertexShader =
491 SHADER_HEADER
492 "layout(location = 0) in vec3 inPos; \n"
493 "layout(location = 1) in vec4 inCol; \n";
494
495 for (size_t i = 0; i < premade.nInputs; i++)
496 {
497 sVertexShader.append("layout(location = " + std::to_string(2 + i) + ") in vec2 inUV" + std::to_string(1 + i) + "; \n");
498 }
499
500 for (size_t i = 0; i < premade.nInputs; i++)
501 {
502 sVertexShader.append("out vec2 xUV" + std::to_string(1 + i) + "; \n");
503 }
504
505 sVertexShader.append("out vec4 xCol; \n");
506 sVertexShader.append(premade.sVertexSource);
507
508
509 // Construct Pixel Shader
510 std::string sPixelShader =
511 SHADER_HEADER
512 "in vec4 xCol; \n";
513
514 for (size_t i = 0; i < premade.nInputs; i++)
515 {
516 sPixelShader.append("in vec2 xUV" + std::to_string(1 + i) + "; \n");
517 }
518
519 for (size_t i = 0; i < premade.nInputs; i++)
520 {
521 sPixelShader.append("uniform sampler2D tex" + std::to_string(1 + i) + ";\n");
522 }
523
524 for (const auto& attribute : premade.vAttributes)
525 {
526 sPixelShader.append("uniform " + std::get<1>(attribute) + " " + std::get<0>(attribute) + " = " + std::get<2>(attribute) + ";\n");
527 }
528
529 sPixelShader.append("out vec4 pix_out;\n");
530 sPixelShader.append(premade.sPixelSource);
531
532 olc::Effect effect = ConstructShader(sVertexShader, sPixelShader);
533 effect.SetSlots(uint32_t(premade.nInputs), uint32_t(premade.nOutputs));
534 return effect;
535 }
536
537
538 void Shade::OnBeforeUserCreate()

Callers 1

OnUserCreateMethod · 0.80

Calls 1

SetSlotsMethod · 0.80

Tested by 1

OnUserCreateMethod · 0.64