render buffer can have size related to screen size with user defined ratio

This commit is contained in:
Mikulas Florek 2016-02-01 16:38:27 +01:00
parent b87af138cf
commit a779ec2e2e
3 changed files with 28 additions and 6 deletions

View file

@ -36,6 +36,17 @@ template <> inline Vec3 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline Vec2 toType(lua_State* L, int index)
{
Vec2 v;
lua_rawgeti(L, index, 1);
v.x = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
lua_rawgeti(L, index, 2);
v.y = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
return v;
}
template <> inline int64 toType(lua_State* L, int index)
{
return (int64)lua_tointeger(L, index);

View file

@ -2,6 +2,7 @@
#include "lumix.h"
#include "core/vec.h"
#include <bgfx/bgfx.h>
@ -31,14 +32,14 @@ class FrameBuffer
{
Declaration()
: m_renderbuffers_count(0)
, m_screen_size(false)
, m_size_ratio(-1, -1)
{ }
static const int MAX_RENDERBUFFERS = 16;
int32 m_width;
int32 m_height;
bool m_screen_size;
Vec2 m_size_ratio;
RenderBuffer m_renderbuffers[MAX_RENDERBUFFERS];
int32 m_renderbuffers_count;
char m_name[64];
@ -53,7 +54,7 @@ class FrameBuffer
int getWidth() const { return m_declaration.m_width; }
int getHeight() const { return m_declaration.m_height; }
void resize(int width, int height);
bool hasScreenSize() const { return m_declaration.m_screen_size; }
Vec2 getSizeRatio() const { return m_declaration.m_size_ratio; }
const char* getName() const { return m_declaration.m_name; }
bgfx::TextureHandle getRenderbufferHandle(int idx) const { return m_declaration.m_renderbuffers[idx].m_handle; }

View file

@ -184,13 +184,19 @@ struct PipelineImpl : public Pipeline
decl.m_width = (int)lua_tointeger(L, -1);
}
lua_pop(L, 1);
if (lua_getfield(L, -1, "size_ratio") == LUA_TBOOLEAN)
{
decl.m_size_ratio = LuaWrapper::toType<Vec2>(L, -1);
}
lua_pop(L, 1);
if (lua_getfield(L, -1, "screen_size") == LUA_TBOOLEAN)
{
decl.m_screen_size = lua_toboolean(L, -1) != 0;
bool is_screen_size = lua_toboolean(L, -1) != 0;
decl.m_size_ratio = is_screen_size ? Vec2(1, 1) : Vec2(-1, -1);
}
else
{
decl.m_screen_size = false;
decl.m_size_ratio = Vec2(-1, -1);
}
lua_pop(L, 1);
if (lua_getfield(L, -1, "height") == LUA_TNUMBER)
@ -1926,7 +1932,11 @@ struct PipelineImpl : public Pipeline
}
for (auto& i : m_framebuffers)
{
if (i->hasScreenSize()) i->resize(w, h);
auto size_ratio = i->getSizeRatio();
if (size_ratio.x > 0 || size_ratio.y > 0)
{
i->resize(int(w * size_ratio.x), int(h * size_ratio.y));
}
}
m_width = w;
m_height = h;