Jump to content

Render Picture in Picture with Supersampling


photo

Recommended Posts

Hello

We are using WidgetSpriteViewport for Picture in Picture views right know.

Is it possible to enable supersampling only for this Widget or do we have to do it another way? What other possibilities do we have?

Thanks

Link to comment

Hello.

You can try wrapping the WidgetSprite class. We create the texture ourselves and render into it with the necessary settings after updating the GUI.

class WidgetSpriteSupersampling
{
public:
	WidgetSpriteSupersampling(int width, int height)
	{
		widget = WidgetSprite::create();
		widget->setWidth(width);
		widget->setHeight(height);

		viewport = Viewport::create();

		texture = Texture::create();
		int flags = Texture::FILTER_LINEAR | Texture::ANISOTROPY_16 | Texture::USAGE_RENDER;
		texture->create2D(width, height, Texture::FORMAT_RGBA8, flags);

		widget->setRender(texture, !Render::isFlipped());
		callback_id = Engine::get()->addCallback(Engine::CALLBACK_END_GUI_UPDATE, MakeCallback(this, &WidgetSpriteSupersampling::on_end_gui_update));
	}

	~WidgetSpriteSupersampling()
	{
		Engine::get()->removeCallback(Engine::CALLBACK_END_GUI_UPDATE, callback_id);
	}

	WidgetPtr getWidget() const { return widget; }

	void setCamera(CameraPtr in_camera) { camera = in_camera; }
	void setSupersampling(float in_supersampling) { supersampling = in_supersampling; }

private:
	void on_end_gui_update()
	{
		if (camera == nullptr)
			return;

		float old_supersampling = Render::getSupersampling();
		Render::setSupersampling(supersampling);
		viewport->renderTexture2D(camera, texture);
		Render::setSupersampling(old_supersampling);
	}

private:
	WidgetSpritePtr widget;
	ViewportPtr viewport;
	TexturePtr texture;
	CameraPtr camera;
	void *callback_id{nullptr};

	float supersampling{1.0f};
};

Here is example of usage:

WidgetSpriteSupersampling *widget = nullptr;

int AppWorldLogic::init()
{
	widget = new WidgetSpriteSupersampling(1024, 512);
	widget->setCamera(Game::getPlayer()->getCamera());
	widget->setSupersampling(2.0f);
	Gui::get()->addChild(widget->getWidget(), Gui::ALIGN_CENTER);
	return 1;
}

int AppWorldLogic::shutdown()
{
	delete widget;
	return 1;
}

 

  • Thanks 2
Link to comment
×
×
  • Create New...