11#ifndef JAU_GAMP_GRAPH_GL_REGION_HPP_
12#define JAU_GAMP_GRAPH_GL_REGION_HPP_
60 int m_num_vertices, m_num_indices;
73 : m_renderMode(m), m_array(
GLFloatArrayDataServer::createGLSLInterleaved(arrayCompsPerElement(m), false, 256, GL_STATIC_DRAW)),
92 GLsizei
indexCount() const noexcept {
return m_num_indices; }
93 GLsizei
vertexCount() const noexcept {
return m_num_vertices; }
102 m_array->seal(
gl, seal_);
103 m_indices->seal(
gl, seal_);
109 void pushVertex(
const Vertex& v,
const Vec3f& normal) {
111 m_array->put3f(v.
coord());
114 m_array->put3f(normal);
118 void pushVertex(
const Vertex& v,
const Vec3f& normal,
const Vec4f& color) {
120 m_array->put3f(v.coord());
121 m_array->put3f(v.texCoord());
123 m_array->put3f(normal);
126 m_array->put4f(color);
130 void pushIndices(uint32_t i, uint32_t j, uint32_t k) {
132 m_indices->putN(i, j, k);
135 void pushNewVerticesIdx(
const Vertex& vertIn1,
const Vertex& vertIn2,
const Vertex& vertIn3,
const Vec3f& normal) {
136 pushIndices(m_num_vertices, m_num_vertices+1, m_num_vertices+2);
137 pushVertex(vertIn1, normal);
138 pushVertex(vertIn2, normal);
139 pushVertex(vertIn3, normal);
150 jau::PLAIN_PRINT(
true,
"add.0 num[vertices %d, indices %d]", m_num_vertices, m_num_indices);
162 m_array->growIfNeeded(verticeCount * m_array->compsPerElem());
165 uint32_t idxOffset = m_num_vertices;
166 if( vertsIn.
size() >= 3 ) {
170 for(
const Vertex& v : vertsIn) {
171 pushVertex(v,
shape.normal());
173 constexpr static uint32_t max_index = std::numeric_limits<uint32_t>::max() /
sizeof(uint32_t);
180 uint32_t tv0Idx = triInVertices[0].id();
181 if ( max_index - idxOffset > tv0Idx ) {
183 pushIndices(tv0Idx+idxOffset,
184 triInVertices[1].
id()+idxOffset,
185 triInVertices[2].
id()+idxOffset);
188 pushNewVerticesIdx(triInVertices[0], triInVertices[1], triInVertices[2],
shape.normal());
194 jau::PLAIN_PRINT(
true,
"add.x num[vertices %d, indices %d (%d)]", m_num_vertices,
195 m_num_indices, m_indices->elemCount() * m_indices->compsPerElem());
199 assert(m_num_indices == m_indices->elemCount() * m_indices->compsPerElem());
232 if( 0 == pass2SampleCount ) {
242 if( m_lastRenderMode != curRenderMode ) {
245 }
else if( Region.isGraphAA(curRenderModes) &&
246 ( lastPass2Quality != pass2Quality || lastPass2SampleCount != pass2SampleCount ) ) {
250 updateImpl(
gl, renderer, curRenderModes);
252 drawImpl(
gl, renderer, curRenderModes);
253 clearDirtyBits(DIRTY_SHAPE|DIRTY_STATE);
254 lastRenderModes = curRenderModes;
255 lastPass2Quality = pass2Quality;
256 lastPass2SampleCount = pass2SampleCount;
258 renderer.useProgram(
gl,
true);
260 m_array->enableBuffer(
gl,
true);
261 m_indices->bindBuffer(
gl,
true);
263 ::glEnable(GL_BLEND);
264 ::glBlendEquation(GL_FUNC_ADD);
265 ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
267 ::glDrawElements(GL_TRIANGLES, m_indices->elemCount() * m_indices->compsPerElem(), GL_UNSIGNED_INT,
nullptr);
270 m_indices->bindBuffer(
gl,
false);
271 m_array->enableBuffer(
gl,
false);
277 int m_lastPass2Quality = -1;
278 int m_lastPass2SampleCount = -1;
317 void clearDirtyBits(
DirtyBits v) { m_dirty &= ~v; }
321 std::string r(
"Region[");
323 .append(
", dirty "+
to_string(m_dirty)).append(
", vertices ").append(std::to_string(m_num_vertices))
324 .append(
", indices ").append(std::to_string(m_num_indices))
325 .append(
", box ").append(m_box.toString()).append(
"]");
A Generic shape objects which is defined by a list of Outlines.
std::array< Vertex, 3 > trivert_t
constexpr const Vec3f & texCoord() const noexcept
constexpr const Vec3f & coord() const noexcept
constexpr DirtyBits dirtyBits() const noexcept
void draw(GL &gl, GraphRenderer &renderer)
Renders the associated OGL objects specifying current width/hight of window for optional multi pass r...
constexpr bool hasColorChannel() const noexcept
constexpr const AABBox3f & bounds() const noexcept
JAU_MAKE_BITFIELD_ENUM_STRING_MEMBER(DirtyBits, shape, state)
constexpr RenderMode renderMode() const noexcept
constexpr bool hasNormalChannel() const noexcept
void markStateDirty() noexcept
Mark this region's render-state dirty, i.e.
constexpr bool isStateDirty() const noexcept
Returns true if this region's state is dirty, see markStateDirty().
constexpr bool isShapeDirty() const noexcept
Returns true if this region's shape are dirty, see markShapeDirty().
jau::darray< uint32_t, glmemsize_t > u32buffer_t
void addOutlineShape(GL &gl, OutlineShape &shape)
static constexpr int DEFAULT_TWO_PASS_TEXTURE_UNIT
constexpr GLsizei arrayCompsPerElement() const noexcept
void markShapeDirty() noexcept
Mark this region's shape dirty, i.e.
GLsizei vertexCount() const noexcept
void seal(GL &gl, bool seal_)
void addOutlineShape(OutlineShape &shape)
GLsizei indexCount() const noexcept
GraphRegion(RenderMode m)
std::string toString() noexcept
const RenderState & renderState() const noexcept
static constexpr std::string_view gca_Color
Color attribute (optional), USE_COLOR_CHANNEL:
static constexpr std::string_view gca_Vertex
The vertex attribute.
static constexpr std::string_view gca_CurveParam
Curve texture coord attribute.
static constexpr std::string_view gca_Normal
Normal attribute (optional), USE_NORMAL_CHANNEL:
The RenderState is owned by GraphRenderer.
constexpr int aaQuality() const noexcept
Returns pass2 AA-quality rendering value for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT.
constexpr int sampleCount() const noexcept
Returns pass2 AA sample count for Graph Region AA render-modes: VBAA_RENDERING_BIT or Region#MSAA_REN...
Implementation of a dynamic linear array storage, aka vector, including relative positional access.
constexpr size_type size() const noexcept
Like std::vector::size().
Axis Aligned Bounding Box.
constexpr bool is_set(const E mask, const E bits) noexcept
GLArrayDataServer< float > GLFloatArrayDataServer
GLsizeiptr glmemsize_t
Compatible with ssize_t.
GLArrayDataServerRef< float > GLFloatArrayDataServerRef
GLArrayDataServer< uint32_t > GLUIntArrayDataServer
GLArrayDataServerRef< uint32_t > GLUIntArrayDataServerRef
constexpr bool hasNormalChannel(RenderMode m) noexcept
jau::darray< Vertex, uint32_t > VertexList
RenderMode
Render mode bits being part of the shader-selection-key.
std::shared_ptr< Triangle > TriangleRef
constexpr bool hasColorChannel(RenderMode m) noexcept
jau::darray< TriangleRef, uint32_t > TriangleRefList
@ none
One pass none rendering either using no AA or underlying full-screen AA (fsaa) nor extra channels nor...
@ msaa
MSAA based Anti-Aliasing, a two pass region rendering, slower and more resource hungry (FBO with samp...
@ vbaa
View based Anti-Aliasing, a two pass region rendering, slower and more resource hungry (FBO),...
@ colorchannel
If set, a color channel attribute per vertex is added to the stream, otherwise static color can being...
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.
Author: Sven Gothel sgothel@jausoft.com Copyright Gothel Software e.K.
void PLAIN_PRINT(const bool printPrefix, const char *format,...) noexcept
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
std::string to_string(const bit_order_t v) noexcept
Return std::string representation of the given bit_order_t.