12#ifndef GAMP_DEMOS_REDSQUAREES2_HPP_
13#define GAMP_DEMOS_REDSQUAREES2_HPP_
35 GLUniformSyncPMVMat4f m_pmvMatUni;
37 bool m_animating =
true;
38 jau::fraction_timespec m_tlast;
43 m_pmvMatUni(
"gcu_PMVMatrix"),
46 m_st.manage(m_pmvMatUni);
53 const PMVMat4f&
pmv() const noexcept {
return m_pmvMatUni.pmv(); }
54 bool animating() const noexcept {
return m_animating; }
65 "demos/glsl/bin",
"RedSquareShader");
67 "demos/glsl/bin",
"RedSquareShader");
76 if( !sp0->
add(
gl, vp0,
true) || !sp0->
add(
gl, fp0,
true) ) {
82 m_st.attachShaderProgram(
gl, sp0,
true);
86 pmv.getP().loadIdentity();
87 pmv.getMv().loadIdentity();
92 vertices->put( { -2, 2, 0,
96 m_st.manage(vertices);
97 vertices->seal(
gl,
true);
101 assert(GL_FLOAT == vertices->compType());
102 colors->put( { 1, 0, 0, 1,
107 colors->seal(
gl,
true);
109 ::glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
110 ::glEnable(GL_DEPTH_TEST);
112 m_initialized = sp0->
inUse();
113 if( !m_initialized ) {
118 std::cout <<
"Init:\n";
119 std::cout << m_st.toString(
true) <<
"\n";
120 return m_initialized;
126 m_initialized =
false;
135 pmv.getP().loadIdentity();
137 const float aspect = 1.0f;
138 const float fovy_deg=45.0f;
139 const float aspect2 = ( (float) m_viewport.width() / (
float) m_viewport.height() ) / aspect;
140 const float zNear=1.0f;
141 const float zFar=100.0f;
143 m_st.useProgram(
gl,
true);
144 m_st.send(
gl, m_pmvMatUni);
145 m_st.useProgram(
gl,
false);
150 if( !m_initialized ) {
154 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
156 m_st.useProgram(
gl,
true);
158 pmv.getMv().loadIdentity();
159 pmv.translateMv(0, 0, -10);
160 static float t_sum_ms = 0;
162 t_sum_ms += float( (when - m_tlast).to_ms() );
165 pmv.rotateMv(ang, 0, 0, 1);
166 pmv.rotateMv(ang, 0, 1, 0);
167 m_st.send(
gl, m_pmvMatUni);
170 ::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
171 m_st.useProgram(
gl,
false);
176 std::string
toStringImpl() const noexcept
override {
return "RedSquareES2"; }
void dispose(const WindowSRef &win, const jau::fraction_timespec &when) override
Notifies the listener to perform the release of all renderer resources per context,...
bool init(const WindowSRef &win, const jau::fraction_timespec &when) override
Called by the drawable immediately after the render context is initialized.
void reshape(const WindowSRef &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 display(const WindowSRef &win, const jau::fraction_timespec &when) override
Called by the drawable to initiate rendering by the client.
Recti & viewport() noexcept
std::string toStringImpl() const noexcept override
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_sref 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 ShaderCodeSRef create(GLenum type, size_t count, const source_list_t &sources)
static ShaderProgramSRef create() noexcept
void destroy(GL &gl) noexcept
Detaches all shader codes and deletes the program.
bool add(const ShaderCodeSRef &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.
GLArrayDataServerSRef< float > GLFloatArrayDataServerSRef
std::shared_ptr< ShaderCode > ShaderCodeSRef
std::shared_ptr< ShaderProgram > ShaderProgramSRef
std::shared_ptr< Window > WindowSRef
PMVMatrix4< float > PMVMat4f
ssize_t fprintf_td(const uint64_t elapsed_ms, FILE *stream, std::string_view format, const Args &...args) noexcept
Convenient secure fprintf() invocation, prepending the given elapsed_ms timestamp and using jau:forma...
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.