12#ifndef GAMP_DEMOS_REDSQUAREES2_HPP_
13#define GAMP_DEMOS_REDSQUAREES2_HPP_
36 bool m_animating =
true;
37 jau::fraction_timespec m_tlast;
42 m_pmv(), m_initialized(false) { }
49 bool animating() const noexcept {
return m_animating; }
58 "demos/glsl/bin",
"RedSquareShader");
60 "demos/glsl/bin",
"RedSquareShader");
69 if( !sp0->
add(
gl, vp0,
true) || !sp0->
add(
gl, fp0,
true) ) {
75 m_st.attachShaderProgram(
gl, sp0,
true);
78 m_pmv.getP().loadIdentity();
79 m_pmv.getMv().loadIdentity();
85 vertices->put3f(-2, 2, 0);
86 vertices->put3f( 2, 2, 0);
87 vertices->put3f(-2, -2, 0);
88 vertices->put3f( 2, -2, 0);
89 m_st.ownAttribute(vertices,
true);
90 vertices->seal(
gl,
true);
94 assert(GL_FLOAT == vertices->compType());
95 colors->put4f(1, 0, 0, 1);
96 colors->put4f(0, 0, 1, 1);
97 colors->put4f(1, 0, 0, 1);
98 colors->put4f(1, 0, 0, 1);
99 m_st.ownAttribute(colors,
true);
100 colors->seal(
gl,
true);
102 ::glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
103 ::glEnable(GL_DEPTH_TEST);
105 m_initialized = sp0->
inUse();
106 if( !m_initialized ) {
111 return m_initialized;
117 m_initialized =
false;
125 m_pmv.getP().loadIdentity();
127 const float aspect = 1.0f;
128 const float fovy_deg=45.0f;
129 const float aspect2 = ( (float) m_viewport.width() / (
float) m_viewport.height() ) / aspect;
130 const float zNear=1.0f;
131 const float zFar=100.0f;
133 m_st.useProgram(
gl,
true);
134 m_st.pushAllUniforms(
gl);
135 m_st.useProgram(
gl,
false);
140 if( !m_initialized ) {
144 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
146 m_st.useProgram(
gl,
true);
147 m_pmv.getMv().loadIdentity();
148 m_pmv.translateMv(0, 0, -10);
149 static float t_sum_ms = 0;
151 t_sum_ms += float( (when - m_tlast).to_ms() );
154 m_pmv.rotateMv(ang, 0, 0, 1);
155 m_pmv.rotateMv(ang, 0, 1, 0);
156 m_st.pushAllUniforms(
gl);
159 ::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
160 m_st.useProgram(
gl,
false);
165 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(const std::string &name, GLsizei compsPerElement, bool normalized, GLsizei initialElementCount, GLenum vboUsage)
size_t defaultShaderCustomization(const GL &gl, bool preludeVersion, bool addDefaultPrecision)
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.
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.