11#ifndef JAU_GAMP_GRAPH_GL_RENDERSTATE_HPP_
12#define JAU_GAMP_GRAPH_GL_RENDERSTATE_HPP_
32 using namespace gamp::render::gl;
33 using namespace gamp::render::gl::glsl;
48 constexpr static std::string_view thisKey =
"gamp.graph.gl.RenderState" ;
123 : m_rs(rs), gcu_PMVMatrix(rs.gcu_PMVMatrix)
144 bool setPMVMat01,
bool pass1,
bool throwOnError) {
145 if( rs.m_id != rsId ) {
147 gcu_PMVMatrix = rs.gcu_PMVMatrix;
148 gcu_Weight->scalar() = rs.m_weight;
149 gcu_StaticColor->vec4f() = rs.m_staticColor;
153 if( rs.m_sp && rs.m_sp->inUse() ) {
173 std::string sb(
"ProgramLocal[rsID ");
174 sb.append(std::to_string(rsId)).append(
"\n");
176 sb.append(gcu_PMVMatrix->toString()).append(
", ").append(
"\n");
177 sb.append(gcu_StaticColor->toString()).append(
", ");
178 sb.append(gcu_Weight->toString()).append(
"]");
194 bool m_useFrustumClipping;
200 static int getNextID() {
return nextID++; }
208 : m_id( getNextID() ),
210 m_weight(1), m_staticColor(1, 1, 1, 1),
212 m_clipFrustum(), m_useFrustumClipping(false),
213 m_hintBits(0), m_debugBits(0), m_sp(nullptr)
216 constexpr int id() const noexcept {
return m_id; }
237 if( *spNext == *m_sp ) {
238 m_sp->useProgram(
gl,
true);
242 m_sp->notifyNotInUse();
245 m_sp->useProgram(
gl,
true);
264 constexpr float weight() const noexcept {
return m_weight; }
269 constexpr int aaQuality() const noexcept {
return m_aaQuality; }
274 constexpr int sampleCount() const noexcept {
return m_sampleCount; }
279 m_useFrustumClipping=
true;
287 constexpr int hintBits() const noexcept {
return m_hintBits; }
288 constexpr bool hintBitsSet(
int bits)
const noexcept {
return bits == ( m_hintBits & bits ); }
292 constexpr int debugBits() const noexcept {
return m_debugBits; }
293 constexpr bool debugBitsSet(
int mask)
const noexcept {
return mask == ( m_debugBits & mask ); }
306 if( m_sp && ( updateLocation || 0 >
data.location() ) ) {
307 const bool ok = 0 <=
data.setLocation(
gl, m_sp->program());
308 if( throwOnError && !ok ) {
328 updateLocation = updateLocation || 0 >
data.location();
329 if( m_sp && updateLocation ) {
330 updateData = 0 <=
data.setLocation(
gl, m_sp->program());
331 if( throwOnError && !updateData ) {
340 return !updateLocation;
351 if( m_sp && ( updateLocation || 0 >
data.location() ) ) {
352 const bool ok = 0 <=
data.setLocation(
gl, m_sp->program());
353 if( throwOnError && !ok ) {
371 return "RenderState["+(m_sp ? m_sp->toString() :
"n/a")+
"]";
static constexpr std::string_view gcu_StaticColor
static constexpr std::string_view gcu_Weight
ProgramLocal(RenderState &rs)
bool update(GL &gl, RenderState &rs, bool updateLocation, RenderMode renderMode, bool setPMVMat01, bool pass1, bool throwOnError)
constexpr int getRenderStateId() const noexcept
static constexpr int MIN_AA_SAMPLE_COUNT
Minimum pass2 AA sample count {@value} for Graph Region AA GraphRegion::renderMode(): RenderMode::vba...
static constexpr int BITHINT_GLOBAL_DEPTH_TEST_ENABLED
Bitfield hint, if set stating globally enabled GL#GL_DEPTH_TEST, otherwise disabled.
void setHintBits(int bits) noexcept
void disableFrustumClipping() noexcept
static constexpr int MAX_AA_SAMPLE_COUNT
Maximum pass2 AA sample count {@value} for Graph Region AA GraphRegion::renderMode(): RenderMode::vba...
constexpr int debugBits() const noexcept
constexpr int hintBits() const noexcept
constexpr float weight() const noexcept
bool updateUniformLoc(GL &gl, bool updateLocation, GLUniformData &data, bool throwOnError)
bool updateAttributeLoc(GL &gl, bool updateLocation, GLArrayData &data, bool throwOnError)
void clearHintBits(int bits) noexcept
static constexpr int DEFAULT_AA_SAMPLE_COUNT
Default pass2 AA sample count {@value} for Graph Region AA GraphRegion::renderMode(): RenderMode::vba...
RenderState(jau::math::util::PMVMat4f &pmvMat)
Create a RenderState, a composition of RegionRenderer.
constexpr bool hintBitsSet(int bits) const noexcept
jau::math::geom::Frustum * clipFrustum()
Returns the optional Mv-premultiplied clipping Frustum or nullptr if unused.
jau::math::util::PMVMat4f & getMatrix() noexcept
static constexpr int clipAAQuality(int v)
Returns clipped AA quality value to [MIN_AA_QUALITY..MAX_AA_QUALITY].
constexpr int id() const noexcept
constexpr int aaQuality() const noexcept
Returns pass2 AA-quality rendering value for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT.
bool setShaderProgram(GL &gl, ShaderProgramRef &spNext)
Sets the current ShaderProgram and enables it.
static constexpr int MAX_AA_QUALITY
Maximum pass2 AA-quality rendering {@value} for Graph Region AA GraphRegion::renderMode(): RenderMode...
constexpr int sampleCount() const noexcept
Returns pass2 AA sample count for Graph Region AA render-modes: VBAA_RENDERING_BIT or Region#MSAA_REN...
void clearDebugBits(int mask) noexcept
int setAAQuality(int v)
Sets pass2 AA-quality rendering value clipped to the range [Region#MIN_AA_QUALITY....
static constexpr int MIN_AA_QUALITY
Minimum pass2 AA-quality rendering {@value} for Graph Region AA GraphRegion::renderMode(): RenderMode...
bool updateUniformDataLoc(GL &gl, bool updateLocation, bool updateData, GLUniformData &data, bool throwOnError)
static constexpr int DEFAULT_AA_QUALITY
Default pass2 AA-quality rendering {@value} for Graph Region AA GraphRegion::renderMode(): RenderMode...
void setDebugBits(int mask) noexcept
static constexpr int DEBUG_LINESTRIP
static constexpr int BITHINT_BLENDING_ENABLED
Bitfield hint, if set stating enabled GL#GL_BLEND, otherwise disabled.
constexpr bool debugBitsSet(int mask) const noexcept
constexpr bool isShaderProgramInUse() const noexcept
Return whether the current ShaderProgram is in use.
int setSampleCount(int v)
Sets pass2 AA sample count clipped to the range [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COU...
constexpr ShaderProgramRef & shaderProgram() noexcept
Return the current ShaderProgram.
const jau::math::util::PMVMat4f & getMatrix() const noexcept
jau::math::Vec4f & staticColor() noexcept
constexpr const ShaderProgramRef & shaderProgram() const noexcept
Return the current ShaderProgram.
static bool isWeightValid(float v)
const jau::math::Vec4f & staticColor() const noexcept
constexpr bool usesFrustumClipping() const noexcept
void destroy()
Only nullifies ShaderProgram reference owned by RegionRenderer.
static constexpr int clipAASampleCount(int v)
Returns clipped AA sample-count to [MIN_AA_SAMPLE_COUNT..MAX_AA_SAMPLE_COUNT].
void setFrustumClipping(const jau::math::geom::Frustum &clipFrustum) noexcept
Set the optional clipping Frustum, which shall be pre-multiplied with the Mv-matrix or null to disabl...
Interface for a generic data buffer to be used for OpenGL arrays.
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
ordered_atomic< int, std::memory_order_seq_cst > sc_atomic_int
SC atomic integral scalar integer.
std::shared_ptr< GLUniformSyncPMVMat4f > GLUniformSyncPMVMat4fRef
std::shared_ptr< GLUniformScalarF32 > GLUniformScalarF32Ref
std::shared_ptr< GLUniformVec4f > GLUniformVec4fRef
std::shared_ptr< ShaderProgram > ShaderProgramRef
RenderMode
Render mode bits being part of the shader-selection-key.
constexpr bool hasVariableWeight(RenderMode renderMode) noexcept
PMVMatrix4< float > PMVMat4f