This commit is contained in:
hiker 2016-04-20 09:16:52 +10:00
commit 6987c82c7b
4 changed files with 79 additions and 27 deletions

View File

@ -24,6 +24,7 @@
#include "config/user_config.hpp"
#include "graphics/2dutils.hpp"
#include "graphics/central_settings.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/scalable_font.hpp"
@ -1958,16 +1959,31 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
else if (type == WTYPE_MODEL_VIEW)
{
ModelViewWidget* mvw = dynamic_cast<ModelViewWidget*>(widget);
FrameBuffer* fb = mvw->getFrameBuffer();
if (fb != NULL && fb->getRTT().size() > 0)
if (CVS->isGLSL())
{
glEnable(GL_FRAMEBUFFER_SRGB);
draw2DImageFromRTT(fb->getRTT()[0], 512, 512,
rect, core::rect<s32>(0, 0, 512, 512), NULL, SColor(255, 255, 255, 255), true);
glDisable(GL_FRAMEBUFFER_SRGB);
FrameBuffer* fb = mvw->getFrameBuffer();
if (fb != NULL && fb->getRTT().size() > 0)
{
glEnable(GL_FRAMEBUFFER_SRGB);
draw2DImageFromRTT(fb->getRTT()[0], 512, 512,
rect, core::rect<s32>(0, 0, 512, 512), NULL,
SColor(255, 255, 255, 255), true);
glDisable(GL_FRAMEBUFFER_SRGB);
}
}
else
{
video::ITexture* texture = mvw->getTexture();
if (texture != NULL && texture->getSize().Width > 0
&& texture->getSize().Height > 0)
{
draw2DImage(texture, rect, core::rect<s32>(0, 0, 512, 512),
NULL, NULL, true);
}
}
}
else if (type == WTYPE_ICON_BUTTON || type == WTYPE_MODEL_VIEW)
else if (type == WTYPE_ICON_BUTTON)
{
drawIconButton(rect, widget, pressed, focused);
}

View File

@ -40,11 +40,13 @@ ModelViewWidget::ModelViewWidget() :
IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false)
{
m_frame_buffer = NULL;
m_texture = NULL;
m_rtt_main_node = NULL;
m_camera = NULL;
m_light = NULL;
m_type = WTYPE_MODEL_VIEW;
m_rtt_provider = NULL;
m_old_rtt_provider = NULL;
m_rotation_mode = ROTATE_OFF;
// so that the base class doesn't complain there is no icon defined
@ -59,6 +61,10 @@ ModelViewWidget::~ModelViewWidget()
delete m_rtt_provider;
m_rtt_provider = NULL;
delete m_old_rtt_provider;
m_old_rtt_provider = NULL;
m_texture = NULL;
}
// -----------------------------------------------------------------------------
void ModelViewWidget::add()
@ -107,6 +113,10 @@ void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location,
m_model_location.push_back(location);
m_model_scale.push_back(scale);
m_model_frames.push_back(frame);
delete m_old_rtt_provider;
m_old_rtt_provider = NULL;
m_texture = NULL;
}
// -----------------------------------------------------------------------------
@ -159,29 +169,43 @@ void ModelViewWidget::update(float delta)
if (fabsf(angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF;
}
if (!CVS->isGLSL())
return;
if (m_rtt_provider == NULL)
if (CVS->isGLSL())
{
std::string name = "model view ";
name += m_properties[PROP_ID].c_str();
if (m_rtt_provider == NULL)
{
m_rtt_provider = new RTT(512, 512);
}
m_rtt_provider = new RTT(512, 512);
}
if (m_rtt_main_node == NULL)
{
setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames);
}
m_rtt_main_node->setRotation(core::vector3df(0.0f, angle, 0.0f));
m_rtt_main_node->setVisible(true);
if (m_rtt_main_node == NULL)
m_frame_buffer = m_rtt_provider->render(m_camera, GUIEngine::getLatestDt());
m_rtt_main_node->setVisible(false);
}
else
{
setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames);
if (m_old_rtt_provider == NULL)
{
std::string name = "model view ";
name += m_properties[PROP_ID].c_str();
m_old_rtt_provider = new IrrDriver::RTTProvider(core::dimension2d<u32>(512, 512), name, false);
m_old_rtt_provider->setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames);
}
m_texture = m_old_rtt_provider->renderToTexture(angle);
if (m_texture == NULL)
{
m_rtt_unsupported = true;
}
}
m_rtt_main_node->setRotation(core::vector3df(0.0f, angle, 0.0f));
m_rtt_main_node->setVisible(true);
m_frame_buffer = m_rtt_provider->render(m_camera, GUIEngine::getLatestDt());
m_rtt_main_node->setVisible(false);
}
void ModelViewWidget::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
@ -310,6 +334,11 @@ void ModelViewWidget::elementRemoved()
{
delete m_rtt_provider;
m_rtt_provider = NULL;
delete m_old_rtt_provider;
m_old_rtt_provider = NULL;
m_texture = NULL;
IconButtonWidget::elementRemoved();
}
@ -317,4 +346,8 @@ void ModelViewWidget::clearRttProvider()
{
delete m_rtt_provider;
m_rtt_provider = NULL;
delete m_old_rtt_provider;
m_old_rtt_provider = NULL;
m_texture = NULL;
}

View File

@ -51,6 +51,7 @@ namespace GUIEngine
std::vector<int> m_model_frames;
RTT* m_rtt_provider;
IrrDriver::RTTProvider* m_old_rtt_provider;
float angle;
@ -63,6 +64,7 @@ namespace GUIEngine
scene::ISceneNode *m_light;
FrameBuffer *m_frame_buffer;
video::ITexture *m_texture;
public:
@ -102,6 +104,7 @@ namespace GUIEngine
const std::vector<int>& model_frames);
FrameBuffer* getFrameBuffer() { return m_frame_buffer; }
video::ITexture* getTexture() { return m_texture; }
};
}

View File

@ -272,11 +272,11 @@ void Attachment::hitBanana(Item *item, int new_attachment)
case ATTACH_ANVIL:
// if the kart already has an anvil, attach a new anvil,
// and increase the overall time
new_attachment = 2;
new_attachment = 1;
leftover_time = m_time_left;
break;
case ATTACH_PARACHUTE:
new_attachment = 2;
new_attachment = 0;
leftover_time = m_time_left;
break;
default: