14#include <lagrange/ui/api.h>
15#include <lagrange/ui/Entity.h>
16#include <lagrange/ui/utils/math.h>
18#include <lagrange/ui/types/Color.h>
19#include <lagrange/ui/types/Texture.h>
21#include <lagrange/Logger.h>
23#if defined(__EMSCRIPTEN__)
24#include <webgl/webgl2.h>
33#include <unordered_map>
42 std::shared_ptr<Texture> texture =
nullptr;
44 Eigen::Vector4f color;
53 std::string display_name;
58 bool is_attrib =
false;
68 int value_dimension = 0;
73 bool transformable =
false;
74 bool colormap =
false;
79 float min_value = std::numeric_limits<float>::lowest();
80 float max_value = std::numeric_limits<float>::max();
89 int min_value = std::numeric_limits<int>::lowest();
90 int max_value = std::numeric_limits<int>::max();
104 constexpr static const StringID DepthTest =
"DepthTest"_hs;
105 constexpr static const StringID DepthMask =
"DepthMask"_hs;
106 constexpr static const StringID DepthFunc =
"DepthFunc"_hs;
107 constexpr static const StringID BlendEquation =
"BlendEquation"_hs;
108 constexpr static const StringID DrawBuffer =
"DrawBuffer"_hs;
109 constexpr static const StringID ReadBuffer =
"ReadBuffer"_hs;
110 constexpr static const StringID CullFaceEnabled =
"CullFaceEnabled"_hs;
111 constexpr static const StringID CullFace =
"CullFace"_hs;
112 constexpr static const StringID ColorMask =
"ColorMask"_hs;
114 constexpr static const StringID ScissorTest =
"ScissorTest"_hs;
115 constexpr static const StringID ScissorX =
"ScissorX"_hs;
116 constexpr static const StringID ScissorY =
"ScissorY"_hs;
117 constexpr static const StringID ScissorWidth =
"ScissorWidth"_hs;
118 constexpr static const StringID ScissortHeight =
"ScissortHeight"_hs;
123 constexpr static const StringID BlendDstRGB =
"BlendDstRGB"_hs;
124 constexpr static const StringID BlendSrcAlpha =
"BlendSrcAlpha"_hs;
125 constexpr static const StringID BlendDstAlpha =
"BlendDstAlpha"_hs;
128 constexpr static const StringID
Query =
"Query"_hs;
131 constexpr static const StringID
Pass =
"_Pass"_hs;
136 constexpr static const StringID PointSize =
"_PointSize"_hs;
139 constexpr static const StringID
Primitive =
"Primitive"_hs;
144enum ShaderInterface {
145 SHADER_INTERFACE_NONE = 0,
146 SHADER_INTERFACE_UNIFORM = 1,
147 SHADER_INTERFACE_ATTRIB = 2
155 ShaderInterface shaderInterface;
156 const ShaderValue& operator=(Eigen::Vector2f val)
const;
157 const ShaderValue& operator=(Eigen::Vector3f val)
const;
158 const ShaderValue& operator=(Eigen::Vector4f val)
const;
160 const ShaderValue& operator=(Eigen::Matrix2f val)
const;
161 const ShaderValue& operator=(Eigen::Matrix3f val)
const;
162 const ShaderValue& operator=(Eigen::Matrix4f val)
const;
163 const ShaderValue& operator=(Eigen::Affine3f val)
const;
164 const ShaderValue& operator=(Eigen::Projective3f val)
const;
173 const ShaderValue& operator=(
const std::vector<Eigen::Vector3f>& arr)
const;
176 const ShaderValue& set_array(
const float* data,
int n)
const;
177 const ShaderValue& set_array(
const int* data,
int n)
const;
178 const ShaderValue& set_array(
const unsigned int* data,
int n)
const;
184 const ShaderValue& set_vectors(
const Eigen::Vector2f* data,
int n)
const;
185 const ShaderValue& set_vectors(
const Eigen::Vector3f* data,
int n)
const;
186 const ShaderValue& set_vectors(
const Eigen::Vector4f* data,
int n)
const;
187 const ShaderValue& set_matrices(
const Eigen::Matrix2f* data,
int n,
bool transpose =
false)
189 const ShaderValue& set_matrices(
const Eigen::Matrix3f* data,
int n,
bool transpose =
false)
191 const ShaderValue& set_matrices(
const Eigen::Matrix4f* data,
int n,
bool transpose =
false)
193 const ShaderValue& set_matrices(
const Eigen::Affine3f* data,
int n,
bool transpose =
false)
204 : std::runtime_error(str)
207 void set_desc(
const std::string& desc) { m_desc = desc; }
208 const std::string& get_desc() {
return m_desc; }
214using ShaderDefines = std::vector<std::pair<std::string, std::string>>;
219 Shader(
const std::string& code,
const ShaderDefines& defines);
222 static void unbind();
224 const ShaderValue& operator[](
const std::string& name);
226 const std::string& get_source()
const;
227 std::string& get_source();
229 const ShaderDefines& get_defines()
const;
231 const std::unordered_map<StringID, ShaderValue>& uniforms()
const {
return m_uniforms; }
232 const std::unordered_map<StringID, ShaderValue>& attribs()
const {
return m_attribs; }
233 const std::unordered_map<StringID, std::string>& names()
const {
return m_names; }
235 const std::string& name(StringID
id)
const {
return m_names.at(
id); }
237 const ShaderValue& uniform(
const std::string& name)
const {
return uniform(string_id(name)); }
241 auto it = m_uniforms.find(
id);
242 if (it == m_uniforms.end())
return ShaderValue::none;
246 const ShaderValue& attrib(
const std::string& name)
const {
return attrib(string_id(name)); }
250 auto it = m_attribs.find(
id);
251 if (it == m_attribs.end())
return ShaderValue::none;
255 const std::unordered_map<StringID, int>& sampler_indices()
const {
return m_sampler_indices; }
257 const std::unordered_map<StringID, ShaderTextureProperty>& texture_properties()
const
259 return m_texture_properties;
262 const std::unordered_map<StringID, ShaderFloatProperty>& float_properties()
const
264 return m_float_properties;
267 const std::unordered_map<StringID, ShaderColorProperty>& color_properties()
const
269 return m_color_properties;
272 const std::unordered_map<StringID, ShaderVectorProperty>& vector_properties()
const
274 return m_vector_properties;
277 const std::unordered_map<StringID, ShaderBoolProperty>& bool_properties()
const
279 return m_bool_properties;
282 const std::unordered_map<StringID, ShaderIntProperty>& int_properties()
const
284 return m_int_properties;
287 void upload_default_values();
290 void process_properties(std::string& source);
293 std::unordered_map<StringID, ShaderValue> m_uniforms;
294 std::unordered_map<StringID, ShaderValue> m_attribs;
295 std::unordered_map<StringID, int> m_sampler_indices;
296 std::string m_source;
297 ShaderDefines m_defines;
299 std::unordered_map<StringID, ShaderTextureProperty> m_texture_properties;
300 std::unordered_map<StringID, ShaderFloatProperty> m_float_properties;
301 std::unordered_map<StringID, ShaderColorProperty> m_color_properties;
302 std::unordered_map<StringID, ShaderVectorProperty> m_vector_properties;
303 std::unordered_map<StringID, ShaderBoolProperty> m_bool_properties;
304 std::unordered_map<StringID, ShaderIntProperty> m_int_properties;
305 std::unordered_map<StringID, std::string> m_names;
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Rasterization pipeline option names.
Definition: Shader.h:103
static constexpr const StringID Pass
Use for transparency and polygon offset.
Definition: Shader.h:131
static constexpr const StringID PolygonMode
Rasterize as point/line/polygon, values: GL_POINT/GL_LINE/GL_FILL. Applies to GL_FRONT_AND_BACK by de...
Definition: Shader.h:134
static constexpr const StringID Query
Will only render entities with GLQuery of the same type.
Definition: Shader.h:128
static constexpr const StringID Primitive
Not set by default, use to override.
Definition: Shader.h:139
static constexpr const StringID BlendSrcRGB
Blend func separate.
Definition: Shader.h:122
bool normal
Semantics:
Definition: Shader.h:72