Lagrange
render.h
1/*
2 * Copyright 2021 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/api.h>
15#include <lagrange/ui/components/GLMesh.h>
16#include <lagrange/ui/components/VertexData.h>
17#include <lagrange/ui/types/Camera.h>
18#include <lagrange/ui/types/FrameBuffer.h>
19#include <lagrange/ui/types/Shader.h>
20#include <lagrange/ui/types/ShaderLoader.h>
21#include <tuple>
22
23
24namespace lagrange {
25namespace ui {
26
27class Material;
28
29namespace utils {
30namespace render {
31
38LA_UI_API Eigen::Matrix4f offset_depth(const Eigen::Projective3f& perspective, int layer_index);
39
40
49LA_UI_API void set_render_pass_defaults(GLScope& scope);
50
51
56LA_UI_API std::pair<Eigen::Vector3f, Eigen::Vector3f> compute_perpendicular_plane(
57 Eigen::Vector3f direction);
58
59
60} // namespace render
61
62
63} // namespace utils
64
65
66//==============================================================
67/*
68 New rendering system pipeline utils
69*/
70//==============================================================
71struct Transform;
72
73/*
74 Sets shader uniforms (PV, PVinv, M, NMat, screen_size) based on camera and optional transform
75 Adjusts viewport glViewport if transform contains viewport transform
76*/
77LA_UI_API void set_render_transforms(
78 GLScope& scope,
79 Shader& shader,
80 const Camera& camera,
81 const Transform* transform = nullptr);
82
83
84LA_UI_API void render_vertex_data(const VertexData& vd, GLenum primitive, GLsizei per_element_size);
85
86LA_UI_API GLenum get_gl_primitive(const PrimitiveType& p);
87
88LA_UI_API GLsizei get_gl_primitive_size(const PrimitiveType& p);
89LA_UI_API GLsizei get_gl_primitive_size(GLenum primitive_enum);
90
91
92LA_UI_API std::shared_ptr<VertexData> generate_cube_vertex_data(bool edges = false);
93LA_UI_API std::shared_ptr<VertexData> generate_quad_vertex_data();
94
95LA_UI_API GLMesh generate_quad_mesh_gpu();
96
97
98LA_UI_API void update_vao(VertexData& vertex_data);
99
100
101LA_UI_API entt::resource<Shader>
102get_or_load_shader(ShaderCache& cache, const std::string& generic_path, bool virtual_fs = false);
103
104
105template <typename BufferComponent>
106bool set_mesh_geometry_layout(
107 const Registry& registry,
108 const Entity mesh_geometry_entity,
109 const int& location,
110 VertexData& vertex_data)
111{
112 const auto* buffer_component = registry.try_get<BufferComponent>(mesh_geometry_entity);
113
114 vertex_data.attribute_dimensions[location] = BufferComponent::dimension;
115
116 if (buffer_component && buffer_component->buffer) {
117 vertex_data.attribute_buffers[location] = buffer_component->buffer;
118 return true;
119 } else {
120 vertex_data.attribute_buffers[location] = nullptr;
121 return false;
122 }
123}
124
125LA_UI_API int get_gl_attribute_dimension(GLenum attrib_type);
126
132LA_UI_API void update_vertex_data(
133 const GLMesh& glmesh,
134 const Shader& shader,
135 VertexData& glvd,
136 IndexingMode indexing,
137 entt::id_type submesh_index);
138
139} // namespace ui
140} // namespace lagrange
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API Eigen::Projective3f perspective(float fovy, float aspect, float zNear, float zFar)
Constructs perspective projection matrix.
Definition: math.cpp:52
LA_UI_API void update_vertex_data(const GLMesh &glmesh, const Shader &shader, VertexData &glvd, IndexingMode indexing, entt::id_type submesh_index)
Assigns buffers from GLMesh to GLVertexData to Shader specified locations.
Definition: render.cpp:432
Main namespace for Lagrange.
Definition: AABBIGL.h:30