Class TCastleRenderUnlitMesh
Unit
Declaration
type TCastleRenderUnlitMesh = class(TObject)
Description
Render a set of vertexes, with optional indexes. Can be used multiple times, to render the same vertexes many times.
This is a deliberately simple and thin wrapper over creating and drawing a bunch of vertexes on modern GPUs. E.g. on OpenGL(ES) it creates 1 VBO (vertex buffer object) for position data and optional 1 VBO for indexes (if SetIndexes is ever called).
Make sure all usage is within the same rendering context. This has to be created and destroyed while the OpenGL(ES) context is active.
This is suitable to render only trivial unlit (or invisible) meshes. This is not a full-featured mesh renderer. Some deliberate limitations / hardcoded assumptions to keep this class simple:
It doesn't define any per-vertex attributes other than vertex positions.
If it uses indexes, it always uses 16-bit indexes, not 32-bit. So it works even with OpenGLES 2.0 (not 3.0) or WebGL 1.0.
Always passes vectors as 4D (in homogeneous coordinates). 4D coordinates are useful e.g. for shadow volume quads.
It follows various current RenderContext state, like
TRenderContext.DepthTest,TRenderContext.LineWidth– it doesn't control this state.
For a full-featured mesh rendering, just use TCastleScene, and construct your mesh as TIndexedTriangleSetNode or TIndexedFaceSetNode, see https://castle-engine.io/viewport_and_scenes_from_code#_building_a_mesh_using_code .
The things you really have to set before rendering are:
Vertexes, using
SetVertexes.Matrix (combined projection * camera * model transformation)
ModelViewProjection.That's it, the rest has sensible defaults. You can just call
Render.
For shading this uses a simple shader:
If
UseColor(defaultTrue) then the shader writesColorto the color buffer. Effectively this makes unlit rendering.Note: This class does not set up blending if
Coloralpha is less than 1. If you want blending, set it yourself usingTRenderContext.BlendingEnableand disable usingTRenderContext.BlendingDisable.If
UseColorisFalsethen the shader writes undefined value to the color buffer.But it still writes proper values to depth and stencil.
This is esp. useful when you render things with color buffer disabled (using
RenderContext.ColorChannels := []). The rendering may still be useful, e.g. to fill depth buffer (for shadow maps), stencil buffer, or define shape for GPU occlusion query.Note: This class does not configure
RenderContext.ColorChannels. It is up to you to decide how to hide from user the undefined effect this has on the color buffer.
Example usage:
SavedDepthTest := RenderContext.DepthTest; RenderContext.DepthTest := true; Mesh := TCastleRenderUnlitMesh.Create(true); try Mesh.Color := Yellow; Mesh.ModelViewProjection := RenderContext.ProjectionMatrix * RenderingCamera.CurrentMatrix; Mesh.SetVertexes([ Vector3(0, 0, 0, 1), Vector3(10, 0, 0, 1), Vector3(0, 10, 0, 1) ], false); Mesh.Render(pmTriangles); finally FreeAndNil(Mesh) end; RenderContext.DepthTest := SavedDepthTest;
Source: base_rendering/castlerenderprimitives_render_unlit_mesh.inc (line 111).
Hierarchy
- TObject
- TCastleRenderUnlitMesh
Generated by PasDoc 0.17.0.snapshot.