|
|
@@ -13,7 +13,7 @@ namespace gameplay
|
|
|
{
|
|
|
static std::vector<Form*> __forms;
|
|
|
|
|
|
- Form::Form() : _theme(NULL), _quad(NULL), _node(NULL), _frameBuffer(NULL), _viewport(NULL)
|
|
|
+ Form::Form() : _theme(NULL), _quad(NULL), _node(NULL), _frameBuffer(NULL)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
@@ -27,7 +27,6 @@ namespace gameplay
|
|
|
SAFE_RELEASE(_node);
|
|
|
SAFE_RELEASE(_frameBuffer);
|
|
|
SAFE_RELEASE(_theme);
|
|
|
- SAFE_DELETE(_viewport);
|
|
|
|
|
|
// Remove this Form from the global list.
|
|
|
std::vector<Form*>::iterator it = std::find(__forms.begin(), __forms.end(), this);
|
|
|
@@ -45,9 +44,7 @@ namespace gameplay
|
|
|
Properties* properties = Properties::create(path);
|
|
|
assert(properties);
|
|
|
if (properties == NULL)
|
|
|
- {
|
|
|
return NULL;
|
|
|
- }
|
|
|
|
|
|
// Check if the Properties is valid and has a valid namespace.
|
|
|
Properties* formProperties = properties->getNextNamespace();
|
|
|
@@ -121,14 +118,14 @@ namespace gameplay
|
|
|
void Form::setQuad(const Vector3& p1, const Vector3& p2, const Vector3& p3, const Vector3& p4)
|
|
|
{
|
|
|
Mesh* mesh = Mesh::createQuad(p1, p2, p3, p4);
|
|
|
- initQuad(mesh);
|
|
|
+ initializeQuad(mesh);
|
|
|
SAFE_RELEASE(mesh);
|
|
|
}
|
|
|
|
|
|
void Form::setQuad(float x, float y, float width, float height)
|
|
|
{
|
|
|
Mesh* mesh = Mesh::createQuad(x, y, width, height);
|
|
|
- initQuad(mesh);
|
|
|
+ initializeQuad(mesh);
|
|
|
SAFE_RELEASE(mesh);
|
|
|
}
|
|
|
|
|
|
@@ -143,7 +140,6 @@ namespace gameplay
|
|
|
|
|
|
Matrix::createOrthographicOffCenter(0, _size.x, _size.y, 0, 0, 1, &_projectionMatrix);
|
|
|
_theme->setProjectionMatrix(_projectionMatrix);
|
|
|
- _viewport = new Viewport(0, 0, _size.x, _size.y);
|
|
|
|
|
|
_node->setModel(_quad);
|
|
|
}
|
|
|
@@ -171,14 +167,19 @@ namespace gameplay
|
|
|
if (isDirty())
|
|
|
{
|
|
|
_frameBuffer->bind();
|
|
|
- _viewport->bind();
|
|
|
+
|
|
|
+ Game* game = Game::getInstance();
|
|
|
+ Rectangle prevViewport = game->getViewport();
|
|
|
+
|
|
|
+ game->setViewport(Rectangle(_position.x, _position.y, _size.x, _size.y));
|
|
|
|
|
|
draw(_theme->getSpriteBatch(), _clip);
|
|
|
|
|
|
// Rebind the default framebuffer and game viewport.
|
|
|
FrameBuffer::bindDefault();
|
|
|
- Game* game = Game::getInstance();
|
|
|
- GL_ASSERT( glViewport(0, 0, game->getWidth(), game->getHeight()) );
|
|
|
+
|
|
|
+ // restore the previous game viewport
|
|
|
+ game->setViewport(prevViewport);
|
|
|
}
|
|
|
|
|
|
_quad->draw();
|
|
|
@@ -229,7 +230,7 @@ namespace gameplay
|
|
|
_dirty = false;
|
|
|
}
|
|
|
|
|
|
- void Form::initQuad(Mesh* mesh)
|
|
|
+ void Form::initializeQuad(Mesh* mesh)
|
|
|
{
|
|
|
// Release current model.
|
|
|
SAFE_RELEASE(_quad);
|
|
|
@@ -266,7 +267,6 @@ namespace gameplay
|
|
|
Texture::Sampler* sampler = Texture::Sampler::create(_frameBuffer->getRenderTarget()->getTexture());
|
|
|
sampler->setWrapMode(Texture::CLAMP, Texture::CLAMP);
|
|
|
material->getParameter("u_texture")->setValue(sampler);
|
|
|
-
|
|
|
material->getParameter("u_textureRepeat")->setValue(Vector2::one());
|
|
|
material->getParameter("u_textureTransform")->setValue(Vector2::zero());
|
|
|
|
|
|
@@ -299,7 +299,7 @@ namespace gameplay
|
|
|
|
|
|
// Unproject point into world space.
|
|
|
Ray ray;
|
|
|
- camera->pickRay(NULL, x, y, &ray);
|
|
|
+ camera->pickRay(Game::getInstance()->getViewport(), x, y, &ray);
|
|
|
|
|
|
// Find the quad's plane.
|
|
|
// We know its normal is the quad's forward vector.
|