+ IRenderTarget interface

+ RenderTarget.SaveGLStates
+ RenderTarget.RestoreGLStates
- RenderTarget.Flush
* some bugfixes

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1367 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-01-20 21:46:32 +00:00
parent 5a0feadb8f
commit 0d3f9a9f1c
9 changed files with 215 additions and 110 deletions

View File

@ -296,8 +296,8 @@ private:
int function() sfSoundRecorder_IsAvailable;
}
mixin(loadFromSharedLib2("csfml-audio", "sfSoundRecorder_Create", "sfSoundRecorder_Destroy", "sfSoundRecorder_Start",
"sfSoundRecorder_Stop", "sfSoundRecorder_GetSampleRate", "sfSoundRecorder_IsAvailable"));
mixin(loadFromSharedLib2("csfml-audio", "sfSoundRecorder", "Create", "Destroy", "Start",
"Stop", "GetSampleRate", "IsAvailable"));
}
// Use explicit alloc to allow instaciation by C thread

View File

@ -181,7 +181,7 @@ public:
// * Returns:
// * True if copy was successful
// */
// void copyScreen(RenderWindow window, IntRect sourceRect = new IntRect())
// void copyScreen(RenderWindow window, IntRect sourceRect = IntRect())
// {
// return cast(bool)sfImage_CopyScreen(m_ptr, window.getNativePointer, sourceRect);
// }

View File

@ -0,0 +1,115 @@
/**
*
*/
module dsfml.graphics.irendertarget;
import dsfml.system.vector2;
import dsfml.graphics.idrawable;
import dsfml.graphics.rect;
import dsfml.graphics.shader;
import dsfml.graphics.view;
import dsfml.graphics.color;
interface IRenderTarget
{
/*
* Clear the entire target with a single color
*
* \param color : Color to use to clear the render target
*
*/
void clear(Color color = Color());
/*
* Draw something into the target
*
* \param object : Object to draw
*
*/
void draw(IDrawable object);
/*
* Draw something into the target with a shader
*
* \param object : Object to draw
* \param shader : Shader to apply
*
*/
void draw(IDrawable object, Shader shader);
/*
* Get the width of the rendering region of the target
*
* \return Width in pixels
*
*/
uint getWidth();
/*
* Get the height of the rendering region of the target
*
* \return Height in pixels
*
*/
uint getHeight();
/*
* Change the current active view.
*
* \param view : New view to use (pass GetDefaultView() to set the default view)
*
*/
void setView(View view);
/*
* Get the current view
*
* \return Current view active in the window
*
*/
View getView();
/*
* Get the default view of the window
*
* \return Default view
*
*/
View getDefaultView();
/*
* Get the viewport of a view applied to this target
*
* \param view Target view
*
* \return Viewport rectangle, expressed in pixels in the current target
*
*/
IntRect getViewport(View view);
/*
* Convert a point in target coordinates into view coordinates
*
* \param x : X coordinate of the point to convert, relative to the target
* \param y : Y coordinate of the point to convert, relative to the target
* \param view : Target view to convert the point to, null to use the currently associated view
*
* \return Converted point
*
*/
Vector2f convertCoords(uint x, uint y, View view = null);
/*
* Save the current OpenGL render states and matrices
*
*/
void saveGLStates();
/*
* Restore the previously saved OpenGL render states and matrices
*
*/
void restoreGLStates();
}

View File

@ -36,13 +36,14 @@ import dsfml.graphics.idrawable,
dsfml.graphics.color,
dsfml.graphics.rect,
dsfml.graphics.shader,
dsfml.graphics.view;
dsfml.graphics.view,
dsfml.graphics.irendertarget;
/**
* Target for 2D rendering into an image that can be reused in a sprite
*/
class RenderImage : DSFMLObject
class RenderImage : DSFMLObject, IRenderTarget
{
private:
Image _image = null;
@ -110,20 +111,6 @@ public:
return sfRenderImage_SetActive(m_ptr, active);
}
/**
* Make sure that what has been drawn so far is rendered
*
* Use this function if you use OpenGL rendering commands, and you want to make sure that things will appear on top
* of all the SFML objects that have been drawn so far. This is needed because SFML doesn't use immediate rendering,
* it first accumulates drawables into a queue and trigger the actual rendering afterwards.
*
* You don't need to call this function if you're not dealing with OpenGL directly.
*/
void flush()
{
sfRenderImage_Flush(m_ptr);
}
/**
* Update the contents of the target image
*/
@ -149,7 +136,7 @@ public:
* drawable = Object to draw
* shader = Shader to use
*/
void drawWithShader(IDrawable drawable, Shader shader)
void draw(IDrawable drawable, Shader shader)
{
drawable.renderWithShader(this, shader);
}
@ -217,9 +204,9 @@ public:
}
IntRect getViewport() // TODO: is there a need to accept other Views than the currently assigned one?
IntRect getViewport(View view = null) // TODO: is there a need to accept other Views than the currently assigned one?
{
return sfRenderImage_GetViewport(m_ptr, _view.getNativePointer);
return sfRenderImage_GetViewport(m_ptr, view is null ? _view.getNativePointer : view.getNativePointer);
}
/**
@ -267,17 +254,30 @@ public:
return sfRenderImage_IsAvailable();
}
private:
extern (C)
/**
* Save the current OpenGL render states and matrices
*/
void saveGLStates()
{
static
sfRenderImage_SaveGLStates(m_ptr);
}
/**
* Restore the previously saved OpenGL render states and matrices
*/
void restoreGLStates()
{
sfRenderImage_RestoreGLStates(m_ptr);
}
private:
static extern(C)
{
void* function(uint, uint, bool) sfRenderImage_Create;
void function(void*) sfRenderImage_Destroy;
uint function(void*) sfRenderImage_GetWidth;
uint function(void*) sfRenderImage_GetHeight;
bool function(void*, bool) sfRenderImage_SetActive;
void function(void*) sfRenderImage_Flush;
void function(void*) sfRenderImage_Display;
void function(void*, void*) sfRenderImage_DrawSprite;
@ -296,40 +296,16 @@ private:
void function(void*, uint, uint, float*, float*, void*) sfRenderImage_ConvertCoords;
void* function(void*) sfRenderImage_GetImage;
bool function() sfRenderImage_IsAvailable;
}
// DSFML2
void function(void*) sfRenderImage_SaveGLStates;
void function(void*) sfRenderImage_RestoreGLStates;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-graphics-d");
else
DllLoader dll = DllLoader.load("csfml-graphics");
mixin(loadFromSharedLib2("csfml-graphics", "sfRenderImage", "Create", "Destroy", "GetWidth", "GetHeight",
"SetActive", "Display", "Clear", "SetView", "GetView", "GetDefaultView", "GetViewport", "ConvertCoords",
"GetImage", "IsAvailable",
// DSFML2
"SaveGLStates", "RestoreGLStates"));
mixin(loadFromSharedLib("sfRenderImage_Create"));
mixin(loadFromSharedLib("sfRenderImage_Destroy"));
mixin(loadFromSharedLib("sfRenderImage_GetWidth"));
mixin(loadFromSharedLib("sfRenderImage_GetHeight"));
mixin(loadFromSharedLib("sfRenderImage_SetActive"));
mixin(loadFromSharedLib("sfRenderImage_Flush"));
mixin(loadFromSharedLib("sfRenderImage_Display"));
/*
mixin(loadFromSharedLib("sfRenderImage_DrawSprite"));
mixin(loadFromSharedLib("sfRenderImage_DrawShape"));
mixin(loadFromSharedLib("sfRenderImage_DrawText"));
mixin(loadFromSharedLib("sfRenderImage_DrawSpriteWithShader"));
mixin(loadFromSharedLib("sfRenderImage_DrawShapeWithShader"));
mixin(loadFromSharedLib("sfRenderImage_DrawTextWithShader"));
*/
mixin(loadFromSharedLib("sfRenderImage_Clear"));
mixin(loadFromSharedLib("sfRenderImage_SetView"));
mixin(loadFromSharedLib("sfRenderImage_GetView"));
mixin(loadFromSharedLib("sfRenderImage_GetDefaultView"));
mixin(loadFromSharedLib("sfRenderImage_GetViewport"));
mixin(loadFromSharedLib("sfRenderImage_ConvertCoords"));
mixin(loadFromSharedLib("sfRenderImage_GetImage"));
mixin(loadFromSharedLib("sfRenderImage_IsAvailable"));
}
}

View File

@ -34,7 +34,8 @@ import dsfml.graphics.color,
dsfml.graphics.rect,
dsfml.graphics.shader,
dsfml.graphics.view,
dsfml.graphics.idrawable;
dsfml.graphics.idrawable,
dsfml.graphics.irendertarget;
import dsfml.window.event,
dsfml.window.input,
@ -49,7 +50,7 @@ import dsfml.system.common,
/**
* Simple wrapper for Window that allows easy 2D rendering.
*/
class RenderWindow : Window
class RenderWindow : Window, IRenderTarget
{
private:
View m_view = null;
@ -235,16 +236,47 @@ public:
}
/**
* Make sure that what has been drawn so far is rendered
* Use this function if you use OpenGL rendering commands, and you want to make sure that things will appear on top
* of all the SFML objects that have been drawn so far. This is needed because SFML doesn't use immediate rendering,
* it first accumulates drawables into a queue and trigger the actual rendering afterwards.
*
* You don't need to call this function if you're not dealing with OpenGL directly.
* Save the current OpenGL render states and matrices
*/
void flush()
void saveGLStates()
{
sfRenderWindow_Flush(m_ptr);
sfRenderWindow_SaveGLStates(m_ptr);
}
/**
* Restore the previously saved OpenGL render states and matrices
*/
void restoreGLStates()
{
sfRenderWindow_RestoreGLStates(m_ptr);
}
/**
* Return the width of the rendering region of a renderwindow
*
* Returns:
* Width in pixels
*/
uint getWidth()
{
return sfRenderWindow_GetWidth(m_ptr);
}
/**
* Return the height of the rendering region of a renderwindow
*
* Returns:
* Height in pixels
*/
uint getHeight()
{
return sfRenderWindow_GetHeight(m_ptr);
}
IntRect getViewport(View view = null) // TODO: is there a need to accept other Views than the currently assigned one?
{
return sfRenderWindow_GetViewport(m_ptr, view is null ? m_view.getNativePointer : view.getNativePointer);
}
private:
@ -255,7 +287,9 @@ private:
void* function(WindowHandle, ContextSettings*) sfRenderWindow_CreateFromHandle;
void function(void*) sfRenderWindow_Destroy;
void* function(void*) sfRenderWindow_GetInput;
// bool function(void*) sfRenderWindow_IsOpened; // also in Window
bool function(void*) sfRenderWindow_IsOpened;
uint function(void*) sfRenderWindow_GetWidth;
uint function(void*) sfRenderWindow_GetHeight;
/*
void function(void*, void*) sfRenderWindow_DrawSprite;
@ -275,40 +309,17 @@ private:
void function(void*, uint, uint, float*, float*, void*) sfRenderWindow_ConvertCoords;
// DSFML2
void function(void*) sfRenderWindow_Flush;
void function(void*) sfRenderWindow_SaveGLStates;
void function(void*) sfRenderWindow_RestoreGLStates;
IntRect function(void*, void*) sfRenderWindow_GetViewport;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-graphics-d");
else
DllLoader dll = DllLoader.load("csfml-graphics");
mixin(loadFromSharedLib2("csfml-graphics", "sfRenderWindow", "Create", "CreateFromHandle",
"Destroy", "GetInput", "Clear", "SetView", "GetView", "GetDefaultView", "ConvertCoords",
"GetWidth", "GetHeight",
// DSFML2
"SaveGLStates", "RestoreGLStates", "GetViewport"));
mixin(loadFromSharedLib("sfRenderWindow_Create"));
mixin(loadFromSharedLib("sfRenderWindow_CreateFromHandle"));
mixin(loadFromSharedLib("sfRenderWindow_Destroy"));
mixin(loadFromSharedLib("sfRenderWindow_GetInput"));
/*
mixin(loadFromSharedLib("sfRenderWindow_DrawSprite"));
mixin(loadFromSharedLib("sfRenderWindow_DrawShape"));
mixin(loadFromSharedLib("sfRenderWindow_DrawText"));
mixin(loadFromSharedLib("sfRenderWindow_DrawSpriteWithShader"));
mixin(loadFromSharedLib("sfRenderWindow_DrawShapeWithShader"));
mixin(loadFromSharedLib("sfRenderWindow_DrawTextWithShader"));
*/
mixin(loadFromSharedLib("sfRenderWindow_Clear"));
mixin(loadFromSharedLib("sfRenderWindow_SetView"));
mixin(loadFromSharedLib("sfRenderWindow_GetView"));
mixin(loadFromSharedLib("sfRenderWindow_GetDefaultView"));
mixin(loadFromSharedLib("sfRenderWindow_ConvertCoords"));
// DSFML2
mixin(loadFromSharedLib("sfRenderWindow_Flush"));
}
static ~this()
{

View File

@ -177,7 +177,8 @@ public:
IntRect getSubRect()
{
if (m_subRect == IntRect())
m_subRect = IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
m_subRect = sfSprite_GetSubRect(m_ptr);
//m_subRect = IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
return m_subRect;
}
@ -218,7 +219,7 @@ private:
typedef void function(void*, int) pf_sfSprite_FlipX;
typedef void function(void*, int) pf_sfSprite_FlipY;
typedef void* function(void*) pf_sfSprite_GetImage;
typedef void* function(void*) pf_sfSprite_GetSubRect;
typedef IntRect function(void*) pf_sfSprite_GetSubRect;
typedef float function(void*) pf_sfSprite_GetWidth;
typedef float function(void*) pf_sfSprite_GetHeight;
typedef Color function(void*, uint, uint) pf_sfSprite_GetPixel;

View File

@ -47,7 +47,7 @@ string loadFromSharedLib(string fname)
}
//used to mixin code function
string loadFromSharedLib2(S...)(string lib, S fnames)
string loadFromSharedLib2(S...)(string lib, string object, S fnames)
{
string res = `static this()
{
@ -60,7 +60,7 @@ string loadFromSharedLib2(S...)(string lib, S fnames)
foreach(fname; fnames)
{
res ~= "\t" ~ fname ~ " = " ~ "cast(typeof(" ~ fname ~ ")) dll.getSymbol(\"" ~ fname ~ "\");\n";
res ~= "\t" ~ object ~ "_" ~ fname ~ " = " ~ "cast(typeof(" ~ object ~ "_" ~ fname ~ ")) dll.getSymbol(\"" ~ object ~ "_" ~ fname ~ "\");\n";
}
return res ~ "}\n";
}

View File

@ -32,7 +32,7 @@ extern(C)
{
typedef void function(float) pf_sfSleep;
private static __gshared pf_sfSleep sfSleep;
private static const __gshared pf_sfSleep sfSleep;
}
static this()

View File

@ -155,4 +155,6 @@ alias Vector2!(float) Vector2f;
/// ditto
alias Vector2!(int) Vector2i;
/// ditto
alias Vector2!(int) Vector2ui;
alias Vector2!(uint) Vector2ui;
/// ditto
alias Vector2!(ubyte) Vector2ub;