Added UI Scaling support
This commit is contained in:
@ -32,8 +32,8 @@ void UICanvas::rebufferShaderParameters() {
|
||||
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
|
||||
data.projection = glm::ortho(
|
||||
0.0f,
|
||||
camera->getRenderTarget()->getWidth(),
|
||||
camera->getRenderTarget()->getHeight(),
|
||||
camera->getRenderTarget()->getWidth() / this->getScale(),
|
||||
camera->getRenderTarget()->getHeight() / this->getScale(),
|
||||
0.0f
|
||||
);
|
||||
data.view = glm::mat4(1.0f);
|
||||
@ -46,6 +46,10 @@ void UICanvas::rebufferShaderParameters() {
|
||||
this->shaderBuffer.buffer(&data);
|
||||
}
|
||||
|
||||
float_t UICanvas::getScale() {
|
||||
return this->camera->getRenderTarget()->getScale();
|
||||
}
|
||||
|
||||
float_t UICanvas::getWidth() {
|
||||
return w;
|
||||
}
|
||||
@ -78,13 +82,13 @@ void UICanvas::onStart() {
|
||||
|
||||
useEffectWithTeardown([&]{
|
||||
if(camera == nullptr) return evtRenderResize = [&] {};
|
||||
this->w = camera->getRenderTarget()->getWidth();
|
||||
this->h = camera->getRenderTarget()->getHeight();
|
||||
this->w = camera->getRenderTarget()->getWidth() / this->getScale();
|
||||
this->h = camera->getRenderTarget()->getHeight() / this->getScale();
|
||||
this->rebufferShaderParameters();
|
||||
|
||||
return evtRenderResize = useEvent([&](float_t w, float_t h){
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->w = w / this->getScale();
|
||||
this->h = h / this->getScale();
|
||||
this->rebufferShaderParameters();
|
||||
|
||||
auto comps = this->item->findChildren<UIComponent>();
|
||||
|
Reference in New Issue
Block a user