Jump to content

Rendering 2 worlds is slow and choppy


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

I'm rendering two worlds to two separate windows with a UI overlay.  The moment I render the 2nd world it cause FPS to drop and rendering is very choppy in both windows.  I've also noticed that the window position in CreateWindow() seems to have no effect.

#include "UltraEngine.h"

using namespace UltraEngine;

#define RENDERLAYER_1 2
#define RENDERLAYER_2 4

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();

    //WINDOW A
    auto window = CreateWindow("WindowA", 0, 0, 512, 512, displays[0]);
    auto framebuffer = CreateFramebuffer(window);
    auto world = CreateWorld();
    world->RecordStats(true);
    auto font = LoadFont("Fonts/arial.ttf");

    auto camera = CreateCamera(world);
    camera->SetPosition(0, 0, -2);

    auto ui_camera = CreateCamera(world, UltraEngine::PROJECTION_ORTHOGRAPHIC);
    ui_camera->SetRenderLayers(RENDERLAYER_1);
    ui_camera->SetPosition(framebuffer->size.x / 2.0f, framebuffer->size.y / 2.0f);
    ui_camera->SetClearMode(UltraEngine::CLEAR_DEPTH);

    auto ui = CreateInterface(world, font, framebuffer->size);
    ui->background->SetColor(0, 0, 0, 0);
    ui->SetRenderLayers(RENDERLAYER_1);

    //WINDOW B
    auto worldB = CreateWorld();
    worldB->RecordStats(true);
    auto windowB = CreateWindow("WindowB", 800, 0, 512, 512, displays[0]);
    auto framebufferB = CreateFramebuffer(windowB);
    auto cameraB = CreateCamera(worldB);
    cameraB->SetPosition(0, 0, -2);

    auto ui_cameraB = CreateCamera(worldB, UltraEngine::PROJECTION_ORTHOGRAPHIC);
    ui_cameraB->SetRenderLayers(RENDERLAYER_2);
    ui_cameraB->SetPosition(framebufferB->size.x / 2.0f, framebufferB->size.y / 2.0f);
    ui_cameraB->SetClearMode(UltraEngine::CLEAR_DEPTH);

    auto uiB = CreateInterface(worldB, font, framebufferB->size);
    uiB->background->SetColor(0, 0, 0, 0);
    uiB->SetRenderLayers(RENDERLAYER_2);

    auto fpsA = CreateLabel("FPS : 0", 10, 10, 100, 20, ui->root);
    auto fpsB = CreateLabel("FPS : 0", 10, 10, 100, 20, uiB->root);

    auto boxA = CreateBox(world);
    boxA->SetColor(1, 0, 0);

    auto boxB = CreateBox(worldB);
    boxB->SetColor(0, 1, 0);

    while (true)
    {
        while (UltraEngine::PeekEvent()) {
            auto event = UltraEngine::WaitEvent();
            switch (event.id) {
            case UltraEngine::EVENT_WINDOWCLOSE:
                if (event.source == window) {
                    return 0;
                }
                break;
            }

            ui->ProcessEvent(event);
            uiB->ProcessEvent(event);
        }

        fpsA->SetText("FPS : " + WString(world->renderstats.framerate));
        fpsB->SetText("FPS : " + WString(worldB->renderstats.framerate));

        boxA->Turn(0.1f, 0.1f, 0.2f);
        boxB->Turn(0.2f, 0.1f, 0.1f);

        worldB->Update();
        worldB->Render(framebufferB, false);

        world->Update();
        world->Render(framebuffer, false);
    }
    return 0;
}

 

Link to comment
Share on other sites

  • Solution

I would expect real-time rendering to two framebuffers to be terrible, because the rendering thread has to stop and sync with the culling thread to handle the changed world it is working with.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...