| 87 | } |
| 88 | |
| 89 | bool ShaderNode::initWithVertex(std::string_view vert, std::string_view frag) |
| 90 | { |
| 91 | if (vert.empty()) |
| 92 | vert = position_vert; |
| 93 | _vertFileName = vert; |
| 94 | _fragFileName = frag; |
| 95 | |
| 96 | loadShaderVertex(vert, frag); |
| 97 | |
| 98 | _time = 0; |
| 99 | _resolution = Vec2(SIZE_X, SIZE_Y); |
| 100 | |
| 101 | scheduleUpdate(); |
| 102 | |
| 103 | setContentSize(Size(SIZE_X, SIZE_Y)); |
| 104 | setAnchorPoint(Vec2(0.5f, 0.5f)); |
| 105 | |
| 106 | // init custom command |
| 107 | auto attrPosLoc = _programState->getAttributeLocation("a_position"); |
| 108 | |
| 109 | auto vertexLayout = _programState->getMutableVertexLayout(); |
| 110 | vertexLayout->setAttrib("a_position", attrPosLoc, backend::VertexFormat::FLOAT2, 0, false); |
| 111 | |
| 112 | float w = SIZE_X, h = SIZE_Y; |
| 113 | Vec2 vertices[6] = {Vec2(0.0f, 0.0f), Vec2(w, 0.0f), Vec2(w, h), Vec2(0.0f, 0.0f), Vec2(0.0f, h), Vec2(w, h)}; |
| 114 | vertexLayout->setStride(sizeof(Vec2)); |
| 115 | |
| 116 | /* |
| 117 | * TODO: the Y-coordinate of subclasses are flipped in metal |
| 118 | * |
| 119 | * keywords: AX_USE_METAL , AX_USE_GL |
| 120 | */ |
| 121 | |
| 122 | _customCommand.createVertexBuffer(sizeof(Vec2), 6, CustomCommand::BufferUsage::STATIC); |
| 123 | _customCommand.updateVertexBuffer(vertices, sizeof(vertices)); |
| 124 | |
| 125 | _customCommand.setDrawType(CustomCommand::DrawType::ARRAY); |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | void ShaderNode::loadShaderVertex(std::string_view vert, std::string_view frag) |
| 131 | { |
no test coverage detected