12#ifndef GAMP_DEMOS_REDSQUAREES2_HPP_
13#define GAMP_DEMOS_REDSQUAREES2_HPP_
36 bool m_animating =
true;
37 jau::fraction_timespec m_tlast;
43 m_initialized(false) { }
49 const PMVMat4f&
pmv() const noexcept {
return m_pmvMatUni->pmv(); }
50 bool animating() const noexcept {
return m_animating; }
59 "demos/glsl/bin",
"RedSquareShader");
61 "demos/glsl/bin",
"RedSquareShader");
70 if( !sp0->
add(
gl, vp0,
true) || !sp0->
add(
gl, fp0,
true) ) {
76 m_st.attachShaderProgram(
gl, sp0,
true);
80 pmv.getP().loadIdentity();
81 pmv.getMv().loadIdentity();
82 m_st.ownUniform(m_pmvMatUni,
true);
87 vertices->put( { -2, 2, 0,
91 m_st.ownAttribute(vertices,
true);
92 vertices->seal(
gl,
true);
96 assert(GL_FLOAT == vertices->compType());
97 colors->put( { 1, 0, 0, 1,
101 m_st.ownAttribute(colors,
true);
102 colors->seal(
gl,
true);
104 ::glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
105 ::glEnable(GL_DEPTH_TEST);
107 m_initialized = sp0->
inUse();
108 if( !m_initialized ) {
113 return m_initialized;
119 m_initialized =
false;
128 pmv.getP().loadIdentity();
130 const float aspect = 1.0f;
131 const float fovy_deg=45.0f;
132 const float aspect2 = ( (float) m_viewport.width() / (
float) m_viewport.height() ) / aspect;
133 const float zNear=1.0f;
134 const float zFar=100.0f;
136 m_st.useProgram(
gl,
true);
137 m_st.pushAllUniforms(
gl);
138 m_st.useProgram(
gl,
false);
143 if( !m_initialized ) {
147 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
149 m_st.useProgram(
gl,
true);
151 pmv.getMv().loadIdentity();
152 pmv.translateMv(0, 0, -10);
153 static float t_sum_ms = 0;
155 t_sum_ms += float( (when - m_tlast).to_ms() );
158 pmv.rotateMv(ang, 0, 0, 1);
159 pmv.rotateMv(ang, 0, 1, 0);
160 m_st.pushAllUniforms(
gl);
163 ::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
164 m_st.useProgram(
gl,
false);
169 std::string
toStringImpl() const noexcept
override {
return "RedSquareES2"; }
bool init(const WindowRef &win, const jau::fraction_timespec &when) override
Called by the drawable immediately after the render context is initialized.
void reshape(const WindowRef &win, const jau::math::Recti &viewport, const jau::fraction_timespec &when) override
Called by the drawable during the first repaint after the component has been resized.
void dispose(const WindowRef &win, const jau::fraction_timespec &when) override
Notifies the listener to perform the release of all renderer resources per context,...
Recti & viewport() noexcept
std::string toStringImpl() const noexcept override
void display(const WindowRef &win, const jau::fraction_timespec &when) override
Called by the drawable to initiate rendering by the client.
PMVMat4f & pmv() noexcept
const PMVMat4f & pmv() const noexcept
bool & animating() noexcept
const Recti & viewport() const noexcept
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(std::string_view name, GLsizei compsPerElement, bool normalized, GLsizei initialElementCount, GLenum vboUsage)
size_t defaultShaderCustomization(const GL &gl, bool preludeVersion=true, bool addDefaultPrecision=true, bool addDefaultDefines=true)
Default customization of this shader source code.
static ShaderCodeRef create(GLenum type, size_t count, const source_list_t &sources) noexcept
void destroy(GL &gl) noexcept
Detaches all shader codes and deletes the program.
static ShaderProgramRef create() noexcept
bool add(const ShaderCodeRef &shaderCode) noexcept
Adds a new shader to this program.
constexpr bool inUse() const noexcept
constexpr RenderListener(Private) noexcept
Private ctor for shared_ptr<RenderListener> instance method w/o public ctor.
std::string toString() const noexcept
const gamp::render::RenderContext * renderContext() const noexcept
void dispose(const jau::fraction_timespec &when) noexcept override
constexpr T adeg_to_rad(const T arc_degree) noexcept
Converts arc-degree to radians.
std::shared_ptr< GLUniformSyncPMVMat4f > GLUniformSyncPMVMat4fRef
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.