@@ -327,28 +327,33 @@ class RenderPass final {
327327 [[nodiscard]] NodeType getType () const noexcept {
328328 return mType ;
329329 }
330- void render (ImVec2 frameBufferSize, const ImVec2 clipMin, const ImVec2 clipMax, ImVec2 base, ImVec2 size ,
330+ void render (const ImVec2 frameBufferSize, const ImVec2 clipMin, const ImVec2 clipMax, const ImVec2 canvasSize ,
331331 const ShaderToyUniform& uniform, const GLuint vao, const GLuint vbo) {
332332 glDisable (GL_BLEND);
333333 constexpr ImVec2 cubeMapSize{ static_cast <float >(cubeMapRenderTargetSize), static_cast <float >(cubeMapRenderTargetSize) };
334+ const auto screenBase = clipMin;
335+ const auto screenSize = ImVec2{ clipMax.x - clipMin.x , clipMax.y - clipMin.y };
334336
335337 for (uint32_t idx = 0 ; idx < mBuffers .size (); ++idx) {
336338 const auto buffer = mBuffers [idx].get ();
337-
339+ ImVec2 size, base, fbSize, uniformSize;
338340 if (buffer) {
339- if (mType == NodeType::CubeMap) {
340- size = cubeMapSize;
341- }
341+ base = { 0 , 0 };
342+ size = mType == NodeType::CubeMap ? cubeMapSize : screenSize;
343+ fbSize = size;
344+ uniformSize = mType == NodeType::CubeMap ? cubeMapSize : canvasSize;
342345 glViewport (0 , 0 , static_cast <GLsizei>(size.x ), static_cast <GLsizei>(size.y ));
343346 glDisable (GL_SCISSOR_TEST);
344347 buffer->bind (static_cast <uint32_t >(size.x ), static_cast <uint32_t >(size.y ));
345- base = { 0 , 0 };
346- frameBufferSize = size;
347348 } else {
348349 glViewport (0 , 0 , static_cast <GLsizei>(frameBufferSize.x ), static_cast <GLsizei>(frameBufferSize.y ));
349350 glEnable (GL_SCISSOR_TEST);
350351 glScissor (static_cast <GLint>(clipMin.x ), static_cast <GLint>(frameBufferSize.y - clipMax.y ),
351352 static_cast <GLint>(clipMax.x - clipMin.x ), static_cast <GLint>(clipMax.y - clipMin.y ));
353+ base = screenBase;
354+ size = screenSize;
355+ fbSize = frameBufferSize;
356+ uniformSize = canvasSize;
352357 }
353358 glUseProgram (mProgram );
354359 // update vertex array
@@ -362,8 +367,8 @@ class RenderPass final {
362367 Vertex{ ImVec2{ base.x + size.x , base.y + size.y }, ImVec2{ size.x , 0.0 } }, // right-bottom
363368 };
364369 for (auto & [pos, coord] : vertices) {
365- pos.x = pos.x / frameBufferSize .x * 2 .0f - 1 .0f ;
366- pos.y = 1 .0f - pos.y / frameBufferSize .y * 2 .0f ;
370+ pos.x = pos.x / fbSize .x * 2 .0f - 1 .0f ;
371+ pos.y = 1 .0f - pos.y / fbSize .y * 2 .0f ;
367372 }
368373 glBufferData (GL_ARRAY_BUFFER, 4 * sizeof (Vertex), vertices.data (), GL_STREAM_DRAW);
369374 } else {
@@ -378,8 +383,8 @@ class RenderPass final {
378383 cubeMapVertexPos[cubeMapVertexIndex[idx][3 ]] }, // right-bottom
379384 };
380385 for (auto & [pos, coord, point] : vertices) {
381- pos.x = pos.x / frameBufferSize .x * 2 .0f - 1 .0f ;
382- pos.y = 1 .0f - pos.y / frameBufferSize .y * 2 .0f ;
386+ pos.x = pos.x / fbSize .x * 2 .0f - 1 .0f ;
387+ pos.y = 1 .0f - pos.y / fbSize .y * 2 .0f ;
383388 }
384389 glBufferData (GL_ARRAY_BUFFER, 4 * sizeof (VertexCubeMap), vertices.data (), GL_STREAM_DRAW);
385390 }
@@ -439,7 +444,7 @@ class RenderPass final {
439444
440445 // update uniform
441446 if (mLocationResolution != -1 )
442- glUniform3f (mLocationResolution , size .x , size .y , 0 .0f );
447+ glUniform3f (mLocationResolution , uniformSize .x , uniformSize .y , 0 .0f );
443448 if (mLocationTime != -1 )
444449 glUniform1f (mLocationTime , uniform.time );
445450 if (mLocationTimeDelta != -1 )
@@ -613,7 +618,7 @@ class OpenGLPipeline final : public Pipeline {
613618 mRenderPasses .push_back (std::make_unique<RenderPass>(src, type, std::move (target), std::move (channels)));
614619 }
615620
616- void render (const ImVec2 frameBufferSize, const ImVec2 clipMin, const ImVec2 clipMax, const ImVec2 base, const ImVec2 size,
621+ void render (const ImVec2 frameBufferSize, const ImVec2 clipMin, const ImVec2 clipMax, ImVec2 size,
617622 const ShaderToyUniform& uniform) override {
618623 for (auto & [tex, data, update] : mDynamicTextures ) {
619624 update (data.data ());
@@ -624,7 +629,7 @@ class OpenGLPipeline final : public Pipeline {
624629 glBindTexture (GL_TEXTURE_2D, GL_NONE);
625630 }
626631 for (const auto & pass : mRenderPasses )
627- pass->render (frameBufferSize, clipMin, clipMax, base, size, uniform,
632+ pass->render (frameBufferSize, clipMin, clipMax, size, uniform,
628633 pass->getType () == NodeType::Image ? mVAOImage : mVAOCubeMap , mVBO );
629634 }
630635
0 commit comments