|
|
@@ -28,17 +28,11 @@
|
|
|
#include <Rocket/Core/Core.h>
|
|
|
#include "RenderInterfaceSFML.h"
|
|
|
|
|
|
-#ifdef ENABLE_GLEW
|
|
|
-#include <gl/glew.h>
|
|
|
-#endif
|
|
|
-
|
|
|
#ifndef GL_CLAMP_TO_EDGE
|
|
|
#define GL_CLAMP_TO_EDGE 0x812F
|
|
|
#endif
|
|
|
-// If built with the GL Easy Extension library we can compile geometry to VBO's
|
|
|
-// http://www.opengl.org/sdk/libs/GLee/
|
|
|
-#ifdef ENABLE_GLEW
|
|
|
|
|
|
+#ifdef ENABLE_GLEW
|
|
|
class RocketSFMLRendererGeometryHandler
|
|
|
{
|
|
|
public:
|
|
|
@@ -61,7 +55,6 @@ public:
|
|
|
VertexID = IndexID = 0;
|
|
|
};
|
|
|
};
|
|
|
-
|
|
|
#endif
|
|
|
|
|
|
struct RocketSFMLRendererVertex
|
|
|
@@ -88,37 +81,29 @@ sf::RenderWindow *RocketSFMLRenderer::GetWindow()
|
|
|
|
|
|
void RocketSFMLRenderer::Resize()
|
|
|
{
|
|
|
- MyWindow->SetActive(true);
|
|
|
- //MyWindow->SaveGLStates();
|
|
|
-
|
|
|
static sf::View View;
|
|
|
- //View.SetFromRect(sf::FloatRect(0, (float)MyWindow->GetWidth(), (float)MyWindow->GetHeight(), 0));
|
|
|
- View.SetViewport(sf::FloatRect(0, (float)MyWindow->GetWidth(), (float)MyWindow->GetHeight(), 0));
|
|
|
- MyWindow->SetView(View);
|
|
|
+ View.setViewport(sf::FloatRect(0, (float)MyWindow->getSize().x, (float)MyWindow->getSize().y, 0));
|
|
|
+ MyWindow->setView(View);
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
glLoadIdentity();
|
|
|
- glOrtho(0, MyWindow->GetWidth(), MyWindow->GetHeight(), 0, -1, 1);
|
|
|
+ glOrtho(0, MyWindow->getSize().x, MyWindow->getSize().y, 0, -1, 1);
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
- glViewport(0, 0, MyWindow->GetWidth(), MyWindow->GetHeight());
|
|
|
-
|
|
|
- //MyWindow->RestoreGLStates();
|
|
|
+ glViewport(0, 0, MyWindow->getSize().x, MyWindow->getSize().y);
|
|
|
};
|
|
|
|
|
|
// Called by Rocket when it wants to render geometry that it does not wish to optimise.
|
|
|
void RocketSFMLRenderer::RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, const Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation)
|
|
|
{
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
- glPushMatrix();
|
|
|
+ MyWindow->pushGLStates();
|
|
|
glTranslatef(translation.x, translation.y, 0);
|
|
|
|
|
|
std::vector<Rocket::Core::Vector2f> Positions(num_vertices);
|
|
|
std::vector<Rocket::Core::Colourb> Colors(num_vertices);
|
|
|
std::vector<Rocket::Core::Vector2f> TexCoords(num_vertices);
|
|
|
|
|
|
- for(int i = 0; i < num_vertices; i++)
|
|
|
+ for(int i = 0; i < num_vertices; i++)
|
|
|
{
|
|
|
Positions[i] = vertices[i].position;
|
|
|
Colors[i] = vertices[i].colour;
|
|
|
@@ -136,11 +121,11 @@ void RocketSFMLRenderer::RenderGeometry(Rocket::Core::Vertex* vertices, int num_
|
|
|
glEnable(GL_BLEND);
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
- sf::Image *image = (sf::Image *)texture;
|
|
|
+ sf::Texture *sfTexture = (sf::Texture *)texture;
|
|
|
|
|
|
- if(image)
|
|
|
+ if(sfTexture)
|
|
|
{
|
|
|
- image->Bind();
|
|
|
+ sf::Texture::bind(sfTexture);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -156,21 +141,13 @@ void RocketSFMLRenderer::RenderGeometry(Rocket::Core::Vertex* vertices, int num_
|
|
|
|
|
|
glColor4f(1, 1, 1, 1);
|
|
|
|
|
|
- glPopMatrix();
|
|
|
+ MyWindow->popGLStates();
|
|
|
}
|
|
|
|
|
|
// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
|
|
|
-Rocket::Core::CompiledGeometryHandle RocketSFMLRenderer::CompileGeometry(Rocket::Core::Vertex* vertices,
|
|
|
- int num_vertices, int* indices,
|
|
|
- int num_indices,
|
|
|
- const Rocket::Core::TextureHandle texture)
|
|
|
+Rocket::Core::CompiledGeometryHandle RocketSFMLRenderer::CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, const Rocket::Core::TextureHandle texture)
|
|
|
{
|
|
|
#ifdef ENABLE_GLEW
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
- //if(!GLEE_VERSION_2_0)
|
|
|
- //return (Rocket::Core::CompiledGeometryHandle) NULL;
|
|
|
-
|
|
|
std::vector<RocketSFMLRendererVertex> Data(num_vertices);
|
|
|
|
|
|
for(unsigned long i = 0; i < Data.size(); i++)
|
|
|
@@ -199,7 +176,7 @@ Rocket::Core::CompiledGeometryHandle RocketSFMLRenderer::CompileGeometry(Rocket:
|
|
|
|
|
|
return (Rocket::Core::CompiledGeometryHandle)Geometry;
|
|
|
#else
|
|
|
- return NULL;
|
|
|
+ return (Rocket::Core::CompiledGeometryHandle)NULL;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
@@ -207,20 +184,18 @@ Rocket::Core::CompiledGeometryHandle RocketSFMLRenderer::CompileGeometry(Rocket:
|
|
|
void RocketSFMLRenderer::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
|
|
|
{
|
|
|
#ifdef ENABLE_GLEW
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
RocketSFMLRendererGeometryHandler *RealGeometry = (RocketSFMLRendererGeometryHandler *)geometry;
|
|
|
|
|
|
- glPushMatrix();
|
|
|
+ MyWindow->pushGLStates();
|
|
|
glTranslatef(translation.x, translation.y, 0);
|
|
|
glEnable(GL_BLEND);
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
- sf::Image *image = (sf::Image *)RealGeometry->Texture;
|
|
|
+ sf::Texture *texture = (sf::Texture *)RealGeometry->Texture;
|
|
|
|
|
|
- if(image)
|
|
|
+ if(texture)
|
|
|
{
|
|
|
- image->Bind();
|
|
|
+ sf::Texture::bind(texture);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -249,9 +224,9 @@ void RocketSFMLRenderer::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHa
|
|
|
|
|
|
glColor4f(1, 1, 1, 1);
|
|
|
|
|
|
- glPopMatrix();
|
|
|
+ MyWindow->popGLStates();
|
|
|
#else
|
|
|
- ROCKET_ASSERT(false /*& "Not Implemented"*/);
|
|
|
+ ROCKET_ASSERT(false);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
@@ -259,19 +234,15 @@ void RocketSFMLRenderer::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHa
|
|
|
void RocketSFMLRenderer::ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry)
|
|
|
{
|
|
|
#ifdef ENABLE_GLEW
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
delete (RocketSFMLRendererGeometryHandler *)geometry;
|
|
|
#else
|
|
|
- ROCKET_ASSERT(false /*& "Not Implemented"*/);
|
|
|
+ ROCKET_ASSERT(false);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
// Called by Rocket when it wants to enable or disable scissoring to clip content.
|
|
|
void RocketSFMLRenderer::EnableScissorRegion(bool enable)
|
|
|
{
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
if (enable)
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
else
|
|
|
@@ -281,16 +252,12 @@ void RocketSFMLRenderer::EnableScissorRegion(bool enable)
|
|
|
// Called by Rocket when it wants to change the scissor region.
|
|
|
void RocketSFMLRenderer::SetScissorRegion(int x, int y, int width, int height)
|
|
|
{
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
- glScissor(x, MyWindow->GetHeight() - (y + height), width, height);
|
|
|
+ glScissor(x, MyWindow->getSize().y - (y + height), width, height);
|
|
|
}
|
|
|
|
|
|
// Called by Rocket when a texture is required by the library.
|
|
|
bool RocketSFMLRenderer::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
|
|
|
{
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface();
|
|
|
Rocket::Core::FileHandle file_handle = file_interface->Open(source);
|
|
|
if (file_handle == NULL)
|
|
|
@@ -304,19 +271,19 @@ bool RocketSFMLRenderer::LoadTexture(Rocket::Core::TextureHandle& texture_handle
|
|
|
file_interface->Read(buffer, buffer_size, file_handle);
|
|
|
file_interface->Close(file_handle);
|
|
|
|
|
|
- sf::Image *image = new sf::Image();
|
|
|
+ sf::Texture *texture = new sf::Texture();
|
|
|
|
|
|
- if(!image->LoadFromMemory(buffer, buffer_size))
|
|
|
+ if(!texture->loadFromMemory(buffer, buffer_size))
|
|
|
{
|
|
|
delete buffer;
|
|
|
- delete image;
|
|
|
+ delete texture;
|
|
|
|
|
|
return false;
|
|
|
};
|
|
|
delete buffer;
|
|
|
|
|
|
- texture_handle = (Rocket::Core::TextureHandle) image;
|
|
|
- texture_dimensions = Rocket::Core::Vector2i(image->GetWidth(), image->GetHeight());
|
|
|
+ texture_handle = (Rocket::Core::TextureHandle) texture;
|
|
|
+ texture_dimensions = Rocket::Core::Vector2i(texture->getSize().x, texture->getSize().y);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
@@ -324,18 +291,15 @@ bool RocketSFMLRenderer::LoadTexture(Rocket::Core::TextureHandle& texture_handle
|
|
|
// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
|
|
|
bool RocketSFMLRenderer::GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions)
|
|
|
{
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
- sf::Image *image = new sf::Image();
|
|
|
-
|
|
|
- if(!image->LoadFromPixels(source_dimensions.x, source_dimensions.y, source))
|
|
|
- {
|
|
|
- delete image;
|
|
|
+ sf::Texture *texture = new sf::Texture();
|
|
|
|
|
|
+ if (!texture->create(source_dimensions.x, source_dimensions.y)) {
|
|
|
+ delete texture;
|
|
|
return false;
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- texture_handle = (Rocket::Core::TextureHandle)image;
|
|
|
+ texture->update(source, source_dimensions.x, source_dimensions.y, 0, 0);
|
|
|
+ texture_handle = (Rocket::Core::TextureHandle)texture;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
@@ -343,7 +307,5 @@ bool RocketSFMLRenderer::GenerateTexture(Rocket::Core::TextureHandle& texture_ha
|
|
|
// Called by Rocket when a loaded texture is no longer required.
|
|
|
void RocketSFMLRenderer::ReleaseTexture(Rocket::Core::TextureHandle texture_handle)
|
|
|
{
|
|
|
- MyWindow->SetActive();
|
|
|
-
|
|
|
- delete (sf::Image *)texture_handle;
|
|
|
+ delete (sf::Texture *)texture_handle;
|
|
|
}
|