18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 10:46:45 +01:00
Files
maszyna/rendering/geometrybank.h
T
maj00r 65a7bed64e fix(render): texture streaming by default with Vulkan only, the streamer after a fallback, failed banks tried again
After review of #555:

- gfx.textures.streaming is on by default with the Vulkan renderer only, the one it was measured with; with OpenGL it stays
  off as before. A value set in eu07.ini is kept for either renderer. A Vulkan renderer falling back to OpenGL as it starts
  goes without it. The default turned on is logged, as the settings are logged before the renderer is chosen.
- The geometry streamer stopped by the shutdown of a Vulkan renderer that failed to start resumes for the OpenGL renderer
  made after it (geometry_streamer::resume()); before, every streamed model stayed undrawn for the session.
- A bank whose load failed is tried again: 5 s after the first failure, twice as long after each one that follows, up to
  5 min, by the streamer as it's drawn and by load_now(). Only the first failure in a row is logged. A transient read error
  no longer leaves the model undrawn till a restart.
2026-11-30 20:56:03 +01:00

497 lines
29 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "model/ResourceManager.h"
#include "utilities/memorystats.h"
#include <array>
#include <atomic>
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
struct world_vertex;
namespace gfx {
struct basic_vertex {
glm::vec3 position; // 3d space
glm::vec3 normal; // 3d space
glm::vec2 texture; // uv space
glm::vec4 tangent; // xyz - tangent, w - handedness
basic_vertex() = default;
basic_vertex( glm::vec3 Position, glm::vec3 Normal, glm::vec2 Texture ) :
position( Position ), normal( Normal ), texture( Texture )
{}
static basic_vertex convert(world_vertex const &world, glm::dvec3 const &origin);
world_vertex to_world(glm::dvec3 const &origin = glm::dvec3(0.)) const;
void serialize( std::ostream&, bool const Tangent = false ) const;
void deserialize( std::istream&, bool const Tangent = false );
void serialize_packed( std::ostream&, bool const Tangent = false ) const;
void deserialize_packed( std::istream&, bool const Tangent = false );
};
struct vertex_userdata{
glm::vec4 data; // user data (for color or additional uv channels, not subject to post-processing)
void serialize( std::ostream& ) const;
void deserialize( std::istream& );
void serialize_packed( std::ostream& ) const;
void deserialize_packed( std::istream& );
};
// data streams carried in a vertex
enum stream {
none = 0x0,
position = 0x1,
normal = 0x2,
color = 0x4, // currently normal and colour streams are stored in the same slot, and mutually exclusive
texture = 0x8
};
unsigned int const basic_streams { stream::position | stream::normal | stream::texture };
unsigned int const color_streams { stream::position | stream::color | stream::texture };
struct stream_units {
std::vector<GLint> texture { GL_TEXTURE0 }; // unit associated with main texture data stream. TODO: allow multiple units per stream
};
using basic_index = std::uint32_t;
// where a chunk lies in the buffers of its bank, for an indirect draw command made on the cpu: count of indices (or of
// vertices), first index (or vertex), base vertex, whether the draw is indexed, and the primitive type
struct indirect_source {
std::uint32_t count { 0 };
std::uint32_t first { 0 };
std::int32_t basevertex { 0 };
bool indexed { false };
unsigned int type { 0 };
};
using vertex_array = std::vector<basic_vertex>;
using userdata_array = std::vector<vertex_userdata>;
using index_array = std::vector<basic_index>;
// the attributes of a vertex in the compact layout of the EU07M models: the tangent frame as a snorm16 quaternion (its w is negative
// where the bitangent is flipped), then the texture coordinates. with the position in a stream of its own a vertex takes 28 bytes
// against the 48 of basic_vertex, and the depth and shadow passes read 12 of them
struct compact_attributes {
std::array<std::int16_t, 4> qtangent { 0, 0, 0, 32767 };
glm::vec2 texture { 0.f, 0.f };
};
static_assert( sizeof( compact_attributes ) == 16 );
using position_array = std::vector<glm::vec3>;
using compact_array = std::vector<compact_attributes>;
// the vertices the compact streams stand for (the normal and the tangent from the quaternion)
auto decode_compact( position_array const &Positions, compact_array const &Attributes ) -> vertex_array;
// the data of a chunk of a streamed bank: the compact layout (positions and attributes) or basic_vertex, with indices or without
struct chunk_data {
index_array indices;
position_array positions;
compact_array attributes;
vertex_array vertices;
userdata_array userdata;
};
// the data of the chunks of a streamed bank, in the order the chunks were made in
using bank_data = std::vector<chunk_data>;
// where a streamed bank takes the data of its chunks from (modelstreaming): read by a thread of the streamer before the bank is
// drawn, or at once by the thread which reads its vertices
class geometry_source {
public:
virtual ~geometry_source() = default;
// the data of the chunks, in the compact layout or as basic_vertex (Plain). false with the reason when it can't be had. any thread
virtual auto load( bank_data &Data, bool const Plain, std::string &Error ) const -> bool = 0;
// what the data is of, for the log
virtual auto name() const -> std::string const & = 0;
};
// whether the data of a streamed bank is there
enum class residency : std::uint8_t {
resident, // in place, drawn and read; a bank which isn't streamed always is
absent, // not loaded yet, or let go of
loading, // asked of the streamer
failed // it couldn't be had: the bank draws nothing
};
void calculate_tangents( vertex_array &vertices, index_array const &indices, int const type );
void calculate_indices( index_array &Indices, vertex_array &Vertices, userdata_array &Userdata, float tolerancescale = 1.0f );
// generic geometry bank class, allows storage, update and drawing of geometry chunks
struct geometry_handle {
// constructors
geometry_handle() :
bank( 0 ), chunk( 0 )
{}
geometry_handle( std::uint32_t Bank, std::uint32_t Chunk ) :
bank( Bank ), chunk( Chunk )
{}
// methods
inline
operator std::uint64_t() const {
/*
return bank << 14 | chunk; }
*/
return ( std::uint64_t { bank } << 32 | chunk );
}
// members
/*
std::uint32_t
bank : 18, // 250k banks
chunk : 14; // 16k chunks per bank
*/
std::uint32_t bank;
std::uint32_t chunk;
};
class geometry_bank {
public:
// types:
// constructors:
// destructor:
virtual
~geometry_bank() {}
// methods:
// creates a new geometry chunk of specified type from supplied data. returns: handle to the chunk or NULL
auto create( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int const Type ) -> gfx::geometry_handle;
// creates a new indexed geometry chunk of specified type from supplied data. returns: handle to the chunk or NULL
auto create( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int const Type ) -> gfx::geometry_handle;
// creates a new chunk of the compact layout: positions and compact attributes, with indices or without. its vertices() are
// made from them when something reads them first. returns: handle to the chunk or NULL
auto create_compact( gfx::index_array &Indices, gfx::position_array &Positions, gfx::compact_array &Attributes, gfx::userdata_array &Userdata, unsigned int const Type ) -> gfx::geometry_handle;
// replaces vertex data of specified chunk with the supplied data, starting from specified offset
auto replace( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool;
// replaces the index and the vertex data of specified indexed chunk with the supplied data of the same counts. returns: false if the counts differ
auto replace( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry ) -> bool;
// adds supplied vertex data at the end of specified chunk
auto append( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, gfx::geometry_handle const &Geometry ) -> bool;
void erase( gfx::geometry_handle const &Geometry );
// draws geometry stored in specified chunk
auto draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) -> std::size_t;
// draws geometry stored in specified chunk N times via glDrawElementsInstanced*, as instances BaseInstance and onwards
auto draw_instanced( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, std::uint32_t const BaseInstance, unsigned int const Streams = basic_streams ) -> std::size_t;
// draws geometry stored in supplied sequence of chunks of the bank, in their order. the bank is free to combine them into fewer draw calls
auto draw_batch( gfx::geometry_handle const *First, gfx::geometry_handle const *Last, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) -> std::size_t;
// makes the data of specified chunk ready for drawing and tells where it lies. returns: false if there's nothing to draw
auto indirect_source( gfx::geometry_handle const &Geometry, gfx::indirect_source &Source ) -> bool;
// draws geometry stored in specified chunk with the command at Offset (bytes) in the bound draw indirect buffer,
// a glDrawElementsIndirect one for an indexed chunk, glDrawArraysIndirect otherwise
void draw_indirect( gfx::geometry_handle const &Geometry, std::intptr_t const Offset, unsigned int const Streams = basic_streams );
// draws chunks of the bank with Count commands from Offset (bytes) in the bound draw indirect buffer, Stride bytes apart,
// with a single glMultiDrawElementsIndirect (or glMultiDrawArraysIndirect). the chunks have to be of the type of the
// specified one and indexed alike. returns: false if the bank can't, nothing is drawn then
auto draw_indirect_multi( gfx::geometry_handle const &Geometry, std::intptr_t const Offset, std::uint32_t const Count, std::uint32_t const Stride ) -> bool;
// the buffers the bank keeps its geometry in, when they're shared with other banks: chunks of banks of the same group can go
// in one multi draw (draw_indirect_multi()). 0 when the bank has buffers of its own. valid once the chunks were made ready
// for drawing (indirect_source())
auto draw_group() const -> std::uint32_t;
// draws geometry stored in supplied list of chunks
template <typename Iterator_>
auto draw( Iterator_ First, Iterator_ Last, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) ->std::size_t {
std::size_t count { 0 };
while( First != Last ) {
count += draw( *First, Units, Streams ); ++First; }
return count; }
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
void release();
// provides direct access to index data of specfied chunk
auto indices( gfx::geometry_handle const &Geometry ) const -> gfx::index_array const &;
// the positions of the vertices of specified chunk, without the basic_vertex of a chunk of the compact layout being made
auto positions( gfx::geometry_handle const &Geometry ) const -> gfx::position_array;
// provides direct access to vertex data of specfied chunk
auto vertices( gfx::geometry_handle const &Geometry ) const -> gfx::vertex_array const &;
// provides direct access to vertex user data of specfied chunk
auto userdata( gfx::geometry_handle const &Geometry ) const -> gfx::userdata_array const &;
// primitive type of specified chunk, 0 if there's no such chunk
auto type( gfx::geometry_handle const &Geometry ) const -> unsigned int;
// what the chunks keep in the process (a copy of what went to the gpu), added to the counts: chunks and vertex bytes, index bytes,
// user data bytes
void count_memory( memory_count &Vertices, memory_count &Indices, memory_count &Userdata ) const;
// kind of geometry of specified chunk, GL_TRIANGLES, GL_TRIANGLE_STRIP...; no_primitive for a handle to no chunk
auto primitive( gfx::geometry_handle const &Geometry ) const -> unsigned int;
static constexpr unsigned int no_primitive { ~0u };
// the streaming of the geometry (modelstreaming, geometrystreamer.h)
// the chunks of the bank take their data from Source when they're drawn or read, and let go of it when they're unused for a
// while. set before the chunks are made (create_streamed())
void stream_from( std::shared_ptr<geometry_source const> Source );
// an empty chunk of a streamed bank, filled with the data of the bank. returns: handle to the chunk
auto create_streamed( unsigned int const Type ) -> gfx::geometry_handle;
auto streamed() const -> bool {
return m_source != nullptr; }
auto state() const -> gfx::residency {
return m_residency.load( std::memory_order_acquire ); }
// a bank about to be drawn: a streamed one is noted as used, and asked of the streamer when its data isn't there (the lower the
// Priority, the sooner). returns: whether it can be drawn. any thread
auto ready( float const Priority = 0.f ) -> bool;
// a streamed bank noted as used, and asked of the streamer without being drawn (the prefetch). any thread
void touch( float const Priority );
// the data of a streamed bank loaded now by the thread which asks, unless it's there; Pin keeps it for good
void load_now( bool const Pin ) const;
// the streamer: a load begun for an absent bank. returns: false when the bank isn't absent
auto begin_load( float const Priority ) -> bool;
// the streamer: the data of a load begun at Epoch taken, unless the bank was let go of or loaded since. returns: whether it was taken
auto adopt( bank_data &Data, std::uint32_t const Epoch ) -> bool;
// the streamer: the load begun at Epoch failed, the bank stays without its data
auto fail_load( std::uint32_t const Epoch ) -> bool;
// the loads failed one after another since the bank last had its data: the first one is logged, those trying again aren't
auto failures() const -> std::uint32_t {
return m_failures.load( std::memory_order_relaxed ); }
// the data of a streamed bank let go of, unless it's kept for good. the bank is asked for again when it's drawn
void evict();
auto epoch() const -> std::uint32_t {
return m_epoch.load( std::memory_order_acquire ); }
auto requested_priority() const -> float {
return m_priority.load( std::memory_order_relaxed ); }
auto last_used() const -> std::uint32_t {
return m_lastused.load( std::memory_order_relaxed ); }
auto pinned() const -> bool {
return m_pinned.load( std::memory_order_relaxed ); }
// the bytes of the data of the chunks, as the bank took them
auto data_bytes() const -> std::size_t {
return m_databytes.load( std::memory_order_relaxed ); }
auto source() const -> std::shared_ptr<geometry_source const> const & {
return m_source; }
// the layout the data of the streamed bank is to come in
auto plain_layout() const -> bool {
return false == compact_layout_(); }
protected:
// types:
struct geometry_chunk {
unsigned int type; // kind of geometry used by the chunk
// geometry data. for a chunk of the compact layout it's made from the compact streams when it's read first (vertices())
mutable gfx::vertex_array vertices;
gfx::index_array indices; // index data
gfx::userdata_array userdata;
// the compact layout (create_compact()): the positions and the attributes, empty for a chunk of basic_vertex
gfx::position_array positions;
gfx::compact_array attributes;
auto compact() const -> bool {
return false == positions.empty(); }
// NOTE: constructor doesn't copy provided geometry data, but moves it
geometry_chunk( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int Type ) :
type( Type )
{
vertices.swap( Vertices );
userdata.swap( Userdata );
}
// NOTE: constructor doesn't copy provided geometry data, but moves it
geometry_chunk( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int Type ) :
type( Type )
{
vertices.swap( Vertices );
userdata.swap( Userdata );
indices.swap( Indices );
}
};
using geometrychunk_sequence = std::vector<geometry_chunk>;
// methods
inline
auto chunk( gfx::geometry_handle const Geometry ) -> geometry_chunk & {
return m_chunks[ Geometry.chunk - 1 ]; }
inline
auto chunk( gfx::geometry_handle const Geometry ) const -> geometry_chunk const & {
return m_chunks[ Geometry.chunk - 1 ]; }
// a chunk of the compact layout turned into one of basic_vertex, before it's changed (replace(), append(), erase())
void make_plain( geometry_chunk &Chunk ) const;
// members:
geometrychunk_sequence m_chunks;
// the vertices of the compact chunks made when they're first read, by one of the threads reading them at a time
mutable std::mutex m_decodemutex;
// the buffers made of the chunks by one of the threads drawing the bank at a time (vulkan), and the data of a streamed bank taken
// or let go of meanwhile by none of them
mutable std::mutex m_buildmutex;
private:
// methods:
// the data taken by the chunks, with the locks held
void take_( bank_data &Data );
// a streamed bank got its data (adopt(), load_now()): the subclass makes its buffers anew. by default they're let go of
virtual void adopted_() { release_(); }
// whether the data of a streamed bank is to come in the compact layout, which the subclass keeps on the gpu as it is
virtual auto compact_layout_() const -> bool { return false; }
// a load of a streamed bank failed, with the locks held: the bank draws nothing and is tried again later (retry_due_())
void note_failure_();
// whether a failed bank is to be tried again: 5 s after its first failure, twice as long after each one that follows, up to 5 min
auto retry_due_() const -> bool;
// members:
std::shared_ptr<geometry_source const> m_source; // of a streamed bank
std::atomic<gfx::residency> m_residency { gfx::residency::resident };
std::atomic<std::uint32_t> m_failedat { 0 }; // geometry_streamer::now() the last load failed at
std::atomic<std::uint32_t> m_failures { 0 }; // the loads failed one after another since the bank last had its data
std::atomic<std::uint32_t> m_epoch { 0 }; // changed each time the data is taken or let go of
std::atomic<float> m_priority { 0.f }; // the one it was asked for with
std::atomic<std::uint32_t> m_lastused { 0 }; // geometry_streamer::now() it was drawn or touched last
std::atomic<bool> m_pinned { false };
std::atomic<std::size_t> m_databytes { 0 };
mutable std::mutex m_loadmutex; // load_now() by one thread at a time
private:
// methods:
// create() subclass details
virtual void create_( gfx::geometry_handle const &Geometry ) = 0;
// replace() subclass details
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
// draw() subclass details
virtual auto draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t = 0;
// draw_instanced() subclass details. Default implementation falls back to N regular draws.
virtual auto draw_instanced_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, std::uint32_t const BaseInstance, unsigned int const Streams ) -> std::size_t {
std::size_t count { 0 };
for( std::size_t i = 0; i < InstanceCount; ++i ) { count += draw_( Geometry, Units, Streams ); }
return count; }
// draw_batch() subclass details. Default implementation falls back to regular draw of each chunk.
virtual auto draw_batch_( gfx::geometry_handle const *First, gfx::geometry_handle const *Last, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t {
std::size_t count { 0 };
for( ; First != Last; ++First ) { count += draw_( *First, Units, Streams ); }
return count; }
// indirect_source() and draw_indirect() subclass details. by default the bank can't draw indirectly
virtual auto indirect_source_( gfx::geometry_handle const & /*Geometry*/, gfx::indirect_source & /*Source*/ ) -> bool { return false; }
virtual void draw_indirect_( gfx::geometry_handle const & /*Geometry*/, std::intptr_t const /*Offset*/, unsigned int const /*Streams*/ ) {}
virtual auto draw_indirect_multi_( gfx::geometry_handle const & /*Geometry*/, std::intptr_t const /*Offset*/, std::uint32_t const /*Count*/, std::uint32_t const /*Stride*/ ) -> bool { return false; }
// draw_group() subclass details. by default the bank keeps its geometry to itself
virtual auto draw_group_() const -> std::uint32_t { return 0; }
// resource release subclass details
virtual void release_() = 0;
};
// geometry bank manager, holds collection of geometry banks
using geometrybank_handle = geometry_handle;
class geometrybank_manager {
public:
// constructors
geometrybank_manager() = default;
// methods:
// performs a resource sweep
void update();
// registers a new geometry bank. returns: handle to the bank
auto register_bank(std::unique_ptr<geometry_bank> bank) -> gfx::geometrybank_handle;
// creates a new geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
auto create_chunk( gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, int const Type ) -> gfx::geometry_handle;
// creates a new indexed geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
auto create_chunk( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, unsigned int const Type ) -> gfx::geometry_handle;
// creates a new chunk of the compact layout in specified bank (geometry_bank::create_compact()). returns: handle to the chunk or NULL
auto create_chunk_compact( gfx::index_array &Indices, gfx::position_array &Positions, gfx::compact_array &Attributes, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, unsigned int const Type ) -> gfx::geometry_handle;
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
auto replace( gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool;
// replaces the index and the vertex data of specified indexed chunk with the supplied data of the same counts. returns: false if the counts differ
auto replace( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry ) -> bool;
// adds supplied vertex data at the end of specified chunk
auto append( gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry ) -> bool;
void erase( gfx::geometry_handle const &Geometry );
// draws geometry stored in specified chunk
void draw( gfx::geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
// draws geometry stored in specified chunk InstanceCount times via GPU instancing.
// The shader reads per-instance modelview matrices from instance_ssbo[gl_BaseInstance + gl_InstanceID].
void draw_instanced( gfx::geometry_handle const &Geometry, std::size_t const InstanceCount, std::uint32_t const BaseInstance, unsigned int const Streams = basic_streams );
// draws geometry stored in supplied sequence of chunks, in their order. neighbouring chunks of the same bank are passed to it together
void draw_batch( gfx::geometry_handle const *First, gfx::geometry_handle const *Last, unsigned int const Streams = basic_streams );
// makes the data of specified chunk ready for an indirect draw and tells where it lies. returns: false if there's nothing to draw
auto indirect_source( gfx::geometry_handle const &Geometry, gfx::indirect_source &Source ) -> bool;
// draws geometry stored in specified chunk with the command at Offset (bytes) in the bound draw indirect buffer
void draw_indirect( gfx::geometry_handle const &Geometry, std::intptr_t const Offset, unsigned int const Streams = basic_streams );
// draws chunks of the bank of the specified one, of its type and indexed alike, with Count commands from Offset in the bound
// draw indirect buffer, Stride bytes apart, in one call. returns: false if the bank can't, nothing is drawn then
auto draw_indirect_multi( gfx::geometry_handle const &Geometry, std::intptr_t const Offset, std::uint32_t const Count, std::uint32_t const Stride ) -> bool;
// what the chunks of a multi draw (draw_indirect_multi()) have to share, besides their type and whether they're indexed: the
// buffers of the bank of the specified chunk. the same for chunks of banks which share their buffers, the bank otherwise.
// valid once the chunk was made ready for drawing (indirect_source())
auto draw_group( gfx::geometry_handle const &Geometry ) const -> std::uint32_t;
// marks the bank of the chunk as used, as the draws do (the vulkan renderer marks the banks its walkers drew from, M2)
void mark_used( gfx::geometry_handle const &Geometry );
// the streaming of the geometry (geometry_bank::stream_from()): the chunks of the bank take their data from Source
void stream( gfx::geometrybank_handle const &Bank, std::shared_ptr<geometry_source const> Source );
// an empty chunk of a streamed bank. returns: handle to the chunk or NULL
auto create_chunk_streamed( gfx::geometrybank_handle const &Bank, unsigned int const Type ) -> gfx::geometry_handle;
// the data of a streamed bank loaded now and kept for good
void pin( gfx::geometrybank_handle const &Bank );
// a streamed bank noted as used and asked for ahead of its drawing (the prefetch); the lower the Priority, the sooner
void touch( gfx::geometrybank_handle const &Bank, float const Priority );
// whether the bank is streamed
auto streamed( gfx::geometrybank_handle const &Bank ) const -> bool;
template <typename Iterator_>
void draw( Iterator_ First, Iterator_ Last, unsigned int const Streams = basic_streams ) {
while( First != Last ) {
draw( *First, Streams );
++First; } }
// provides direct access to index data of specfied chunk
auto indices( gfx::geometry_handle const &Geometry ) const -> gfx::index_array const &;
// the positions of the vertices of specified chunk (geometry_bank::positions())
auto positions( gfx::geometry_handle const &Geometry ) const -> gfx::position_array;
// provides direct access to vertex data of specfied chunk
auto vertices( gfx::geometry_handle const &Geometry ) const -> gfx::vertex_array const &;
// what the banks keep in the process, for the debug panel: banks, chunks with their vertex bytes, index bytes and user data bytes
struct memory_data {
std::uint64_t banks { 0 };
memory_count vertices;
memory_count indices;
memory_count userdata;
};
auto memory() const -> memory_data;
// provides direct access to vertex data of specfied chunk
auto userdata( gfx::geometry_handle const &Geometry ) const -> gfx::userdata_array const &;
// primitive type of specified chunk, 0 if there's no such chunk
auto type( gfx::geometry_handle const &Geometry ) const -> unsigned int;
// kind of geometry of specified chunk
auto primitive( gfx::geometry_handle const &Geometry ) const -> unsigned int;
// sets target texture unit for the texture data stream
auto units() -> gfx::stream_units & { return m_units; }
// provides access to primitives count
auto primitives_count() const -> std::size_t const & { return m_primitivecount; }
auto primitives_count() -> std::size_t & { return m_primitivecount; }
private:
// types:
using geometrybanktimepoint_pair = std::pair< std::shared_ptr<geometry_bank>, resource_timestamp >;
using geometrybanktimepointpair_sequence = std::deque< geometrybanktimepoint_pair >;
// members:
geometrybanktimepointpair_sequence m_geometrybanks;
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
gfx::stream_units m_units;
// methods
inline
auto valid( gfx::geometry_handle const &Geometry ) const -> bool {
return ( ( Geometry.bank != 0 )
&& ( Geometry.bank <= m_geometrybanks.size() ) ); }
inline
auto bank( gfx::geometry_handle const Geometry ) -> geometrybanktimepointpair_sequence::value_type & {
return m_geometrybanks[ Geometry.bank - 1 ]; }
inline
auto bank( gfx::geometry_handle const Geometry ) const -> geometrybanktimepointpair_sequence::value_type const & {
return m_geometrybanks[ Geometry.bank - 1 ]; }
// members:
std::size_t m_primitivecount { 0 }; // number of drawn primitives
};
} // namespace gfx