1 // Copyright 2016-2021 Doug Moen
2 // Licensed under the Apache License, version 2.0
3 // See accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0
4 
5 #include <libcurv/glsl.h>
6 
7 #include <libcurv/context.h>
8 #include <libcurv/function.h>
9 #include <libcurv/sc_compiler.h>
10 #include <libcurv/shape.h>
11 #include <libcurv/viewed_shape.h>
12 
13 namespace curv {
14 
15 const char glsl_header[] = "";
16 
glsl_function_export(const Shape_Program & shape,std::ostream & out)17 void glsl_function_export(const Shape_Program& shape, std::ostream& out)
18 {
19     SC_Compiler sc(out, SC_Target::glsl, shape.sstate_);
20     At_Program cx(shape);
21 
22     out << glsl_header;
23     if (shape.viewed_shape_) {
24         // output uniform variables for parametric shape
25         for (auto& p : shape.viewed_shape_->param_) {
26             out << "uniform " << p.second.pconfig_.sctype_ << " "
27                 << p.second.identifier_ << ";\n";
28         }
29     }
30     sc.define_function("dist", SC_Type::Num(4), SC_Type::Num(),
31         shape.dist_fun_, cx);
32     sc.define_function("colour", SC_Type::Num(4), SC_Type::Num(3),
33         shape.colour_fun_, cx);
34 }
35 
36 } // namespace
37