27#ifndef EASY3D_RENDERER_RENDER_DEVICE_H
28#define EASY3D_RENDERER_RENDER_DEVICE_H
30#include <easy3d/core/types.h>
40 enum class Backend { opengl, vulkan };
43 enum class Topology { triangles, lines, points };
85 std::vector<vec3> positions_;
86 std::vector<std::uint32_t> source_ids_;
87 std::uint32_t source_count_;
123 std::vector<std::uint32_t>
indices = {},
124 Topology
topology = Topology::triangles,
126 std::shared_ptr<const PointData>
point_data = {});
134 const std::vector<std::uint32_t> &
indices()
const {
140 return primitive_ids_;
154 const std::vector<Vertex> vertices_;
155 const std::vector<std::uint32_t> indices_;
156 const Topology topology_;
157 const std::vector<std::uint32_t> primitive_ids_;
158 std::shared_ptr<const PointData> point_data_;
161 enum class TextureWrap { clamp_to_edge, repeat };
162 enum class TextureFilter { nearest, linear };
167 TextureWrap
wrap = TextureWrap::clamp_to_edge;
169 TextureFilter
filter = TextureFilter::nearest;
196 const std::vector<unsigned char> &
rgba()
const {
206 const std::uint32_t width_, height_;
207 const std::vector<unsigned char> rgba_;
211 enum class PointStyle { plain, sphere, surfel };
212 enum class LineStyle { plain, cylinder, cone };
373 std::vector<vec4> normalize_clipping_planes(
const std::vector<vec4> &planes);
376 mat4 screen_space_projection(std::uint32_t width, std::uint32_t height);
387 std::vector<unsigned char>
rgba;
409 enum class FrameReadback {
440 enum class TransparencyMethod {
468 FrameReadback
readback = FrameReadback::color_depth_ids;
533 virtual const std::string &
name()
const = 0;
574 std::uint32_t height,
575 const std::vector<DrawCommand> &commands,
589 std::uint32_t height,
590 const std::vector<DrawCommand> &commands,
592 std::uint32_t y) = 0;
610 virtual std::vector<FrameImage::Id>
sample_ids(std::uint32_t width,
611 std::uint32_t height,
612 const std::vector<DrawCommand> &commands,
615 std::uint32_t region_width,
616 std::uint32_t region_height) = 0;
648 std::unique_ptr<RenderDevice> create_device(
const DeviceOptions &options = {});
static Mat< N, M, T > identity()
Returns an identity matrix.
Definition mat.h:702
Immutable geometry snapshot submitted to a RenderDevice.
Definition render_device.h:112
const std::vector< Vertex > & vertices() const
Definition render_device.h:129
const std::vector< std::uint32_t > & primitive_ids() const
Definition render_device.h:139
const std::shared_ptr< const PointData > & point_data() const
Definition render_device.h:149
Topology topology() const
Definition render_device.h:144
const std::vector< std::uint32_t > & indices() const
Definition render_device.h:134
Immutable RGBA8 image with explicit sampler state.
Definition render_device.h:173
const Sampler & sampler() const
Definition render_device.h:201
std::uint32_t width() const
Definition render_device.h:186
std::uint32_t height() const
Definition render_device.h:191
const std::vector< unsigned char > & rgba() const
Definition render_device.h:196
Immutable point positions in draw order, mapped to original source slots.
Definition render_device.h:52
PointData & operator=(const PointData &)=delete
Copy assignment is disabled; snapshots are shared by const ownership.
std::uint32_t source_count() const
Definition render_device.h:80
virtual ~PointData()=default
Destroy the point-data snapshot.
const std::vector< vec3 > & positions() const
Definition render_device.h:70
const std::vector< std::uint32_t > & source_ids() const
Definition render_device.h:75
Backend-independent rendering, capture, and selection interface.
Definition render_device.h:524
virtual ScenePixel sample_pixel(std::uint32_t width, std::uint32_t height, const std::vector< DrawCommand > &commands, std::uint32_t x, std::uint32_t y)=0
Sample scene depth and IDs at a top-left framebuffer pixel.
virtual unsigned validation_errors() const =0
virtual DeviceCapabilities capabilities() const =0
virtual std::vector< std::uint32_t > select_points(const PointSelectionRequest &request)=0
Select point source slots inside a framebuffer polygon.
virtual const std::string & driver_version() const =0
virtual const std::string & name() const =0
virtual std::uint32_t supported_sample_counts(PointStyle style=PointStyle::plain) const =0
Query supported MSAA sample counts for a point style.
virtual std::uint64_t point_upload_count() const =0
virtual Backend backend() const =0
virtual std::vector< FrameImage::Id > sample_ids(std::uint32_t width, std::uint32_t height, const std::vector< DrawCommand > &commands, std::uint32_t x, std::uint32_t y, std::uint32_t region_width, std::uint32_t region_height)=0
Sample scene picking IDs over a top-left framebuffer rectangle.
virtual FrameImage render(std::uint32_t width, std::uint32_t height, const std::vector< DrawCommand > &commands, const RenderOptions &options={})=0
Render commands into an offscreen framebuffer and read back results.
virtual std::uint32_t supported_sample_counts(LineStyle style) const =0
Query supported MSAA sample counts for a line style.
virtual ~RenderDevice()=default
Destroy the backend device.
virtual std::uint32_t oit_dropped_fragments() const =0
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Vec< 4, int32_t > ivec4
A 4D point/vector of int32_t type.
Definition types.h:60
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46
Vec< 2, float > vec2
A 2D point/vector of float type.
Definition types.h:42
Optional effects and implementation choices reported by a device.
Definition render_device.h:472
bool eye_dome_lighting
Eye-dome lighting is available.
Definition render_device.h:478
bool native_large_points
Native large-point rasterization is enabled.
Definition render_device.h:482
std::vector< TransparencyMethod > transparency_methods
Supported transparency methods.
Definition render_device.h:480
bool ambient_occlusion
Screen-space ambient occlusion is available.
Definition render_device.h:476
bool shadow
Shadow mapping is available.
Definition render_device.h:474
Common diagnostics and physical-device selection parameters.
Definition render_device.h:417
bool validation
Enable backend validation diagnostics when supported.
Definition render_device.h:419
bool profiling
Enable backend profiling output when supported.
Definition render_device.h:423
bool use_native_large_points
Prefer native large points when supported; false forces portable expansion.
Definition render_device.h:427
bool sync_validation
Enable synchronization validation; implies validation.
Definition render_device.h:421
std::string device_name
Required physical-device name substring; empty accepts any compatible device.
Definition render_device.h:425
Complete backend-independent description of a draw operation.
Definition render_device.h:219
std::shared_ptr< const Geometry > geometry
Geometry snapshot to draw.
Definition render_device.h:220
bool eye_dome_lighting
Apply eye-dome lighting from scene depth; requires a full-viewport untextured overlay quad.
Definition render_device.h:278
mat4 model_view_projection
Model-to-clip transform in Easy3D/OpenGL convention.
Definition render_device.h:224
bool overlay_depth_test
Test triangle overlays against scene depth without writing depth or IDs; submit overlapping annotatio...
Definition render_device.h:254
mat4 model_view
Model-to-view transform for impostor geometry.
Definition render_device.h:335
mat4 projection
OpenGL-convention projection for impostor geometry.
Definition render_device.h:336
std::vector< vec4 > clipping_planes
Up to two view-space halfspaces retaining dot(plane, [position,1]) >= 0; overlays ignore them.
Definition render_device.h:314
mat4 shadow_matrix
Camera-clip to shadow-texture transform.
Definition render_device.h:306
bool shadow_background
Receive shadows while retaining the background picking ID.
Definition render_device.h:295
vec4 back_color
Back-face color when enabled.
Definition render_device.h:242
LineStyle line_style
Line rendering style.
Definition render_device.h:340
std::uint16_t depth_range_max
Encoded far endpoint; 0x8000 marks an invalid value.
Definition render_device.h:369
mat4 model
Model-to-world transform.
Definition render_device.h:237
vec3 eye
Eye position for material lighting.
Definition render_device.h:238
bool lighting_two_sides
Apply material lighting to both triangle sides.
Definition render_device.h:235
vec4 specular
Specular material color.
Definition render_device.h:241
bool ambient_occlusion
Apply screen-space ambient occlusion; color carries view-space radius and bias.
Definition render_device.h:286
bool overlay
Composite triangle annotations after the scene; overlays do not write scene depth or IDs.
Definition render_device.h:248
std::uint32_t object_id
Object ID written for picking.
Definition render_device.h:227
std::vector< vec4 > object_clipping_planes
Up to two halfspaces in the geometry's local space; empty means derive them from clipping_planes and ...
Definition render_device.h:321
vec4 color
Uniform RGBA multiplier.
Definition render_device.h:226
bool line_screen_space_width
Expand plain lines in screen space.
Definition render_device.h:351
float line_width
Plain-line width in framebuffer pixels.
Definition render_device.h:346
bool lighting
Enable fixed directional diffuse lighting.
Definition render_device.h:231
bool transparent
Blend scene triangles using color.w opacity; writes scene depth and picking IDs.
Definition render_device.h:271
bool overlay_independent_depth
Use an independent depth buffer for 3D HUD triangles; requires overlay and excludes overlay_depth_tes...
Definition render_device.h:260
unsigned shadow_map_size
Shadow-map side length in pixels.
Definition render_device.h:307
float sphere_radius
View-space radius for sphere/surfel impostors, independent of model scale.
Definition render_device.h:331
std::shared_ptr< const Image > texture
Optional texture; null selects white.
Definition render_device.h:221
bool shadow_caster
Rasterize scene triangles into the shadow map as well as the scene.
Definition render_device.h:291
bool shadow
Apply a full-viewport multiplicative shadow overlay; color carries darkness, softness,...
Definition render_device.h:302
float shininess
Specular exponent.
Definition render_device.h:243
bool depth_bias
Definition render_device.h:355
PointStyle point_style
Point rendering style.
Definition render_device.h:328
ivec4 viewport
Top-left framebuffer viewport; zero selects the full target.
Definition render_device.h:230
void set_depth_range(const vec2 &range)
Definition render_device.cpp:35
float point_size
Plain-point diameter in framebuffer pixels.
Definition render_device.h:329
std::uint16_t depth_range_min
Encoded near endpoint; 0x8000 marks an invalid value.
Definition render_device.h:368
bool discard_clipped_primitives
Reject a primitive if any control vertex is outside.
Definition render_device.h:322
mat3 normal_matrix
Inverse-transpose normal transform.
Definition render_device.h:225
bool distinct_back_color
Use back_color for back-facing triangles.
Definition render_device.h:236
vec3 light
Directional light for material lighting.
Definition render_device.h:239
vec2 depth_range() const
Definition render_device.cpp:45
bool material_lighting
Enable Renderer material lighting.
Definition render_device.h:234
vec3 sphere_light
View-space directional light for point impostors.
Definition render_device.h:332
bool scene_depth_texture
Sample center-sample scene depth as grayscale through UVs; requires an untextured overlay without ove...
Definition render_device.h:265
vec4 ambient
Ambient material color.
Definition render_device.h:240
float line_radius
View-space radius for cylinder/cone impostors, independent of model scale.
Definition render_device.h:343
Object and primitive IDs associated with one pixel.
Definition render_device.h:391
std::uint32_t primitive
Primitive ID, or UINT32_MAX when provenance is unavailable.
Definition render_device.h:395
std::uint32_t object
Object ID, or UINT32_MAX for the background.
Definition render_device.h:393
CPU-readable color, depth, and picking data captured from a frame.
Definition render_device.h:381
std::vector< unsigned char > rgba
Tightly packed RGBA8 color pixels, top row first.
Definition render_device.h:387
std::vector< float > depth
Per-pixel depth in [0,1]; clear depth is 1.
Definition render_device.h:389
std::vector< Id > ids
Per-pixel picking IDs; background objects use UINT32_MAX.
Definition render_device.h:400
std::uint32_t height
Captured framebuffer height in pixels.
Definition render_device.h:385
std::uint32_t width
Captured framebuffer width in pixels.
Definition render_device.h:383
Inputs for selection of point centers inside a screen polygon.
Definition render_device.h:500
mat4 model_view_projection
Transform from point-local coordinates to OpenGL clip coordinates.
Definition render_device.h:508
std::vector< std::uint32_t > words
Selection bitset, one bit per source slot.
Definition render_device.h:506
bool deselect
Clear bits inside the polygon instead of setting them.
Definition render_device.h:514
std::shared_ptr< const PointData > points
Immutable point positions and source-slot mapping.
Definition render_device.h:502
std::vector< vec4 > local_clipping_planes
Up to two local-space halfspaces that points must satisfy.
Definition render_device.h:516
std::uint32_t height
Framebuffer height in pixels.
Definition render_device.h:512
std::vector< vec2 > polygon
Polygon in top-left framebuffer pixel coordinates.
Definition render_device.h:504
std::uint32_t width
Framebuffer width in pixels.
Definition render_device.h:510
Common frame-rendering parameters.
Definition render_device.h:458
TransparencyMethod transparency
Composite method for transparent commands.
Definition render_device.h:464
unsigned peel_layers
Depth-peeling layer limit; zero requests the backend's maximum.
Definition render_device.h:466
FrameReadback readback
Scene data copied back from the rendered frame.
Definition render_device.h:468
unsigned samples
Requested MSAA sample count; one disables MSAA.
Definition render_device.h:462
vec4 background
RGBA clear color.
Definition render_device.h:460
Texture addressing and filtering configuration.
Definition render_device.h:165
TextureFilter filter
Interpolation used when sampling between texels.
Definition render_device.h:169
TextureWrap wrap
Addressing mode for texture coordinates outside the image.
Definition render_device.h:167
Color/depth/ID result for one scene pixel.
Definition render_device.h:431
float depth
Scene depth in [0,1], defaulting to the clear value.
Definition render_device.h:435
Per-vertex data consumed by a draw command.
Definition render_device.h:91
vec3 position
Position in geometry-local coordinates.
Definition render_device.h:93
vec3 normal
Surface normal.
Definition render_device.h:95
vec2 texcoord
Texture coordinate.
Definition render_device.h:99
vec4 color
RGBA vertex color.
Definition render_device.h:97
vec4 highlight
Definition render_device.h:104