#ifndef GAMP_DEMOS_REDSQUAREES2_HPP_
#define GAMP_DEMOS_REDSQUAREES2_HPP_
#include <cstdio>
private:
bool m_initialized;
bool m_animating = true;
public:
m_pmv(), m_initialized(false) { }
bool animating()
const noexcept {
return m_animating; }
bool&
animating()
noexcept {
return m_animating; }
m_tlast = when;
"demos/glsl/bin", "RedSquareShader");
"demos/glsl/bin", "RedSquareShader");
if( !vp0 || !fp0 ) {
win->dispose(when);
return false;
}
vp0->defaultShaderCustomization(
gl,
true,
true);
fp0->defaultShaderCustomization(
gl,
true,
true);
if( !sp0->add(
gl, vp0,
true) || !sp0->add(
gl, fp0,
true) ) {
win->dispose(when);
return false;
}
vertices->reserve(4);
vertices->put3f(-2, 2, 0);
vertices->put3f( 2, 2, 0);
vertices->put3f(-2, -2, 0);
vertices->put3f( 2, -2, 0);
vertices->seal(
gl,
true);
assert(GL_FLOAT == vertices->compType());
colors->put4f(1, 0, 0, 1);
colors->put4f(0, 0, 1, 1);
colors->put4f(1, 0, 0, 1);
colors->put4f(1, 0, 0, 1);
::glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
::glEnable(GL_DEPTH_TEST);
m_initialized = sp0->inUse();
if( !m_initialized ) {
win->dispose(when);
}
return m_initialized;
}
m_initialized = false;
}
const float aspect = 1.0f;
const float fovy_deg=45.0f;
const float aspect2 = ( (float) m_viewport.
width() / (
float) m_viewport.
height() ) / aspect;
const float zNear=1.0f;
const float zFar=100.0f;
}
if( !m_initialized ) {
return;
}
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static float t_sum_ms = 0;
if( m_animating ) {
t_sum_ms += float( (when - m_tlast).to_ms() );
}
::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_tlast = when;
}
std::string
toStringImpl()
const noexcept override {
return "RedSquareES2"; }
};
#endif
Recti & viewport() noexcept
std::string toStringImpl() const noexcept override
void dispose(const WindowRef &, const jau::fraction_timespec &) override
Notifies the listener to perform the release of all renderer resources per context,...
PMVMat4f & pmv() noexcept
void display(const WindowRef &, const jau::fraction_timespec &when) override
Called by the drawable to initiate rendering by the client.
bool animating() const noexcept
static GLContext & downcast(RenderContext *rc)
Downcast dereferenced given RenderContext* to GLContext&, throws exception if signature doesn't match...
static server_ref createGLSL(const std::string &name, GLsizei compsPerElement, bool normalized, GLsizei initialElementCount, GLenum vboUsage)
static ShaderCodeRef create(GLenum type, size_t count, const source_list_t &sources) noexcept
static ShaderProgramRef create() noexcept
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
void destroy(GL &gl)
Calls release(gl, true, true, true).
void ownUniform(const GLUniformDataRef &data, bool own)
Bind the GLUniform lifecycle to this ShaderState.
void useProgram(GL &gl, bool on)
Turns the shader program on or off.
void pushAllUniforms(const GL &gl)
Same as pushUniform(), but for all active uniforms.
void ownAttribute(const GLArrayDataRef &attr, bool own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
bool attachShaderProgram(GL &gl, const ShaderProgramRef &prog, bool enable)
Attach or switch a shader program.
constexpr RenderListener(Private) noexcept
Private ctor for shared_ptr<RenderListener> instance method w/o public ctor.
std::string toString() const noexcept
constexpr Matrix4 & loadIdentity() noexcept
Set this matrix to identity.
constexpr value_type height() const noexcept
constexpr value_type width() const noexcept
constexpr Mat4 & getP() noexcept
Returns the projection matrix (P).
constexpr SyncMats4f & getSyncPMv() noexcept
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
constexpr Mat4 & getMv() noexcept
Returns the modelview matrix (Mv).
constexpr_cxx26 PMVMatrix4 & rotateMv(const float ang_rad, const float x, const float y, const float z) noexcept
Rotate the modelview matrix by the given axis and angle in radians.
constexpr PMVMatrix4 & translateMv(float x, float y, float z) noexcept
Translate the modelview matrix.
PMVMatrix4 & perspectiveP(const float fovy_rad, const float aspect, const float zNear, const float zFar)
Multiply the projection matrix with the perspective/frustum matrix.
constexpr T adeg_to_rad(const T arc_degree) noexcept
Converts arc-degree to radians.
GLArrayDataServerRef< float > GLFloatArrayDataServerRef
std::shared_ptr< ShaderProgram > ShaderProgramRef
std::shared_ptr< ShaderCode > ShaderCodeRef
std::shared_ptr< Window > WindowRef
PMVMatrix4< float > PMVMat4f
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...
constexpr uint64_t to_ms() const noexcept
Returns time in milliseconds.