mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
CRLF to LF
This commit is contained in:
+109
-109
@@ -1,109 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_COLOR_H
|
||||
#define LOVE_GRAPHICS_COLOR_H
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct ColorT
|
||||
{
|
||||
T r;
|
||||
T g;
|
||||
T b;
|
||||
T a;
|
||||
|
||||
ColorT() : r(0), g(0), b(0), a(0) {}
|
||||
ColorT(T r_, T g_, T b_, T a_) : r(r_), g(g_), b(b_), a(a_) {}
|
||||
void set(T r_, T g_, T b_, T a_)
|
||||
{
|
||||
r = r_;
|
||||
g = g_;
|
||||
b = b_;
|
||||
a = a_;
|
||||
}
|
||||
|
||||
ColorT<T> operator+=(const ColorT<T> &other);
|
||||
ColorT<T> operator*=(T s);
|
||||
ColorT<T> operator/=(T s);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> ColorT<T>::operator+=(const ColorT<T> &other)
|
||||
{
|
||||
r += other.r;
|
||||
g += other.g;
|
||||
b += other.b;
|
||||
a += other.a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> ColorT<T>::operator*=(T s)
|
||||
{
|
||||
r *= s;
|
||||
g *= s;
|
||||
b *= s;
|
||||
a *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> ColorT<T>::operator/=(T s)
|
||||
{
|
||||
r /= s;
|
||||
g /= s;
|
||||
b /= s;
|
||||
a /= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> operator+(const ColorT<T> &a, const ColorT<T> &b)
|
||||
{
|
||||
ColorT<T> tmp(a);
|
||||
return tmp += b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> operator*(const ColorT<T> &a, T s)
|
||||
{
|
||||
ColorT<T> tmp(a);
|
||||
return tmp *= s;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> operator/(const ColorT<T> &a, T s)
|
||||
{
|
||||
ColorT<T> tmp(a);
|
||||
return tmp /= s;
|
||||
}
|
||||
|
||||
typedef ColorT<unsigned char> Color;
|
||||
typedef ColorT<float> Colorf;
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_COLOR_H
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_COLOR_H
|
||||
#define LOVE_GRAPHICS_COLOR_H
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct ColorT
|
||||
{
|
||||
T r;
|
||||
T g;
|
||||
T b;
|
||||
T a;
|
||||
|
||||
ColorT() : r(0), g(0), b(0), a(0) {}
|
||||
ColorT(T r_, T g_, T b_, T a_) : r(r_), g(g_), b(b_), a(a_) {}
|
||||
void set(T r_, T g_, T b_, T a_)
|
||||
{
|
||||
r = r_;
|
||||
g = g_;
|
||||
b = b_;
|
||||
a = a_;
|
||||
}
|
||||
|
||||
ColorT<T> operator+=(const ColorT<T> &other);
|
||||
ColorT<T> operator*=(T s);
|
||||
ColorT<T> operator/=(T s);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> ColorT<T>::operator+=(const ColorT<T> &other)
|
||||
{
|
||||
r += other.r;
|
||||
g += other.g;
|
||||
b += other.b;
|
||||
a += other.a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> ColorT<T>::operator*=(T s)
|
||||
{
|
||||
r *= s;
|
||||
g *= s;
|
||||
b *= s;
|
||||
a *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> ColorT<T>::operator/=(T s)
|
||||
{
|
||||
r /= s;
|
||||
g /= s;
|
||||
b /= s;
|
||||
a /= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> operator+(const ColorT<T> &a, const ColorT<T> &b)
|
||||
{
|
||||
ColorT<T> tmp(a);
|
||||
return tmp += b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> operator*(const ColorT<T> &a, T s)
|
||||
{
|
||||
ColorT<T> tmp(a);
|
||||
return tmp *= s;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ColorT<T> operator/(const ColorT<T> &a, T s)
|
||||
{
|
||||
ColorT<T> tmp(a);
|
||||
return tmp /= s;
|
||||
}
|
||||
|
||||
typedef ColorT<unsigned char> Color;
|
||||
typedef ColorT<float> Colorf;
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_COLOR_H
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "DrawQable.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
DrawQable::~DrawQable()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "DrawQable.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
DrawQable::~DrawQable()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_DRAWQABLE_H
|
||||
#define LOVE_GRAPHICS_DRAWQABLE_H
|
||||
|
||||
// LOVE
|
||||
#include "Drawable.h"
|
||||
#include "Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
/**
|
||||
* A DrawQable is anything that be drawn in part with a Quad.
|
||||
**/
|
||||
class DrawQable : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~DrawQable();
|
||||
|
||||
/**
|
||||
* Draws the object with the specified transformation.
|
||||
*
|
||||
* @param quad The Quad to use to draw the object.
|
||||
* @param x The position of the object along the x-axis.
|
||||
* @param y The position of the object along the y-axis.
|
||||
* @param angle The angle of the object (in radians).
|
||||
* @param sx The scale factor along the x-axis.
|
||||
* @param sy The scale factor along the y-axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
* @param kx Shear along the x-axis.
|
||||
* @param ky Shear along the y-axis.
|
||||
**/
|
||||
virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
|
||||
};
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_DRAWQABLE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_DRAWQABLE_H
|
||||
#define LOVE_GRAPHICS_DRAWQABLE_H
|
||||
|
||||
// LOVE
|
||||
#include "Drawable.h"
|
||||
#include "Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
/**
|
||||
* A DrawQable is anything that be drawn in part with a Quad.
|
||||
**/
|
||||
class DrawQable : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~DrawQable();
|
||||
|
||||
/**
|
||||
* Draws the object with the specified transformation.
|
||||
*
|
||||
* @param quad The Quad to use to draw the object.
|
||||
* @param x The position of the object along the x-axis.
|
||||
* @param y The position of the object along the y-axis.
|
||||
* @param angle The angle of the object (in radians).
|
||||
* @param sx The scale factor along the x-axis.
|
||||
* @param sy The scale factor along the y-axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
* @param kx Shear along the x-axis.
|
||||
* @param ky Shear along the y-axis.
|
||||
**/
|
||||
virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
|
||||
};
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_DRAWQABLE_H
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Drawable.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Drawable::~Drawable()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Drawable.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Drawable::~Drawable()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_DRAWABLE_H
|
||||
#define LOVE_GRAPHICS_DRAWABLE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
/**
|
||||
* A Drawable is anything that can be drawn on screen with a
|
||||
* position, scale and orientation.
|
||||
**/
|
||||
class Drawable : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~Drawable();
|
||||
|
||||
/**
|
||||
* Draws the object with the specified transformation.
|
||||
*
|
||||
* @param x The position of the object along the x-axis.
|
||||
* @param y The position of the object along the y-axis.
|
||||
* @param angle The angle of the object (in radians).
|
||||
* @param sx The scale factor along the x-axis.
|
||||
* @param sy The scale factor along the y-axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
* @param kx Shear along the x-axis.
|
||||
* @param ky Shear along the y-axis.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
|
||||
};
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_DRAWABLE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_DRAWABLE_H
|
||||
#define LOVE_GRAPHICS_DRAWABLE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
/**
|
||||
* A Drawable is anything that can be drawn on screen with a
|
||||
* position, scale and orientation.
|
||||
**/
|
||||
class Drawable : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~Drawable();
|
||||
|
||||
/**
|
||||
* Draws the object with the specified transformation.
|
||||
*
|
||||
* @param x The position of the object along the x-axis.
|
||||
* @param y The position of the object along the y-axis.
|
||||
* @param angle The angle of the object (in radians).
|
||||
* @param sx The scale factor along the x-axis.
|
||||
* @param sy The scale factor along the y-axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
* @param kx Shear along the x-axis.
|
||||
* @param ky Shear along the y-axis.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
|
||||
};
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_DRAWABLE_H
|
||||
|
||||
+166
-166
@@ -1,166 +1,166 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Graphics::~Graphics()
|
||||
{
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, DrawMode &out)
|
||||
{
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(DrawMode in, const char *&out)
|
||||
{
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, AlignMode &out)
|
||||
{
|
||||
return alignModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(AlignMode in, const char *&out)
|
||||
{
|
||||
return alignModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, BlendMode &out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(BlendMode in, const char *&out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, ColorMode &out)
|
||||
{
|
||||
return colorModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(ColorMode in, const char *&out)
|
||||
{
|
||||
return colorModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, LineStyle &out)
|
||||
{
|
||||
return lineStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(LineStyle in, const char *&out)
|
||||
{
|
||||
return lineStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, PointStyle &out)
|
||||
{
|
||||
return pointStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(PointStyle in, const char *&out)
|
||||
{
|
||||
return pointStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, Support &out)
|
||||
{
|
||||
return support.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(Support in, const char *&out)
|
||||
{
|
||||
return support.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
||||
{
|
||||
{ "line", Graphics::DRAW_LINE },
|
||||
{ "fill", Graphics::DRAW_FILL },
|
||||
};
|
||||
|
||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
|
||||
|
||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignModeEntries[] =
|
||||
{
|
||||
{ "left", Graphics::ALIGN_LEFT },
|
||||
{ "right", Graphics::ALIGN_RIGHT },
|
||||
{ "center", Graphics::ALIGN_CENTER },
|
||||
};
|
||||
|
||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
|
||||
|
||||
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
|
||||
{
|
||||
{ "alpha", Graphics::BLEND_ALPHA },
|
||||
{ "additive", Graphics::BLEND_ADDITIVE },
|
||||
{ "subtractive", Graphics::BLEND_SUBTRACTIVE },
|
||||
{ "multiplicative", Graphics::BLEND_MULTIPLICATIVE },
|
||||
{ "premultiplied", Graphics::BLEND_PREMULTIPLIED },
|
||||
};
|
||||
|
||||
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
|
||||
|
||||
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM>::Entry Graphics::colorModeEntries[] =
|
||||
{
|
||||
{ "replace", Graphics::COLOR_REPLACE },
|
||||
{ "modulate", Graphics::COLOR_MODULATE },
|
||||
{ "combine", Graphics::COLOR_COMBINE },
|
||||
};
|
||||
|
||||
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM> Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries));
|
||||
|
||||
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
|
||||
{
|
||||
{ "smooth", Graphics::LINE_SMOOTH },
|
||||
{ "rough", Graphics::LINE_ROUGH }
|
||||
};
|
||||
|
||||
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
|
||||
|
||||
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM>::Entry Graphics::pointStyleEntries[] =
|
||||
{
|
||||
{ "smooth", Graphics::POINT_SMOOTH },
|
||||
{ "rough", Graphics::POINT_ROUGH }
|
||||
};
|
||||
|
||||
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM> Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries));
|
||||
|
||||
StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM>::Entry Graphics::supportEntries[] =
|
||||
{
|
||||
{ "canvas", Graphics::SUPPORT_CANVAS },
|
||||
{ "pixeleffect", Graphics::SUPPORT_PIXELEFFECT },
|
||||
{ "npot", Graphics::SUPPORT_NPOT },
|
||||
{ "subtractive", Graphics::SUPPORT_SUBTRACTIVE },
|
||||
};
|
||||
|
||||
StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM> Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries));
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Graphics::~Graphics()
|
||||
{
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, DrawMode &out)
|
||||
{
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(DrawMode in, const char *&out)
|
||||
{
|
||||
return drawModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, AlignMode &out)
|
||||
{
|
||||
return alignModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(AlignMode in, const char *&out)
|
||||
{
|
||||
return alignModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, BlendMode &out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(BlendMode in, const char *&out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, ColorMode &out)
|
||||
{
|
||||
return colorModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(ColorMode in, const char *&out)
|
||||
{
|
||||
return colorModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, LineStyle &out)
|
||||
{
|
||||
return lineStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(LineStyle in, const char *&out)
|
||||
{
|
||||
return lineStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, PointStyle &out)
|
||||
{
|
||||
return pointStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(PointStyle in, const char *&out)
|
||||
{
|
||||
return pointStyles.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(const char *in, Support &out)
|
||||
{
|
||||
return support.find(in, out);
|
||||
}
|
||||
|
||||
bool Graphics::getConstant(Support in, const char *&out)
|
||||
{
|
||||
return support.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
||||
{
|
||||
{ "line", Graphics::DRAW_LINE },
|
||||
{ "fill", Graphics::DRAW_FILL },
|
||||
};
|
||||
|
||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
|
||||
|
||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignModeEntries[] =
|
||||
{
|
||||
{ "left", Graphics::ALIGN_LEFT },
|
||||
{ "right", Graphics::ALIGN_RIGHT },
|
||||
{ "center", Graphics::ALIGN_CENTER },
|
||||
};
|
||||
|
||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
|
||||
|
||||
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
|
||||
{
|
||||
{ "alpha", Graphics::BLEND_ALPHA },
|
||||
{ "additive", Graphics::BLEND_ADDITIVE },
|
||||
{ "subtractive", Graphics::BLEND_SUBTRACTIVE },
|
||||
{ "multiplicative", Graphics::BLEND_MULTIPLICATIVE },
|
||||
{ "premultiplied", Graphics::BLEND_PREMULTIPLIED },
|
||||
};
|
||||
|
||||
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
|
||||
|
||||
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM>::Entry Graphics::colorModeEntries[] =
|
||||
{
|
||||
{ "replace", Graphics::COLOR_REPLACE },
|
||||
{ "modulate", Graphics::COLOR_MODULATE },
|
||||
{ "combine", Graphics::COLOR_COMBINE },
|
||||
};
|
||||
|
||||
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM> Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries));
|
||||
|
||||
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
|
||||
{
|
||||
{ "smooth", Graphics::LINE_SMOOTH },
|
||||
{ "rough", Graphics::LINE_ROUGH }
|
||||
};
|
||||
|
||||
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
|
||||
|
||||
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM>::Entry Graphics::pointStyleEntries[] =
|
||||
{
|
||||
{ "smooth", Graphics::POINT_SMOOTH },
|
||||
{ "rough", Graphics::POINT_ROUGH }
|
||||
};
|
||||
|
||||
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM> Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries));
|
||||
|
||||
StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM>::Entry Graphics::supportEntries[] =
|
||||
{
|
||||
{ "canvas", Graphics::SUPPORT_CANVAS },
|
||||
{ "pixeleffect", Graphics::SUPPORT_PIXELEFFECT },
|
||||
{ "npot", Graphics::SUPPORT_NPOT },
|
||||
{ "subtractive", Graphics::SUPPORT_SUBTRACTIVE },
|
||||
};
|
||||
|
||||
StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM> Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries));
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
+144
-144
@@ -1,144 +1,144 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_GRAPHICS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Module.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
class Graphics : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
DRAW_LINE = 1,
|
||||
DRAW_FILL,
|
||||
DRAW_MAX_ENUM
|
||||
};
|
||||
|
||||
enum AlignMode
|
||||
{
|
||||
ALIGN_LEFT = 1,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT,
|
||||
ALIGN_MAX_ENUM
|
||||
};
|
||||
|
||||
enum BlendMode
|
||||
{
|
||||
BLEND_ALPHA = 1,
|
||||
BLEND_ADDITIVE,
|
||||
BLEND_SUBTRACTIVE,
|
||||
BLEND_MULTIPLICATIVE,
|
||||
BLEND_PREMULTIPLIED,
|
||||
BLEND_MAX_ENUM
|
||||
};
|
||||
|
||||
enum ColorMode
|
||||
{
|
||||
COLOR_MODULATE = 1,
|
||||
COLOR_REPLACE,
|
||||
COLOR_COMBINE,
|
||||
COLOR_MAX_ENUM
|
||||
};
|
||||
|
||||
enum LineStyle
|
||||
{
|
||||
LINE_ROUGH = 1,
|
||||
LINE_SMOOTH,
|
||||
LINE_MAX_ENUM
|
||||
};
|
||||
|
||||
enum PointStyle
|
||||
{
|
||||
POINT_ROUGH = 1,
|
||||
POINT_SMOOTH,
|
||||
POINT_MAX_ENUM
|
||||
};
|
||||
|
||||
enum Support
|
||||
{
|
||||
SUPPORT_CANVAS = 1,
|
||||
SUPPORT_PIXELEFFECT,
|
||||
SUPPORT_NPOT,
|
||||
SUPPORT_SUBTRACTIVE,
|
||||
SUPPORT_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Graphics();
|
||||
|
||||
static bool getConstant(const char *in, DrawMode &out);
|
||||
static bool getConstant(DrawMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, AlignMode &out);
|
||||
static bool getConstant(AlignMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, BlendMode &out);
|
||||
static bool getConstant(BlendMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, ColorMode &out);
|
||||
static bool getConstant(ColorMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, LineStyle &out);
|
||||
static bool getConstant(LineStyle in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, PointStyle &out);
|
||||
static bool getConstant(PointStyle in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, Support &out);
|
||||
static bool getConstant(Support in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
|
||||
static StringMap<DrawMode, DRAW_MAX_ENUM> drawModes;
|
||||
|
||||
static StringMap<AlignMode, ALIGN_MAX_ENUM>::Entry alignModeEntries[];
|
||||
static StringMap<AlignMode, ALIGN_MAX_ENUM> alignModes;
|
||||
|
||||
static StringMap<BlendMode, BLEND_MAX_ENUM>::Entry blendModeEntries[];
|
||||
static StringMap<BlendMode, BLEND_MAX_ENUM> blendModes;
|
||||
|
||||
static StringMap<ColorMode, COLOR_MAX_ENUM>::Entry colorModeEntries[];
|
||||
static StringMap<ColorMode, COLOR_MAX_ENUM> colorModes;
|
||||
|
||||
static StringMap<LineStyle, LINE_MAX_ENUM>::Entry lineStyleEntries[];
|
||||
static StringMap<LineStyle, LINE_MAX_ENUM> lineStyles;
|
||||
|
||||
static StringMap<PointStyle, POINT_MAX_ENUM>::Entry pointStyleEntries[];
|
||||
static StringMap<PointStyle, POINT_MAX_ENUM> pointStyles;
|
||||
|
||||
static StringMap<Support, SUPPORT_MAX_ENUM>::Entry supportEntries[];
|
||||
static StringMap<Support, SUPPORT_MAX_ENUM> support;
|
||||
|
||||
}; // Graphics
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_GRAPHICS_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_GRAPHICS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Module.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
class Graphics : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
DRAW_LINE = 1,
|
||||
DRAW_FILL,
|
||||
DRAW_MAX_ENUM
|
||||
};
|
||||
|
||||
enum AlignMode
|
||||
{
|
||||
ALIGN_LEFT = 1,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT,
|
||||
ALIGN_MAX_ENUM
|
||||
};
|
||||
|
||||
enum BlendMode
|
||||
{
|
||||
BLEND_ALPHA = 1,
|
||||
BLEND_ADDITIVE,
|
||||
BLEND_SUBTRACTIVE,
|
||||
BLEND_MULTIPLICATIVE,
|
||||
BLEND_PREMULTIPLIED,
|
||||
BLEND_MAX_ENUM
|
||||
};
|
||||
|
||||
enum ColorMode
|
||||
{
|
||||
COLOR_MODULATE = 1,
|
||||
COLOR_REPLACE,
|
||||
COLOR_COMBINE,
|
||||
COLOR_MAX_ENUM
|
||||
};
|
||||
|
||||
enum LineStyle
|
||||
{
|
||||
LINE_ROUGH = 1,
|
||||
LINE_SMOOTH,
|
||||
LINE_MAX_ENUM
|
||||
};
|
||||
|
||||
enum PointStyle
|
||||
{
|
||||
POINT_ROUGH = 1,
|
||||
POINT_SMOOTH,
|
||||
POINT_MAX_ENUM
|
||||
};
|
||||
|
||||
enum Support
|
||||
{
|
||||
SUPPORT_CANVAS = 1,
|
||||
SUPPORT_PIXELEFFECT,
|
||||
SUPPORT_NPOT,
|
||||
SUPPORT_SUBTRACTIVE,
|
||||
SUPPORT_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Graphics();
|
||||
|
||||
static bool getConstant(const char *in, DrawMode &out);
|
||||
static bool getConstant(DrawMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, AlignMode &out);
|
||||
static bool getConstant(AlignMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, BlendMode &out);
|
||||
static bool getConstant(BlendMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, ColorMode &out);
|
||||
static bool getConstant(ColorMode in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, LineStyle &out);
|
||||
static bool getConstant(LineStyle in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, PointStyle &out);
|
||||
static bool getConstant(PointStyle in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, Support &out);
|
||||
static bool getConstant(Support in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
|
||||
static StringMap<DrawMode, DRAW_MAX_ENUM> drawModes;
|
||||
|
||||
static StringMap<AlignMode, ALIGN_MAX_ENUM>::Entry alignModeEntries[];
|
||||
static StringMap<AlignMode, ALIGN_MAX_ENUM> alignModes;
|
||||
|
||||
static StringMap<BlendMode, BLEND_MAX_ENUM>::Entry blendModeEntries[];
|
||||
static StringMap<BlendMode, BLEND_MAX_ENUM> blendModes;
|
||||
|
||||
static StringMap<ColorMode, COLOR_MAX_ENUM>::Entry colorModeEntries[];
|
||||
static StringMap<ColorMode, COLOR_MAX_ENUM> colorModes;
|
||||
|
||||
static StringMap<LineStyle, LINE_MAX_ENUM>::Entry lineStyleEntries[];
|
||||
static StringMap<LineStyle, LINE_MAX_ENUM> lineStyles;
|
||||
|
||||
static StringMap<PointStyle, POINT_MAX_ENUM>::Entry pointStyleEntries[];
|
||||
static StringMap<PointStyle, POINT_MAX_ENUM> pointStyles;
|
||||
|
||||
static StringMap<Support, SUPPORT_MAX_ENUM>::Entry supportEntries[];
|
||||
static StringMap<Support, SUPPORT_MAX_ENUM> support;
|
||||
|
||||
}; // Graphics
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_GRAPHICS_H
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Image::Filter::Filter()
|
||||
: min(FILTER_LINEAR)
|
||||
, mag(FILTER_LINEAR)
|
||||
{
|
||||
}
|
||||
|
||||
Image::Wrap::Wrap()
|
||||
: s(WRAP_CLAMP)
|
||||
, t(WRAP_CLAMP)
|
||||
{
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
}
|
||||
|
||||
bool Image::getConstant(const char *in, FilterMode &out)
|
||||
{
|
||||
return filterModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Image::getConstant(FilterMode in, const char *&out)
|
||||
{
|
||||
return filterModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Image::getConstant(const char *in, WrapMode &out)
|
||||
{
|
||||
return wrapModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Image::getConstant(WrapMode in, const char *&out)
|
||||
{
|
||||
return wrapModes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM>::Entry Image::filterModeEntries[] =
|
||||
{
|
||||
{ "linear", Image::FILTER_LINEAR },
|
||||
{ "nearest", Image::FILTER_NEAREST },
|
||||
};
|
||||
|
||||
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM> Image::filterModes(Image::filterModeEntries, sizeof(Image::filterModeEntries));
|
||||
|
||||
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM>::Entry Image::wrapModeEntries[] =
|
||||
{
|
||||
{ "clamp", Image::WRAP_CLAMP },
|
||||
{ "repeat", Image::WRAP_REPEAT },
|
||||
};
|
||||
|
||||
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM> Image::wrapModes(Image::wrapModeEntries, sizeof(Image::wrapModeEntries));
|
||||
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Image::Filter::Filter()
|
||||
: min(FILTER_LINEAR)
|
||||
, mag(FILTER_LINEAR)
|
||||
{
|
||||
}
|
||||
|
||||
Image::Wrap::Wrap()
|
||||
: s(WRAP_CLAMP)
|
||||
, t(WRAP_CLAMP)
|
||||
{
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
}
|
||||
|
||||
bool Image::getConstant(const char *in, FilterMode &out)
|
||||
{
|
||||
return filterModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Image::getConstant(FilterMode in, const char *&out)
|
||||
{
|
||||
return filterModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Image::getConstant(const char *in, WrapMode &out)
|
||||
{
|
||||
return wrapModes.find(in, out);
|
||||
}
|
||||
|
||||
bool Image::getConstant(WrapMode in, const char *&out)
|
||||
{
|
||||
return wrapModes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM>::Entry Image::filterModeEntries[] =
|
||||
{
|
||||
{ "linear", Image::FILTER_LINEAR },
|
||||
{ "nearest", Image::FILTER_NEAREST },
|
||||
};
|
||||
|
||||
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM> Image::filterModes(Image::filterModeEntries, sizeof(Image::filterModeEntries));
|
||||
|
||||
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM>::Entry Image::wrapModeEntries[] =
|
||||
{
|
||||
{ "clamp", Image::WRAP_CLAMP },
|
||||
{ "repeat", Image::WRAP_REPEAT },
|
||||
};
|
||||
|
||||
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM> Image::wrapModes(Image::wrapModeEntries, sizeof(Image::wrapModeEntries));
|
||||
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_IMAGE_H
|
||||
#define LOVE_GRAPHICS_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/DrawQable.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
class Image : public DrawQable, public Volatile
|
||||
{
|
||||
public:
|
||||
|
||||
enum WrapMode
|
||||
{
|
||||
WRAP_CLAMP = 1,
|
||||
WRAP_REPEAT,
|
||||
WRAP_MAX_ENUM
|
||||
};
|
||||
|
||||
enum FilterMode
|
||||
{
|
||||
FILTER_LINEAR = 1,
|
||||
FILTER_NEAREST,
|
||||
FILTER_MAX_ENUM
|
||||
};
|
||||
|
||||
struct Filter
|
||||
{
|
||||
Filter();
|
||||
FilterMode min;
|
||||
FilterMode mag;
|
||||
};
|
||||
|
||||
struct Wrap
|
||||
{
|
||||
Wrap();
|
||||
WrapMode s;
|
||||
WrapMode t;
|
||||
};
|
||||
|
||||
virtual ~Image();
|
||||
|
||||
static bool getConstant(const char *in, FilterMode &out);
|
||||
static bool getConstant(FilterMode in, const char *&out);
|
||||
static bool getConstant(const char *in, WrapMode &out);
|
||||
static bool getConstant(WrapMode in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<FilterMode, FILTER_MAX_ENUM>::Entry filterModeEntries[];
|
||||
static StringMap<FilterMode, FILTER_MAX_ENUM> filterModes;
|
||||
static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[];
|
||||
static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_IMAGE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_IMAGE_H
|
||||
#define LOVE_GRAPHICS_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/DrawQable.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
class Image : public DrawQable, public Volatile
|
||||
{
|
||||
public:
|
||||
|
||||
enum WrapMode
|
||||
{
|
||||
WRAP_CLAMP = 1,
|
||||
WRAP_REPEAT,
|
||||
WRAP_MAX_ENUM
|
||||
};
|
||||
|
||||
enum FilterMode
|
||||
{
|
||||
FILTER_LINEAR = 1,
|
||||
FILTER_NEAREST,
|
||||
FILTER_MAX_ENUM
|
||||
};
|
||||
|
||||
struct Filter
|
||||
{
|
||||
Filter();
|
||||
FilterMode min;
|
||||
FilterMode mag;
|
||||
};
|
||||
|
||||
struct Wrap
|
||||
{
|
||||
Wrap();
|
||||
WrapMode s;
|
||||
WrapMode t;
|
||||
};
|
||||
|
||||
virtual ~Image();
|
||||
|
||||
static bool getConstant(const char *in, FilterMode &out);
|
||||
static bool getConstant(FilterMode in, const char *&out);
|
||||
static bool getConstant(const char *in, WrapMode &out);
|
||||
static bool getConstant(WrapMode in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<FilterMode, FILTER_MAX_ENUM>::Entry filterModeEntries[];
|
||||
static StringMap<FilterMode, FILTER_MAX_ENUM> filterModes;
|
||||
static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[];
|
||||
static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_IMAGE_H
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Quad::Quad()
|
||||
{
|
||||
}
|
||||
|
||||
Quad::~Quad()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Quad::Quad()
|
||||
{
|
||||
}
|
||||
|
||||
Quad::~Quad()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
+66
-66
@@ -1,66 +1,66 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_QUAD_H
|
||||
#define LOVE_GRAPHICS_QUAD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/math.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
class Quad : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
struct Viewport
|
||||
{
|
||||
float x, y, w, h;
|
||||
};
|
||||
|
||||
Quad();
|
||||
|
||||
virtual ~Quad();
|
||||
|
||||
virtual void refresh(const Viewport &v, float sw, float sh) = 0;
|
||||
|
||||
virtual void setViewport(const Viewport &v) = 0;
|
||||
virtual Viewport getViewport() const = 0;
|
||||
|
||||
virtual void flip(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Mirror texture coordinates around 0.5
|
||||
*/
|
||||
virtual void mirror(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
virtual const vertex *getVertices() const = 0;
|
||||
};
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_QUAD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_QUAD_H
|
||||
#define LOVE_GRAPHICS_QUAD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/math.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
class Quad : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
struct Viewport
|
||||
{
|
||||
float x, y, w, h;
|
||||
};
|
||||
|
||||
Quad();
|
||||
|
||||
virtual ~Quad();
|
||||
|
||||
virtual void refresh(const Viewport &v, float sw, float sh) = 0;
|
||||
|
||||
virtual void setViewport(const Viewport &v) = 0;
|
||||
virtual Viewport getViewport() const = 0;
|
||||
|
||||
virtual void flip(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Mirror texture coordinates around 0.5
|
||||
*/
|
||||
virtual void mirror(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
virtual const vertex *getVertices() const = 0;
|
||||
};
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_QUAD_H
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Volatile.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
// Static members.
|
||||
std::list<Volatile *> Volatile::all;
|
||||
|
||||
Volatile::Volatile()
|
||||
{
|
||||
// Insert this object into "all".
|
||||
all.push_back(this);
|
||||
}
|
||||
|
||||
Volatile::~Volatile()
|
||||
{
|
||||
// Remove the pointer to this object.
|
||||
all.remove(this);
|
||||
}
|
||||
|
||||
bool Volatile::loadAll()
|
||||
{
|
||||
bool success = true;
|
||||
std::list<Volatile *>::iterator i = all.begin();
|
||||
|
||||
while (i != all.end())
|
||||
{
|
||||
success = success && (*i)->loadVolatile();
|
||||
i++;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void Volatile::unloadAll()
|
||||
{
|
||||
std::list<Volatile *>::iterator i = all.begin();
|
||||
|
||||
while (i != all.end())
|
||||
{
|
||||
(*i)->unloadVolatile();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Volatile.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
// Static members.
|
||||
std::list<Volatile *> Volatile::all;
|
||||
|
||||
Volatile::Volatile()
|
||||
{
|
||||
// Insert this object into "all".
|
||||
all.push_back(this);
|
||||
}
|
||||
|
||||
Volatile::~Volatile()
|
||||
{
|
||||
// Remove the pointer to this object.
|
||||
all.remove(this);
|
||||
}
|
||||
|
||||
bool Volatile::loadAll()
|
||||
{
|
||||
bool success = true;
|
||||
std::list<Volatile *>::iterator i = all.begin();
|
||||
|
||||
while (i != all.end())
|
||||
{
|
||||
success = success && (*i)->loadVolatile();
|
||||
i++;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void Volatile::unloadAll()
|
||||
{
|
||||
std::list<Volatile *>::iterator i = all.begin();
|
||||
|
||||
while (i != all.end())
|
||||
{
|
||||
(*i)->unloadVolatile();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_VOLATILE_H
|
||||
#define LOVE_GRAPHICS_VOLATILE_H
|
||||
|
||||
// STL
|
||||
#include <list>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
/**
|
||||
* This class is the superclass of all objects which must completely or
|
||||
* partially reload when the user changes the display resolution. All
|
||||
* volatile objects will be notified when the display mode changes.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Volatile
|
||||
{
|
||||
private:
|
||||
|
||||
// A list of all Volatile object currently alive.
|
||||
static std::list<Volatile *> all;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor. Automatically adds \c this into the list
|
||||
* of volatile objects.
|
||||
**/
|
||||
Volatile();
|
||||
|
||||
/**
|
||||
* Destructor. Removes \c this from the list of volatile
|
||||
* objects.
|
||||
**/
|
||||
virtual ~Volatile();
|
||||
|
||||
/**
|
||||
* Loads the part(s) of the object which is destroyed when
|
||||
* the display mode is changed.
|
||||
*
|
||||
* @return True if successful, false on errors.
|
||||
**/
|
||||
virtual bool loadVolatile() = 0;
|
||||
|
||||
/**
|
||||
* Unloads the part(s) of the objects which would be destroyed
|
||||
* anyway when the display mode is changed.
|
||||
**/
|
||||
virtual void unloadVolatile() = 0;
|
||||
|
||||
// Static:
|
||||
|
||||
/**
|
||||
* Calls \c loadVolatile() on each element in the list of volatiles.
|
||||
*
|
||||
* @return True if all elements succeeded, false if one or more failed.
|
||||
**/
|
||||
static bool loadAll();
|
||||
|
||||
/**
|
||||
* Calls \c unloadVolatile() on each element in the list of volatiles.
|
||||
**/
|
||||
static void unloadAll();
|
||||
|
||||
}; // Volatile
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_VOLATILE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_VOLATILE_H
|
||||
#define LOVE_GRAPHICS_VOLATILE_H
|
||||
|
||||
// STL
|
||||
#include <list>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
/**
|
||||
* This class is the superclass of all objects which must completely or
|
||||
* partially reload when the user changes the display resolution. All
|
||||
* volatile objects will be notified when the display mode changes.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Volatile
|
||||
{
|
||||
private:
|
||||
|
||||
// A list of all Volatile object currently alive.
|
||||
static std::list<Volatile *> all;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor. Automatically adds \c this into the list
|
||||
* of volatile objects.
|
||||
**/
|
||||
Volatile();
|
||||
|
||||
/**
|
||||
* Destructor. Removes \c this from the list of volatile
|
||||
* objects.
|
||||
**/
|
||||
virtual ~Volatile();
|
||||
|
||||
/**
|
||||
* Loads the part(s) of the object which is destroyed when
|
||||
* the display mode is changed.
|
||||
*
|
||||
* @return True if successful, false on errors.
|
||||
**/
|
||||
virtual bool loadVolatile() = 0;
|
||||
|
||||
/**
|
||||
* Unloads the part(s) of the objects which would be destroyed
|
||||
* anyway when the display mode is changed.
|
||||
**/
|
||||
virtual void unloadVolatile() = 0;
|
||||
|
||||
// Static:
|
||||
|
||||
/**
|
||||
* Calls \c loadVolatile() on each element in the list of volatiles.
|
||||
*
|
||||
* @return True if all elements succeeded, false if one or more failed.
|
||||
**/
|
||||
static bool loadAll();
|
||||
|
||||
/**
|
||||
* Calls \c unloadVolatile() on each element in the list of volatiles.
|
||||
**/
|
||||
static void unloadAll();
|
||||
|
||||
}; // Volatile
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_VOLATILE_H
|
||||
|
||||
@@ -1,452 +1,452 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Canvas.h"
|
||||
#include "Graphics.h"
|
||||
#include "common/Matrix.h"
|
||||
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// strategy for fbo creation, interchangable at runtime:
|
||||
// none, opengl >= 3.0, extensions
|
||||
struct FramebufferStrategy
|
||||
{
|
||||
/// create a new framebuffer, depth_stencil and texture
|
||||
/**
|
||||
* @param[out] framebuffer Framebuffer name
|
||||
* @param[out] depth_stencil Name for packed depth and stencil buffer
|
||||
* @param[out] img Texture name
|
||||
* @param[in] width Width of framebuffer
|
||||
* @param[in] height Height of framebuffer
|
||||
* @return Creation status
|
||||
*/
|
||||
virtual GLenum createFBO(GLuint &, GLuint &, GLuint &, int, int)
|
||||
{
|
||||
return GL_FRAMEBUFFER_UNSUPPORTED;
|
||||
}
|
||||
/// remove objects
|
||||
/**
|
||||
* @param[in] framebuffer Framebuffer name
|
||||
* @param[in] depth_stencil Name for packed depth and stencil buffer
|
||||
* @param[in] img Texture name
|
||||
*/
|
||||
virtual void deleteFBO(GLuint, GLuint, GLuint) {}
|
||||
virtual void bindFBO(GLuint) {}
|
||||
};
|
||||
|
||||
struct FramebufferStrategyGL3 : public FramebufferStrategy
|
||||
{
|
||||
virtual GLenum createFBO(GLuint &framebuffer, GLuint &depth_stencil, GLuint &img, int width, int height)
|
||||
{
|
||||
// get currently bound fbo to reset to it later
|
||||
GLint current_fbo;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo);
|
||||
|
||||
// create framebuffer
|
||||
glGenFramebuffers(1, &framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
// create stencil buffer
|
||||
glGenRenderbuffers(1, &depth_stencil);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, depth_stencil);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||
GL_RENDERBUFFER, depth_stencil);
|
||||
|
||||
// generate texture save target
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
bindTexture(0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, img, 0);
|
||||
|
||||
// check status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
|
||||
// unbind framebuffer
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, (GLuint)current_fbo);
|
||||
return status;
|
||||
}
|
||||
virtual void deleteFBO(GLuint framebuffer, GLuint depth_stencil, GLuint img)
|
||||
{
|
||||
deleteTexture(img);
|
||||
glDeleteRenderbuffers(1, &depth_stencil);
|
||||
glDeleteFramebuffers(1, &framebuffer);
|
||||
}
|
||||
|
||||
virtual void bindFBO(GLuint framebuffer)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
}
|
||||
};
|
||||
|
||||
struct FramebufferStrategyEXT : public FramebufferStrategy
|
||||
{
|
||||
|
||||
virtual GLenum createFBO(GLuint &framebuffer, GLuint &depth_stencil, GLuint &img, int width, int height)
|
||||
{
|
||||
GLint current_fbo;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, ¤t_fbo);
|
||||
|
||||
// create framebuffer
|
||||
glGenFramebuffersEXT(1, &framebuffer);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
|
||||
// create stencil buffer
|
||||
glGenRenderbuffersEXT(1, &depth_stencil);
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_stencil);
|
||||
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, width, height);
|
||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
|
||||
GL_RENDERBUFFER_EXT, depth_stencil);
|
||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
|
||||
GL_RENDERBUFFER_EXT, depth_stencil);
|
||||
|
||||
// generate texture save target
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
bindTexture(0);
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, img, 0);
|
||||
|
||||
// check status
|
||||
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||
|
||||
// unbind framebuffer
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)current_fbo);
|
||||
return status;
|
||||
}
|
||||
|
||||
virtual void deleteFBO(GLuint framebuffer, GLuint depth_stencil, GLuint img)
|
||||
{
|
||||
deleteTexture(img);
|
||||
glDeleteRenderbuffersEXT(1, &depth_stencil);
|
||||
glDeleteFramebuffersEXT(1, &framebuffer);
|
||||
}
|
||||
|
||||
virtual void bindFBO(GLuint framebuffer)
|
||||
{
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
}
|
||||
};
|
||||
|
||||
FramebufferStrategy *strategy = NULL;
|
||||
|
||||
FramebufferStrategy strategyNone;
|
||||
|
||||
FramebufferStrategyGL3 strategyGL3;
|
||||
|
||||
FramebufferStrategyEXT strategyEXT;
|
||||
|
||||
Canvas *Canvas::current = NULL;
|
||||
|
||||
static void loadStrategy()
|
||||
{
|
||||
if (!strategy)
|
||||
{
|
||||
if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
|
||||
strategy = &strategyGL3;
|
||||
else if (GLEE_EXT_framebuffer_object && GLEE_EXT_packed_depth_stencil)
|
||||
strategy = &strategyEXT;
|
||||
else
|
||||
strategy = &strategyNone;
|
||||
}
|
||||
}
|
||||
|
||||
Canvas::Canvas(int width, int height)
|
||||
: width(width)
|
||||
, height(height)
|
||||
{
|
||||
float w = static_cast<float>(width);
|
||||
float h = static_cast<float>(height);
|
||||
|
||||
// world coordinates
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = h;
|
||||
vertices[2].x = w;
|
||||
vertices[2].y = h;
|
||||
vertices[3].x = w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
// texture coordinates
|
||||
vertices[0].s = 0;
|
||||
vertices[0].t = 1;
|
||||
vertices[1].s = 0;
|
||||
vertices[1].t = 0;
|
||||
vertices[2].s = 1;
|
||||
vertices[2].t = 0;
|
||||
vertices[3].s = 1;
|
||||
vertices[3].t = 1;
|
||||
|
||||
loadStrategy();
|
||||
|
||||
loadVolatile();
|
||||
}
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
// reset framebuffer if still using this one
|
||||
if (current == this)
|
||||
stopGrab();
|
||||
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool Canvas::isSupported()
|
||||
{
|
||||
loadStrategy();
|
||||
return (strategy != &strategyNone);
|
||||
}
|
||||
|
||||
void Canvas::bindDefaultCanvas()
|
||||
{
|
||||
if (current != NULL)
|
||||
current->stopGrab();
|
||||
}
|
||||
|
||||
void Canvas::startGrab()
|
||||
{
|
||||
// already grabbing
|
||||
if (current == this)
|
||||
return;
|
||||
|
||||
// cleanup after previous fbo
|
||||
if (current != NULL)
|
||||
current->stopGrab();
|
||||
|
||||
// bind buffer and clear screen
|
||||
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
|
||||
strategy->bindFBO(fbo);
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
// Reset the projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set up orthographic view (no depth)
|
||||
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
|
||||
|
||||
// Switch back to modelview matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
// indicate we are using this fbo
|
||||
current = this;
|
||||
}
|
||||
|
||||
void Canvas::stopGrab()
|
||||
{
|
||||
// i am not grabbing. leave me alone
|
||||
if (current != this)
|
||||
return;
|
||||
|
||||
// bind default
|
||||
strategy->bindFBO(0);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
|
||||
void Canvas::clear(const Color &c)
|
||||
{
|
||||
GLuint previous = 0;
|
||||
if (current != NULL)
|
||||
previous = current->fbo;
|
||||
|
||||
strategy->bindFBO(fbo);
|
||||
glPushAttrib(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glPopAttrib();
|
||||
|
||||
strategy->bindFBO(previous);
|
||||
}
|
||||
|
||||
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
drawv(t, vertices);
|
||||
}
|
||||
|
||||
void Canvas::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
quad->mirror(false, true);
|
||||
const vertex *v = quad->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, v);
|
||||
quad->mirror(false, true);
|
||||
}
|
||||
|
||||
love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
||||
{
|
||||
int row = 4 * width;
|
||||
int size = row * height;
|
||||
GLubyte *pixels = new GLubyte[size];
|
||||
GLubyte *screenshot = new GLubyte[size];
|
||||
|
||||
strategy->bindFBO(fbo);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
if (current)
|
||||
strategy->bindFBO(current->fbo);
|
||||
else
|
||||
strategy->bindFBO(0);
|
||||
|
||||
GLubyte *src = pixels - row; // second line of source image
|
||||
GLubyte *dst = screenshot + size; // last row of destination image
|
||||
|
||||
for (int i = 0; i < height; ++i)
|
||||
memcpy(dst -= row, src += row, row);
|
||||
|
||||
love::image::ImageData *img = image->newImageData(width, height, (void *)screenshot);
|
||||
|
||||
delete[] screenshot;
|
||||
delete[] pixels;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
void Canvas::setFilter(const Image::Filter &f)
|
||||
{
|
||||
GLint gmin = (f.min == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;
|
||||
GLint gmag = (f.mag == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;
|
||||
|
||||
bindTexture(img);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
}
|
||||
|
||||
Image::Filter Canvas::getFilter() const
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
|
||||
bindTexture(img);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
f.min = (gmin == GL_NEAREST) ? Image::FILTER_NEAREST : Image::FILTER_LINEAR;
|
||||
f.mag = (gmag == GL_NEAREST) ? Image::FILTER_NEAREST : Image::FILTER_LINEAR;
|
||||
return f;
|
||||
}
|
||||
|
||||
void Canvas::setWrap(const Image::Wrap &w)
|
||||
{
|
||||
GLint wrap_s = (w.s == Image::WRAP_CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
GLint wrap_t = (w.t == Image::WRAP_CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
|
||||
}
|
||||
|
||||
Image::Wrap Canvas::getWrap() const
|
||||
{
|
||||
GLint wrap_s, wrap_t;
|
||||
bindTexture(img);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &wrap_s);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &wrap_t);
|
||||
|
||||
Image::Wrap w;
|
||||
w.s = (wrap_s == GL_CLAMP_TO_EDGE) ? Image::WRAP_CLAMP : Image::WRAP_REPEAT;
|
||||
w.t = (wrap_t == GL_CLAMP_TO_EDGE) ? Image::WRAP_CLAMP : Image::WRAP_REPEAT;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
bool Canvas::loadVolatile()
|
||||
{
|
||||
status = strategy->createFBO(fbo, depth_stencil, img, width, height);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
return false;
|
||||
|
||||
setFilter(settings.filter);
|
||||
setWrap(settings.wrap);
|
||||
Color c;
|
||||
c.r = c.g = c.b = c.a = 0;
|
||||
clear(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Canvas::unloadVolatile()
|
||||
{
|
||||
settings.filter = getFilter();
|
||||
settings.wrap = getWrap();
|
||||
strategy->deleteFBO(fbo, depth_stencil, img);
|
||||
}
|
||||
|
||||
int Canvas::getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
int Canvas::getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
void Canvas::drawv(const Matrix &t, const vertex *v) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
bindTexture(img);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Canvas.h"
|
||||
#include "Graphics.h"
|
||||
#include "common/Matrix.h"
|
||||
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// strategy for fbo creation, interchangable at runtime:
|
||||
// none, opengl >= 3.0, extensions
|
||||
struct FramebufferStrategy
|
||||
{
|
||||
/// create a new framebuffer, depth_stencil and texture
|
||||
/**
|
||||
* @param[out] framebuffer Framebuffer name
|
||||
* @param[out] depth_stencil Name for packed depth and stencil buffer
|
||||
* @param[out] img Texture name
|
||||
* @param[in] width Width of framebuffer
|
||||
* @param[in] height Height of framebuffer
|
||||
* @return Creation status
|
||||
*/
|
||||
virtual GLenum createFBO(GLuint &, GLuint &, GLuint &, int, int)
|
||||
{
|
||||
return GL_FRAMEBUFFER_UNSUPPORTED;
|
||||
}
|
||||
/// remove objects
|
||||
/**
|
||||
* @param[in] framebuffer Framebuffer name
|
||||
* @param[in] depth_stencil Name for packed depth and stencil buffer
|
||||
* @param[in] img Texture name
|
||||
*/
|
||||
virtual void deleteFBO(GLuint, GLuint, GLuint) {}
|
||||
virtual void bindFBO(GLuint) {}
|
||||
};
|
||||
|
||||
struct FramebufferStrategyGL3 : public FramebufferStrategy
|
||||
{
|
||||
virtual GLenum createFBO(GLuint &framebuffer, GLuint &depth_stencil, GLuint &img, int width, int height)
|
||||
{
|
||||
// get currently bound fbo to reset to it later
|
||||
GLint current_fbo;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo);
|
||||
|
||||
// create framebuffer
|
||||
glGenFramebuffers(1, &framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
// create stencil buffer
|
||||
glGenRenderbuffers(1, &depth_stencil);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, depth_stencil);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||
GL_RENDERBUFFER, depth_stencil);
|
||||
|
||||
// generate texture save target
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
bindTexture(0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, img, 0);
|
||||
|
||||
// check status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
|
||||
// unbind framebuffer
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, (GLuint)current_fbo);
|
||||
return status;
|
||||
}
|
||||
virtual void deleteFBO(GLuint framebuffer, GLuint depth_stencil, GLuint img)
|
||||
{
|
||||
deleteTexture(img);
|
||||
glDeleteRenderbuffers(1, &depth_stencil);
|
||||
glDeleteFramebuffers(1, &framebuffer);
|
||||
}
|
||||
|
||||
virtual void bindFBO(GLuint framebuffer)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
}
|
||||
};
|
||||
|
||||
struct FramebufferStrategyEXT : public FramebufferStrategy
|
||||
{
|
||||
|
||||
virtual GLenum createFBO(GLuint &framebuffer, GLuint &depth_stencil, GLuint &img, int width, int height)
|
||||
{
|
||||
GLint current_fbo;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, ¤t_fbo);
|
||||
|
||||
// create framebuffer
|
||||
glGenFramebuffersEXT(1, &framebuffer);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
|
||||
// create stencil buffer
|
||||
glGenRenderbuffersEXT(1, &depth_stencil);
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_stencil);
|
||||
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, width, height);
|
||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
|
||||
GL_RENDERBUFFER_EXT, depth_stencil);
|
||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
|
||||
GL_RENDERBUFFER_EXT, depth_stencil);
|
||||
|
||||
// generate texture save target
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
bindTexture(0);
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, img, 0);
|
||||
|
||||
// check status
|
||||
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||
|
||||
// unbind framebuffer
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)current_fbo);
|
||||
return status;
|
||||
}
|
||||
|
||||
virtual void deleteFBO(GLuint framebuffer, GLuint depth_stencil, GLuint img)
|
||||
{
|
||||
deleteTexture(img);
|
||||
glDeleteRenderbuffersEXT(1, &depth_stencil);
|
||||
glDeleteFramebuffersEXT(1, &framebuffer);
|
||||
}
|
||||
|
||||
virtual void bindFBO(GLuint framebuffer)
|
||||
{
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
}
|
||||
};
|
||||
|
||||
FramebufferStrategy *strategy = NULL;
|
||||
|
||||
FramebufferStrategy strategyNone;
|
||||
|
||||
FramebufferStrategyGL3 strategyGL3;
|
||||
|
||||
FramebufferStrategyEXT strategyEXT;
|
||||
|
||||
Canvas *Canvas::current = NULL;
|
||||
|
||||
static void loadStrategy()
|
||||
{
|
||||
if (!strategy)
|
||||
{
|
||||
if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
|
||||
strategy = &strategyGL3;
|
||||
else if (GLEE_EXT_framebuffer_object && GLEE_EXT_packed_depth_stencil)
|
||||
strategy = &strategyEXT;
|
||||
else
|
||||
strategy = &strategyNone;
|
||||
}
|
||||
}
|
||||
|
||||
Canvas::Canvas(int width, int height)
|
||||
: width(width)
|
||||
, height(height)
|
||||
{
|
||||
float w = static_cast<float>(width);
|
||||
float h = static_cast<float>(height);
|
||||
|
||||
// world coordinates
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = h;
|
||||
vertices[2].x = w;
|
||||
vertices[2].y = h;
|
||||
vertices[3].x = w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
// texture coordinates
|
||||
vertices[0].s = 0;
|
||||
vertices[0].t = 1;
|
||||
vertices[1].s = 0;
|
||||
vertices[1].t = 0;
|
||||
vertices[2].s = 1;
|
||||
vertices[2].t = 0;
|
||||
vertices[3].s = 1;
|
||||
vertices[3].t = 1;
|
||||
|
||||
loadStrategy();
|
||||
|
||||
loadVolatile();
|
||||
}
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
// reset framebuffer if still using this one
|
||||
if (current == this)
|
||||
stopGrab();
|
||||
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool Canvas::isSupported()
|
||||
{
|
||||
loadStrategy();
|
||||
return (strategy != &strategyNone);
|
||||
}
|
||||
|
||||
void Canvas::bindDefaultCanvas()
|
||||
{
|
||||
if (current != NULL)
|
||||
current->stopGrab();
|
||||
}
|
||||
|
||||
void Canvas::startGrab()
|
||||
{
|
||||
// already grabbing
|
||||
if (current == this)
|
||||
return;
|
||||
|
||||
// cleanup after previous fbo
|
||||
if (current != NULL)
|
||||
current->stopGrab();
|
||||
|
||||
// bind buffer and clear screen
|
||||
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
|
||||
strategy->bindFBO(fbo);
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
// Reset the projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set up orthographic view (no depth)
|
||||
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
|
||||
|
||||
// Switch back to modelview matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
// indicate we are using this fbo
|
||||
current = this;
|
||||
}
|
||||
|
||||
void Canvas::stopGrab()
|
||||
{
|
||||
// i am not grabbing. leave me alone
|
||||
if (current != this)
|
||||
return;
|
||||
|
||||
// bind default
|
||||
strategy->bindFBO(0);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
|
||||
void Canvas::clear(const Color &c)
|
||||
{
|
||||
GLuint previous = 0;
|
||||
if (current != NULL)
|
||||
previous = current->fbo;
|
||||
|
||||
strategy->bindFBO(fbo);
|
||||
glPushAttrib(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glPopAttrib();
|
||||
|
||||
strategy->bindFBO(previous);
|
||||
}
|
||||
|
||||
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
drawv(t, vertices);
|
||||
}
|
||||
|
||||
void Canvas::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
quad->mirror(false, true);
|
||||
const vertex *v = quad->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, v);
|
||||
quad->mirror(false, true);
|
||||
}
|
||||
|
||||
love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
||||
{
|
||||
int row = 4 * width;
|
||||
int size = row * height;
|
||||
GLubyte *pixels = new GLubyte[size];
|
||||
GLubyte *screenshot = new GLubyte[size];
|
||||
|
||||
strategy->bindFBO(fbo);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
if (current)
|
||||
strategy->bindFBO(current->fbo);
|
||||
else
|
||||
strategy->bindFBO(0);
|
||||
|
||||
GLubyte *src = pixels - row; // second line of source image
|
||||
GLubyte *dst = screenshot + size; // last row of destination image
|
||||
|
||||
for (int i = 0; i < height; ++i)
|
||||
memcpy(dst -= row, src += row, row);
|
||||
|
||||
love::image::ImageData *img = image->newImageData(width, height, (void *)screenshot);
|
||||
|
||||
delete[] screenshot;
|
||||
delete[] pixels;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
void Canvas::setFilter(const Image::Filter &f)
|
||||
{
|
||||
GLint gmin = (f.min == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;
|
||||
GLint gmag = (f.mag == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;
|
||||
|
||||
bindTexture(img);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
}
|
||||
|
||||
Image::Filter Canvas::getFilter() const
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
|
||||
bindTexture(img);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
f.min = (gmin == GL_NEAREST) ? Image::FILTER_NEAREST : Image::FILTER_LINEAR;
|
||||
f.mag = (gmag == GL_NEAREST) ? Image::FILTER_NEAREST : Image::FILTER_LINEAR;
|
||||
return f;
|
||||
}
|
||||
|
||||
void Canvas::setWrap(const Image::Wrap &w)
|
||||
{
|
||||
GLint wrap_s = (w.s == Image::WRAP_CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
GLint wrap_t = (w.t == Image::WRAP_CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
|
||||
}
|
||||
|
||||
Image::Wrap Canvas::getWrap() const
|
||||
{
|
||||
GLint wrap_s, wrap_t;
|
||||
bindTexture(img);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &wrap_s);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &wrap_t);
|
||||
|
||||
Image::Wrap w;
|
||||
w.s = (wrap_s == GL_CLAMP_TO_EDGE) ? Image::WRAP_CLAMP : Image::WRAP_REPEAT;
|
||||
w.t = (wrap_t == GL_CLAMP_TO_EDGE) ? Image::WRAP_CLAMP : Image::WRAP_REPEAT;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
bool Canvas::loadVolatile()
|
||||
{
|
||||
status = strategy->createFBO(fbo, depth_stencil, img, width, height);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
return false;
|
||||
|
||||
setFilter(settings.filter);
|
||||
setWrap(settings.wrap);
|
||||
Color c;
|
||||
c.r = c.g = c.b = c.a = 0;
|
||||
clear(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Canvas::unloadVolatile()
|
||||
{
|
||||
settings.filter = getFilter();
|
||||
settings.wrap = getWrap();
|
||||
strategy->deleteFBO(fbo, depth_stencil, img);
|
||||
}
|
||||
|
||||
int Canvas::getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
int Canvas::getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
void Canvas::drawv(const Matrix &t, const vertex *v) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
bindTexture(img);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_CANVAS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_CANVAS_H
|
||||
|
||||
#include "graphics/DrawQable.h"
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/Image.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "image/Image.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "common/math.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "OpenGL.h"
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Canvas : public DrawQable, public Volatile
|
||||
{
|
||||
public:
|
||||
Canvas(int width, int height);
|
||||
virtual ~Canvas();
|
||||
|
||||
static bool isSupported();
|
||||
|
||||
unsigned int getStatus() const
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
static Canvas *current;
|
||||
static void bindDefaultCanvas();
|
||||
|
||||
void startGrab();
|
||||
void stopGrab();
|
||||
|
||||
void clear(const Color &c);
|
||||
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* @copydoc DrawQable::drawq()
|
||||
**/
|
||||
void drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
love::image::ImageData *getImageData(love::image::Image *image);
|
||||
|
||||
void setFilter(const Image::Filter &f);
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(const Image::Wrap &w);
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
friend class PixelEffect;
|
||||
GLuint getTextureName() const
|
||||
{
|
||||
return img;
|
||||
}
|
||||
|
||||
GLsizei width;
|
||||
GLsizei height;
|
||||
GLuint fbo;
|
||||
GLuint depth_stencil;
|
||||
GLuint img;
|
||||
|
||||
vertex vertices[4];
|
||||
|
||||
GLenum status;
|
||||
|
||||
struct
|
||||
{
|
||||
Image::Filter filter;
|
||||
Image::Wrap wrap;
|
||||
} settings;
|
||||
|
||||
void drawv(const Matrix &t, const vertex *v) const;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_CANVAS_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_CANVAS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_CANVAS_H
|
||||
|
||||
#include "graphics/DrawQable.h"
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/Image.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "image/Image.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "common/math.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "OpenGL.h"
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Canvas : public DrawQable, public Volatile
|
||||
{
|
||||
public:
|
||||
Canvas(int width, int height);
|
||||
virtual ~Canvas();
|
||||
|
||||
static bool isSupported();
|
||||
|
||||
unsigned int getStatus() const
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
static Canvas *current;
|
||||
static void bindDefaultCanvas();
|
||||
|
||||
void startGrab();
|
||||
void stopGrab();
|
||||
|
||||
void clear(const Color &c);
|
||||
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* @copydoc DrawQable::drawq()
|
||||
**/
|
||||
void drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
love::image::ImageData *getImageData(love::image::Image *image);
|
||||
|
||||
void setFilter(const Image::Filter &f);
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(const Image::Wrap &w);
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
friend class PixelEffect;
|
||||
GLuint getTextureName() const
|
||||
{
|
||||
return img;
|
||||
}
|
||||
|
||||
GLsizei width;
|
||||
GLsizei height;
|
||||
GLuint fbo;
|
||||
GLuint depth_stencil;
|
||||
GLuint img;
|
||||
|
||||
vertex vertices[4];
|
||||
|
||||
GLenum status;
|
||||
|
||||
struct
|
||||
{
|
||||
Image::Filter filter;
|
||||
Image::Wrap wrap;
|
||||
} settings;
|
||||
|
||||
void drawv(const Matrix &t, const vertex *v) const;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_CANVAS_H
|
||||
|
||||
@@ -1,385 +1,385 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
#include "common/config.h"
|
||||
#include "Font.h"
|
||||
#include "font/GlyphData.h"
|
||||
#include "Quad.h"
|
||||
|
||||
#include "libraries/utf8/utf8.h"
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Matrix.h"
|
||||
#include <math.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <algorithm> // for max
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
|
||||
: rasterizer(r)
|
||||
, height(r->getHeight())
|
||||
, lineHeight(1)
|
||||
, mSpacing(1)
|
||||
, filter(filter)
|
||||
{
|
||||
r->retain();
|
||||
love::font::GlyphData *gd = r->getGlyphData(32);
|
||||
type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
|
||||
delete gd;
|
||||
createTexture();
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
rasterizer->release();
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
void Font::createTexture()
|
||||
{
|
||||
texture_x = texture_y = rowHeight = TEXTURE_PADDING;
|
||||
GLuint t;
|
||||
glGenTextures(1, &t);
|
||||
textures.push_back(t);
|
||||
bindTexture(t);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
|
||||
// Initialize the texture
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
(GLsizei)TEXTURE_WIDTH,
|
||||
(GLsizei)TEXTURE_HEIGHT,
|
||||
0,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
NULL);
|
||||
// Fill the texture with transparent black
|
||||
std::vector<GLubyte> emptyData(TEXTURE_WIDTH * TEXTURE_HEIGHT * (type == FONT_TRUETYPE ? 2 : 4), 0);
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(GLsizei)TEXTURE_WIDTH,
|
||||
(GLsizei)TEXTURE_HEIGHT,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
&emptyData[0]);
|
||||
}
|
||||
|
||||
Font::Glyph *Font::addGlyph(int glyph)
|
||||
{
|
||||
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
|
||||
int w = gd->getWidth();
|
||||
int h = gd->getHeight();
|
||||
|
||||
if (texture_x + w + TEXTURE_PADDING > TEXTURE_WIDTH)
|
||||
{
|
||||
// out of space - new row!
|
||||
texture_x = TEXTURE_PADDING;
|
||||
texture_y += rowHeight;
|
||||
rowHeight = TEXTURE_PADDING;
|
||||
}
|
||||
if (texture_y + h + TEXTURE_PADDING > TEXTURE_HEIGHT)
|
||||
{
|
||||
// totally out of space - new texture!
|
||||
createTexture();
|
||||
}
|
||||
|
||||
Glyph *g = new Glyph;
|
||||
g->list = g->texture = 0;
|
||||
g->spacing = gd->getAdvance();
|
||||
|
||||
// don't waste space for empty glyphs. also fixes a division by zero bug with ati drivers
|
||||
if (w > 0 && h > 0)
|
||||
{
|
||||
g->list = glGenLists(1);
|
||||
if (0 == g->list)
|
||||
{
|
||||
delete g;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GLuint t = textures.back();
|
||||
bindTexture(t);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
|
||||
|
||||
g->texture = t;
|
||||
|
||||
Quad::Viewport v;
|
||||
v.x = (float) texture_x;
|
||||
v.y = (float) texture_y;
|
||||
v.w = (float) w;
|
||||
v.h = (float) h;
|
||||
Quad *q = new Quad(v, (const float) TEXTURE_WIDTH, (const float) TEXTURE_HEIGHT);
|
||||
const vertex *verts = q->getVertices();
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].s);
|
||||
|
||||
glNewList(g->list, GL_COMPILE);
|
||||
glPushMatrix();
|
||||
glTranslatef(static_cast<float>(gd->getBearingX()), static_cast<float>(-gd->getBearingY()), 0.0f);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glPopMatrix();
|
||||
glEndList();
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
if (w > 0)
|
||||
texture_x += (w + TEXTURE_PADDING);
|
||||
if (h > 0)
|
||||
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
|
||||
|
||||
delete gd;
|
||||
glyphs[glyph] = g;
|
||||
return g;
|
||||
}
|
||||
|
||||
float Font::getHeight() const
|
||||
{
|
||||
return static_cast<float>(height);
|
||||
}
|
||||
|
||||
void Font::print(std::string text, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||
{
|
||||
float dx = 0.0f; // spacing counter for newline handling
|
||||
glPushMatrix();
|
||||
|
||||
Matrix t;
|
||||
t.setTransformation(ceil(x), ceil(y), angle, sx, sy, ox, oy, kx, ky);
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::iterator> i(text.begin(), text.begin(), text.end());
|
||||
utf8::iterator<std::string::iterator> end(text.end(), text.begin(), text.end());
|
||||
while (i != end)
|
||||
{
|
||||
int g = *i++;
|
||||
if (g == '\n')
|
||||
{
|
||||
// wrap newline, but do not print it
|
||||
glTranslatef(-dx, floor(getHeight() * getLineHeight() + 0.5f), 0);
|
||||
dx = 0.0f;
|
||||
continue;
|
||||
}
|
||||
Glyph *glyph = glyphs[g];
|
||||
if (!glyph) glyph = addGlyph(g);
|
||||
glPushMatrix();
|
||||
// 1.25 is magic line height for true type fonts
|
||||
if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() / 1.25f + 0.5f), 0);
|
||||
bindTexture(glyph->texture);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
glTranslatef(static_cast<GLfloat>(glyph->spacing), 0, 0);
|
||||
dx += glyph->spacing;
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
glPopMatrix();
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Font::print(char character, float x, float y)
|
||||
{
|
||||
Glyph *glyph = glyphs[character];
|
||||
if (!glyph) glyph = addGlyph(character);
|
||||
|
||||
if (0 != glyph->texture)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
|
||||
bindTexture(glyph->texture);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
int Font::getWidth(const std::string &line)
|
||||
{
|
||||
if (line.size() == 0) return 0;
|
||||
int temp = 0;
|
||||
|
||||
Glyph *g;
|
||||
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::const_iterator> i(line.begin(), line.begin(), line.end());
|
||||
utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end());
|
||||
while (i != end)
|
||||
{
|
||||
int c = *i++;
|
||||
g = glyphs[c];
|
||||
if (!g) g = addGlyph(c);
|
||||
temp += static_cast<int>(g->spacing * mSpacing);
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
int Font::getWidth(const char *line)
|
||||
{
|
||||
return this->getWidth(std::string(line));
|
||||
}
|
||||
|
||||
int Font::getWidth(const char character)
|
||||
{
|
||||
Glyph *g = glyphs[character];
|
||||
if (!g) g = addGlyph(character);
|
||||
return g->spacing;
|
||||
}
|
||||
|
||||
std::vector<std::string> Font::getWrap(const std::string text, float wrap, int *max_width)
|
||||
{
|
||||
using namespace std;
|
||||
const float width_space = static_cast<float>(getWidth(' '));
|
||||
vector<string> lines_to_draw;
|
||||
int maxw = 0;
|
||||
|
||||
//split text at newlines
|
||||
istringstream iss(text);
|
||||
string line;
|
||||
ostringstream string_builder;
|
||||
while (getline(iss, line, '\n'))
|
||||
{
|
||||
// split line into words
|
||||
vector<string> words;
|
||||
istringstream word_iss(line);
|
||||
copy(istream_iterator<string>(word_iss), istream_iterator<string>(),
|
||||
back_inserter< vector<string> >(words));
|
||||
|
||||
// put words back together until a wrap occurs
|
||||
float width = 0.0f;
|
||||
float oldwidth = 0.0f;
|
||||
string_builder.str("");
|
||||
vector<string>::const_iterator word_iter, wend = words.end();
|
||||
for (word_iter = words.begin(); word_iter != wend; ++word_iter)
|
||||
{
|
||||
const string &word = *word_iter;
|
||||
width += getWidth(word);
|
||||
|
||||
// on wordwrap, push line to line buffer and clear string builder
|
||||
if (width >= wrap && oldwidth > 0)
|
||||
{
|
||||
int realw = (int) width;
|
||||
|
||||
// remove trailing space
|
||||
string tmp = string_builder.str();
|
||||
lines_to_draw.push_back(tmp.substr(0,tmp.size()-1));
|
||||
string_builder.str("");
|
||||
width = static_cast<float>(getWidth(word));
|
||||
realw -= (int) width;
|
||||
if (realw > maxw)
|
||||
maxw = realw;
|
||||
}
|
||||
string_builder << word << " ";
|
||||
width += width_space;
|
||||
oldwidth = width;
|
||||
}
|
||||
// push last line
|
||||
if (width > maxw)
|
||||
maxw = (int) width;
|
||||
string tmp = string_builder.str();
|
||||
lines_to_draw.push_back(tmp.substr(0,tmp.size()-1));
|
||||
}
|
||||
|
||||
if (max_width)
|
||||
*max_width = maxw;
|
||||
|
||||
return lines_to_draw;
|
||||
}
|
||||
|
||||
void Font::setLineHeight(float height)
|
||||
{
|
||||
this->lineHeight = height;
|
||||
}
|
||||
|
||||
float Font::getLineHeight() const
|
||||
{
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
void Font::setSpacing(float amount)
|
||||
{
|
||||
mSpacing = amount;
|
||||
}
|
||||
|
||||
float Font::getSpacing() const
|
||||
{
|
||||
return mSpacing;
|
||||
}
|
||||
|
||||
bool Font::loadVolatile()
|
||||
{
|
||||
createTexture();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Font::unloadVolatile()
|
||||
{
|
||||
// nuke everything from orbit
|
||||
std::map<int, Glyph *>::iterator it = glyphs.begin();
|
||||
Glyph *g;
|
||||
while (it != glyphs.end())
|
||||
{
|
||||
g = it->second;
|
||||
glDeleteLists(g->list, 1);
|
||||
delete g;
|
||||
glyphs.erase(it++);
|
||||
}
|
||||
std::vector<GLuint>::iterator iter = textures.begin();
|
||||
while (iter != textures.end())
|
||||
{
|
||||
deleteTexture(*iter);
|
||||
iter++;
|
||||
}
|
||||
textures.clear();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
#include "common/config.h"
|
||||
#include "Font.h"
|
||||
#include "font/GlyphData.h"
|
||||
#include "Quad.h"
|
||||
|
||||
#include "libraries/utf8/utf8.h"
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Matrix.h"
|
||||
#include <math.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <algorithm> // for max
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
|
||||
: rasterizer(r)
|
||||
, height(r->getHeight())
|
||||
, lineHeight(1)
|
||||
, mSpacing(1)
|
||||
, filter(filter)
|
||||
{
|
||||
r->retain();
|
||||
love::font::GlyphData *gd = r->getGlyphData(32);
|
||||
type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
|
||||
delete gd;
|
||||
createTexture();
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
rasterizer->release();
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
void Font::createTexture()
|
||||
{
|
||||
texture_x = texture_y = rowHeight = TEXTURE_PADDING;
|
||||
GLuint t;
|
||||
glGenTextures(1, &t);
|
||||
textures.push_back(t);
|
||||
bindTexture(t);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
|
||||
// Initialize the texture
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
(GLsizei)TEXTURE_WIDTH,
|
||||
(GLsizei)TEXTURE_HEIGHT,
|
||||
0,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
NULL);
|
||||
// Fill the texture with transparent black
|
||||
std::vector<GLubyte> emptyData(TEXTURE_WIDTH * TEXTURE_HEIGHT * (type == FONT_TRUETYPE ? 2 : 4), 0);
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(GLsizei)TEXTURE_WIDTH,
|
||||
(GLsizei)TEXTURE_HEIGHT,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
&emptyData[0]);
|
||||
}
|
||||
|
||||
Font::Glyph *Font::addGlyph(int glyph)
|
||||
{
|
||||
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
|
||||
int w = gd->getWidth();
|
||||
int h = gd->getHeight();
|
||||
|
||||
if (texture_x + w + TEXTURE_PADDING > TEXTURE_WIDTH)
|
||||
{
|
||||
// out of space - new row!
|
||||
texture_x = TEXTURE_PADDING;
|
||||
texture_y += rowHeight;
|
||||
rowHeight = TEXTURE_PADDING;
|
||||
}
|
||||
if (texture_y + h + TEXTURE_PADDING > TEXTURE_HEIGHT)
|
||||
{
|
||||
// totally out of space - new texture!
|
||||
createTexture();
|
||||
}
|
||||
|
||||
Glyph *g = new Glyph;
|
||||
g->list = g->texture = 0;
|
||||
g->spacing = gd->getAdvance();
|
||||
|
||||
// don't waste space for empty glyphs. also fixes a division by zero bug with ati drivers
|
||||
if (w > 0 && h > 0)
|
||||
{
|
||||
g->list = glGenLists(1);
|
||||
if (0 == g->list)
|
||||
{
|
||||
delete g;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GLuint t = textures.back();
|
||||
bindTexture(t);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
|
||||
|
||||
g->texture = t;
|
||||
|
||||
Quad::Viewport v;
|
||||
v.x = (float) texture_x;
|
||||
v.y = (float) texture_y;
|
||||
v.w = (float) w;
|
||||
v.h = (float) h;
|
||||
Quad *q = new Quad(v, (const float) TEXTURE_WIDTH, (const float) TEXTURE_HEIGHT);
|
||||
const vertex *verts = q->getVertices();
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].s);
|
||||
|
||||
glNewList(g->list, GL_COMPILE);
|
||||
glPushMatrix();
|
||||
glTranslatef(static_cast<float>(gd->getBearingX()), static_cast<float>(-gd->getBearingY()), 0.0f);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glPopMatrix();
|
||||
glEndList();
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
if (w > 0)
|
||||
texture_x += (w + TEXTURE_PADDING);
|
||||
if (h > 0)
|
||||
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
|
||||
|
||||
delete gd;
|
||||
glyphs[glyph] = g;
|
||||
return g;
|
||||
}
|
||||
|
||||
float Font::getHeight() const
|
||||
{
|
||||
return static_cast<float>(height);
|
||||
}
|
||||
|
||||
void Font::print(std::string text, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||
{
|
||||
float dx = 0.0f; // spacing counter for newline handling
|
||||
glPushMatrix();
|
||||
|
||||
Matrix t;
|
||||
t.setTransformation(ceil(x), ceil(y), angle, sx, sy, ox, oy, kx, ky);
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::iterator> i(text.begin(), text.begin(), text.end());
|
||||
utf8::iterator<std::string::iterator> end(text.end(), text.begin(), text.end());
|
||||
while (i != end)
|
||||
{
|
||||
int g = *i++;
|
||||
if (g == '\n')
|
||||
{
|
||||
// wrap newline, but do not print it
|
||||
glTranslatef(-dx, floor(getHeight() * getLineHeight() + 0.5f), 0);
|
||||
dx = 0.0f;
|
||||
continue;
|
||||
}
|
||||
Glyph *glyph = glyphs[g];
|
||||
if (!glyph) glyph = addGlyph(g);
|
||||
glPushMatrix();
|
||||
// 1.25 is magic line height for true type fonts
|
||||
if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() / 1.25f + 0.5f), 0);
|
||||
bindTexture(glyph->texture);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
glTranslatef(static_cast<GLfloat>(glyph->spacing), 0, 0);
|
||||
dx += glyph->spacing;
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
glPopMatrix();
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Font::print(char character, float x, float y)
|
||||
{
|
||||
Glyph *glyph = glyphs[character];
|
||||
if (!glyph) glyph = addGlyph(character);
|
||||
|
||||
if (0 != glyph->texture)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
|
||||
bindTexture(glyph->texture);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
int Font::getWidth(const std::string &line)
|
||||
{
|
||||
if (line.size() == 0) return 0;
|
||||
int temp = 0;
|
||||
|
||||
Glyph *g;
|
||||
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::const_iterator> i(line.begin(), line.begin(), line.end());
|
||||
utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end());
|
||||
while (i != end)
|
||||
{
|
||||
int c = *i++;
|
||||
g = glyphs[c];
|
||||
if (!g) g = addGlyph(c);
|
||||
temp += static_cast<int>(g->spacing * mSpacing);
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
int Font::getWidth(const char *line)
|
||||
{
|
||||
return this->getWidth(std::string(line));
|
||||
}
|
||||
|
||||
int Font::getWidth(const char character)
|
||||
{
|
||||
Glyph *g = glyphs[character];
|
||||
if (!g) g = addGlyph(character);
|
||||
return g->spacing;
|
||||
}
|
||||
|
||||
std::vector<std::string> Font::getWrap(const std::string text, float wrap, int *max_width)
|
||||
{
|
||||
using namespace std;
|
||||
const float width_space = static_cast<float>(getWidth(' '));
|
||||
vector<string> lines_to_draw;
|
||||
int maxw = 0;
|
||||
|
||||
//split text at newlines
|
||||
istringstream iss(text);
|
||||
string line;
|
||||
ostringstream string_builder;
|
||||
while (getline(iss, line, '\n'))
|
||||
{
|
||||
// split line into words
|
||||
vector<string> words;
|
||||
istringstream word_iss(line);
|
||||
copy(istream_iterator<string>(word_iss), istream_iterator<string>(),
|
||||
back_inserter< vector<string> >(words));
|
||||
|
||||
// put words back together until a wrap occurs
|
||||
float width = 0.0f;
|
||||
float oldwidth = 0.0f;
|
||||
string_builder.str("");
|
||||
vector<string>::const_iterator word_iter, wend = words.end();
|
||||
for (word_iter = words.begin(); word_iter != wend; ++word_iter)
|
||||
{
|
||||
const string &word = *word_iter;
|
||||
width += getWidth(word);
|
||||
|
||||
// on wordwrap, push line to line buffer and clear string builder
|
||||
if (width >= wrap && oldwidth > 0)
|
||||
{
|
||||
int realw = (int) width;
|
||||
|
||||
// remove trailing space
|
||||
string tmp = string_builder.str();
|
||||
lines_to_draw.push_back(tmp.substr(0,tmp.size()-1));
|
||||
string_builder.str("");
|
||||
width = static_cast<float>(getWidth(word));
|
||||
realw -= (int) width;
|
||||
if (realw > maxw)
|
||||
maxw = realw;
|
||||
}
|
||||
string_builder << word << " ";
|
||||
width += width_space;
|
||||
oldwidth = width;
|
||||
}
|
||||
// push last line
|
||||
if (width > maxw)
|
||||
maxw = (int) width;
|
||||
string tmp = string_builder.str();
|
||||
lines_to_draw.push_back(tmp.substr(0,tmp.size()-1));
|
||||
}
|
||||
|
||||
if (max_width)
|
||||
*max_width = maxw;
|
||||
|
||||
return lines_to_draw;
|
||||
}
|
||||
|
||||
void Font::setLineHeight(float height)
|
||||
{
|
||||
this->lineHeight = height;
|
||||
}
|
||||
|
||||
float Font::getLineHeight() const
|
||||
{
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
void Font::setSpacing(float amount)
|
||||
{
|
||||
mSpacing = amount;
|
||||
}
|
||||
|
||||
float Font::getSpacing() const
|
||||
{
|
||||
return mSpacing;
|
||||
}
|
||||
|
||||
bool Font::loadVolatile()
|
||||
{
|
||||
createTexture();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Font::unloadVolatile()
|
||||
{
|
||||
// nuke everything from orbit
|
||||
std::map<int, Glyph *>::iterator it = glyphs.begin();
|
||||
Glyph *g;
|
||||
while (it != glyphs.end())
|
||||
{
|
||||
g = it->second;
|
||||
glDeleteLists(g->list, 1);
|
||||
delete g;
|
||||
glyphs.erase(it++);
|
||||
}
|
||||
std::vector<GLuint>::iterator iter = textures.begin();
|
||||
while (iter != textures.end())
|
||||
{
|
||||
deleteTexture(*iter);
|
||||
iter++;
|
||||
}
|
||||
textures.clear();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
+182
-182
@@ -1,182 +1,182 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
|
||||
// STD
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "font/Rasterizer.h"
|
||||
#include "graphics/Image.h"
|
||||
|
||||
#include "OpenGL.h"
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Font : public Object, public Volatile
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param data The font data to construct from.
|
||||
**/
|
||||
Font(love::font::Rasterizer *r, const Image::Filter &filter = Image::Filter());
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position with rotation and scaling.
|
||||
*
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx Scale along the x axis.
|
||||
* @param sy Scale along the y axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
* @param kx Shear along the x axis.
|
||||
* @param ky Shear along the y axis.
|
||||
**/
|
||||
void print(std::string text, float x, float y, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f, float ox = 0.0f, float oy = 0.0f, float kx = 0.0f, float ky = 0.0f);
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
*
|
||||
* @param character A character.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void print(char character, float x, float y);
|
||||
|
||||
/**
|
||||
* Returns the height of the font.
|
||||
**/
|
||||
float getHeight() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed string.
|
||||
*
|
||||
* @param line A line of text.
|
||||
**/
|
||||
int getWidth(const std::string &line);
|
||||
int getWidth(const char *line);
|
||||
|
||||
/**
|
||||
* Returns the width of the passed character.
|
||||
*
|
||||
* @param character A character.
|
||||
**/
|
||||
int getWidth(const char character);
|
||||
|
||||
/**
|
||||
* Returns the maximal width of a wrapped string
|
||||
* and optionally the number of lines
|
||||
*
|
||||
* @param text The input text
|
||||
* @param wrap The number of pixels to wrap at
|
||||
* @param max_width Optional output of the maximum width
|
||||
* Returns a vector with the lines.
|
||||
**/
|
||||
std::vector<std::string> getWrap(const std::string text, float wrap, int *max_width = 0);
|
||||
|
||||
/**
|
||||
* Sets the line height (which should be a number to multiply the font size by,
|
||||
* example: line height = 1.2 and size = 12 means that rendered line height = 12*1.2)
|
||||
* @param height The new line height.
|
||||
**/
|
||||
void setLineHeight(float height);
|
||||
|
||||
/**
|
||||
* Returns the line height.
|
||||
**/
|
||||
float getLineHeight() const;
|
||||
|
||||
/**
|
||||
* Sets the spacing modifier (changes the spacing between the characters the
|
||||
* same way that the line height does [multiplication]).
|
||||
* Note: The spacing must be set BEFORE the font is loaded to have any effect.
|
||||
* @param amount The amount of modification.
|
||||
**/
|
||||
void setSpacing(float amount);
|
||||
|
||||
/**
|
||||
* Returns the spacing modifier.
|
||||
**/
|
||||
float getSpacing() const;
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
private:
|
||||
|
||||
enum FontType
|
||||
{
|
||||
FONT_TRUETYPE = 1,
|
||||
FONT_IMAGE,
|
||||
FONT_UNKNOWN
|
||||
};
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
GLuint list;
|
||||
GLuint texture;
|
||||
int spacing;
|
||||
};
|
||||
|
||||
love::font::Rasterizer *rasterizer;
|
||||
|
||||
int height;
|
||||
float lineHeight;
|
||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||
std::vector<GLuint> textures; // vector of packed textures
|
||||
std::map<int, Glyph *> glyphs; // maps glyphs to display lists
|
||||
FontType type;
|
||||
Image::Filter filter;
|
||||
|
||||
static const int TEXTURE_WIDTH = 512;
|
||||
static const int TEXTURE_HEIGHT = 512;
|
||||
static const int TEXTURE_PADDING = 1;
|
||||
|
||||
int texture_x, texture_y;
|
||||
int rowHeight;
|
||||
|
||||
void createTexture();
|
||||
Glyph *addGlyph(int glyph);
|
||||
}; // Font
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
|
||||
// STD
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "font/Rasterizer.h"
|
||||
#include "graphics/Image.h"
|
||||
|
||||
#include "OpenGL.h"
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Font : public Object, public Volatile
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param data The font data to construct from.
|
||||
**/
|
||||
Font(love::font::Rasterizer *r, const Image::Filter &filter = Image::Filter());
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position with rotation and scaling.
|
||||
*
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx Scale along the x axis.
|
||||
* @param sy Scale along the y axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
* @param kx Shear along the x axis.
|
||||
* @param ky Shear along the y axis.
|
||||
**/
|
||||
void print(std::string text, float x, float y, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f, float ox = 0.0f, float oy = 0.0f, float kx = 0.0f, float ky = 0.0f);
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
*
|
||||
* @param character A character.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void print(char character, float x, float y);
|
||||
|
||||
/**
|
||||
* Returns the height of the font.
|
||||
**/
|
||||
float getHeight() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed string.
|
||||
*
|
||||
* @param line A line of text.
|
||||
**/
|
||||
int getWidth(const std::string &line);
|
||||
int getWidth(const char *line);
|
||||
|
||||
/**
|
||||
* Returns the width of the passed character.
|
||||
*
|
||||
* @param character A character.
|
||||
**/
|
||||
int getWidth(const char character);
|
||||
|
||||
/**
|
||||
* Returns the maximal width of a wrapped string
|
||||
* and optionally the number of lines
|
||||
*
|
||||
* @param text The input text
|
||||
* @param wrap The number of pixels to wrap at
|
||||
* @param max_width Optional output of the maximum width
|
||||
* Returns a vector with the lines.
|
||||
**/
|
||||
std::vector<std::string> getWrap(const std::string text, float wrap, int *max_width = 0);
|
||||
|
||||
/**
|
||||
* Sets the line height (which should be a number to multiply the font size by,
|
||||
* example: line height = 1.2 and size = 12 means that rendered line height = 12*1.2)
|
||||
* @param height The new line height.
|
||||
**/
|
||||
void setLineHeight(float height);
|
||||
|
||||
/**
|
||||
* Returns the line height.
|
||||
**/
|
||||
float getLineHeight() const;
|
||||
|
||||
/**
|
||||
* Sets the spacing modifier (changes the spacing between the characters the
|
||||
* same way that the line height does [multiplication]).
|
||||
* Note: The spacing must be set BEFORE the font is loaded to have any effect.
|
||||
* @param amount The amount of modification.
|
||||
**/
|
||||
void setSpacing(float amount);
|
||||
|
||||
/**
|
||||
* Returns the spacing modifier.
|
||||
**/
|
||||
float getSpacing() const;
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
private:
|
||||
|
||||
enum FontType
|
||||
{
|
||||
FONT_TRUETYPE = 1,
|
||||
FONT_IMAGE,
|
||||
FONT_UNKNOWN
|
||||
};
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
GLuint list;
|
||||
GLuint texture;
|
||||
int spacing;
|
||||
};
|
||||
|
||||
love::font::Rasterizer *rasterizer;
|
||||
|
||||
int height;
|
||||
float lineHeight;
|
||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||
std::vector<GLuint> textures; // vector of packed textures
|
||||
std::map<int, Glyph *> glyphs; // maps glyphs to display lists
|
||||
FontType type;
|
||||
Image::Filter filter;
|
||||
|
||||
static const int TEXTURE_WIDTH = 512;
|
||||
static const int TEXTURE_HEIGHT = 512;
|
||||
static const int TEXTURE_PADDING = 1;
|
||||
|
||||
int texture_x, texture_y;
|
||||
int rowHeight;
|
||||
|
||||
void createTexture();
|
||||
Glyph *addGlyph(int glyph);
|
||||
}; // Font
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
|
||||
+12981
-12981
File diff suppressed because it is too large
Load Diff
+12452
-12452
File diff suppressed because it is too large
Load Diff
+1156
-1156
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,432 +1,432 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image::Filter Image::defaultFilter;
|
||||
|
||||
Image::Image(love::image::ImageData *data)
|
||||
: width((float)(data->getWidth()))
|
||||
, height((float)(data->getHeight()))
|
||||
, texture(0)
|
||||
{
|
||||
data->retain();
|
||||
this->data = data;
|
||||
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = height;
|
||||
vertices[2].x = width;
|
||||
vertices[2].y = height;
|
||||
vertices[3].x = width;
|
||||
vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = 0;
|
||||
vertices[0].t = 0;
|
||||
vertices[1].s = 0;
|
||||
vertices[1].t = 1;
|
||||
vertices[2].s = 1;
|
||||
vertices[2].t = 1;
|
||||
vertices[3].s = 1;
|
||||
vertices[3].t = 0;
|
||||
|
||||
settings.filter = defaultFilter;
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if (data != 0)
|
||||
data->release();
|
||||
unload();
|
||||
}
|
||||
|
||||
float Image::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float Image::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
const vertex *Image::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
love::image::ImageData *Image::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Image::getRectangleVertices(int x, int y, int w, int h, vertex *vertices) const
|
||||
{
|
||||
// Check upper.
|
||||
x = (x+w > (int)width) ? (int)width-w : x;
|
||||
y = (y+h > (int)height) ? (int)height-h : y;
|
||||
|
||||
// Check lower.
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = (float)h;
|
||||
vertices[2].x = (float)w;
|
||||
vertices[2].y = (float)h;
|
||||
vertices[3].x = (float)w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
float tx = (float)x/width;
|
||||
float ty = (float)y/height;
|
||||
float tw = (float)w/width;
|
||||
float th = (float)h/height;
|
||||
|
||||
vertices[0].s = tx;
|
||||
vertices[0].t = ty;
|
||||
vertices[1].s = tx;
|
||||
vertices[1].t = ty+th;
|
||||
vertices[2].s = tx+tw;
|
||||
vertices[2].t = ty+th;
|
||||
vertices[3].s = tx+tw;
|
||||
vertices[3].t = ty;
|
||||
}
|
||||
|
||||
void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, vertices);
|
||||
}
|
||||
|
||||
void Image::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
const vertex *v = quad->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, v);
|
||||
}
|
||||
|
||||
void Image::setFilter(const Image::Filter &f)
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
gmin = gmag = 0; // so that they're not used uninitialized
|
||||
|
||||
switch (f.min)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmin = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmin = GL_NEAREST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (f.mag)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmag = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmag = GL_NEAREST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
}
|
||||
|
||||
Image::Filter Image::getFilter() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gmin, gmag;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void Image::setWrap(Image::Wrap w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch (w.s)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gs = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (w.t)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gt = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
}
|
||||
|
||||
Image::Wrap Image::getWrap() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gs, gt;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >);
|
||||
|
||||
Wrap w;
|
||||
|
||||
switch (gs)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.s = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.s = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gt)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.t = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.t = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
void Image::bind() const
|
||||
{
|
||||
if (texture == 0)
|
||||
return;
|
||||
|
||||
bindTexture(texture);
|
||||
}
|
||||
|
||||
bool Image::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void Image::unload()
|
||||
{
|
||||
return unloadVolatile();
|
||||
}
|
||||
|
||||
bool Image::loadVolatile()
|
||||
{
|
||||
if (hasNpot())
|
||||
return loadVolatileNPOT();
|
||||
else
|
||||
return loadVolatilePOT();
|
||||
}
|
||||
|
||||
bool Image::loadVolatilePOT()
|
||||
{
|
||||
glGenTextures(1,(GLuint *)&texture);
|
||||
bindTexture(texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
float p2width = next_p2(width);
|
||||
float p2height = next_p2(height);
|
||||
float s = width/p2width;
|
||||
float t = height/p2height;
|
||||
|
||||
vertices[1].t = t;
|
||||
vertices[2].t = t;
|
||||
vertices[2].s = s;
|
||||
vertices[3].s = s;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
(GLsizei)p2width,
|
||||
(GLsizei)p2height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
0);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
setFilter(settings.filter);
|
||||
setWrap(settings.wrap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Image::loadVolatileNPOT()
|
||||
{
|
||||
glGenTextures(1,(GLuint *)&texture);
|
||||
bindTexture(texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
setFilter(settings.filter);
|
||||
setWrap(settings.wrap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Image::unloadVolatile()
|
||||
{
|
||||
settings.filter = getFilter();
|
||||
settings.wrap = getWrap();
|
||||
// Delete the hardware texture.
|
||||
if (texture != 0)
|
||||
{
|
||||
deleteTexture(texture);
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawv(const Matrix &t, const vertex *v) const
|
||||
{
|
||||
bind();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
bool Image::hasNpot()
|
||||
{
|
||||
return GLEE_ARB_texture_non_power_of_two != 0;
|
||||
}
|
||||
|
||||
void Image::setDefaultFilter(const Image::Filter &f)
|
||||
{
|
||||
defaultFilter = f;
|
||||
}
|
||||
|
||||
const Image::Filter &Image::getDefaultFilter()
|
||||
{
|
||||
return defaultFilter;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image::Filter Image::defaultFilter;
|
||||
|
||||
Image::Image(love::image::ImageData *data)
|
||||
: width((float)(data->getWidth()))
|
||||
, height((float)(data->getHeight()))
|
||||
, texture(0)
|
||||
{
|
||||
data->retain();
|
||||
this->data = data;
|
||||
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = height;
|
||||
vertices[2].x = width;
|
||||
vertices[2].y = height;
|
||||
vertices[3].x = width;
|
||||
vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = 0;
|
||||
vertices[0].t = 0;
|
||||
vertices[1].s = 0;
|
||||
vertices[1].t = 1;
|
||||
vertices[2].s = 1;
|
||||
vertices[2].t = 1;
|
||||
vertices[3].s = 1;
|
||||
vertices[3].t = 0;
|
||||
|
||||
settings.filter = defaultFilter;
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if (data != 0)
|
||||
data->release();
|
||||
unload();
|
||||
}
|
||||
|
||||
float Image::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float Image::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
const vertex *Image::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
love::image::ImageData *Image::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Image::getRectangleVertices(int x, int y, int w, int h, vertex *vertices) const
|
||||
{
|
||||
// Check upper.
|
||||
x = (x+w > (int)width) ? (int)width-w : x;
|
||||
y = (y+h > (int)height) ? (int)height-h : y;
|
||||
|
||||
// Check lower.
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = (float)h;
|
||||
vertices[2].x = (float)w;
|
||||
vertices[2].y = (float)h;
|
||||
vertices[3].x = (float)w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
float tx = (float)x/width;
|
||||
float ty = (float)y/height;
|
||||
float tw = (float)w/width;
|
||||
float th = (float)h/height;
|
||||
|
||||
vertices[0].s = tx;
|
||||
vertices[0].t = ty;
|
||||
vertices[1].s = tx;
|
||||
vertices[1].t = ty+th;
|
||||
vertices[2].s = tx+tw;
|
||||
vertices[2].t = ty+th;
|
||||
vertices[3].s = tx+tw;
|
||||
vertices[3].t = ty;
|
||||
}
|
||||
|
||||
void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, vertices);
|
||||
}
|
||||
|
||||
void Image::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
const vertex *v = quad->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, v);
|
||||
}
|
||||
|
||||
void Image::setFilter(const Image::Filter &f)
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
gmin = gmag = 0; // so that they're not used uninitialized
|
||||
|
||||
switch (f.min)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmin = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmin = GL_NEAREST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (f.mag)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmag = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmag = GL_NEAREST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
}
|
||||
|
||||
Image::Filter Image::getFilter() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gmin, gmag;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void Image::setWrap(Image::Wrap w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch (w.s)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gs = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (w.t)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gt = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
}
|
||||
|
||||
Image::Wrap Image::getWrap() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gs, gt;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >);
|
||||
|
||||
Wrap w;
|
||||
|
||||
switch (gs)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.s = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.s = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gt)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.t = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.t = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
void Image::bind() const
|
||||
{
|
||||
if (texture == 0)
|
||||
return;
|
||||
|
||||
bindTexture(texture);
|
||||
}
|
||||
|
||||
bool Image::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void Image::unload()
|
||||
{
|
||||
return unloadVolatile();
|
||||
}
|
||||
|
||||
bool Image::loadVolatile()
|
||||
{
|
||||
if (hasNpot())
|
||||
return loadVolatileNPOT();
|
||||
else
|
||||
return loadVolatilePOT();
|
||||
}
|
||||
|
||||
bool Image::loadVolatilePOT()
|
||||
{
|
||||
glGenTextures(1,(GLuint *)&texture);
|
||||
bindTexture(texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
float p2width = next_p2(width);
|
||||
float p2height = next_p2(height);
|
||||
float s = width/p2width;
|
||||
float t = height/p2height;
|
||||
|
||||
vertices[1].t = t;
|
||||
vertices[2].t = t;
|
||||
vertices[2].s = s;
|
||||
vertices[3].s = s;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
(GLsizei)p2width,
|
||||
(GLsizei)p2height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
0);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
setFilter(settings.filter);
|
||||
setWrap(settings.wrap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Image::loadVolatileNPOT()
|
||||
{
|
||||
glGenTextures(1,(GLuint *)&texture);
|
||||
bindTexture(texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
setFilter(settings.filter);
|
||||
setWrap(settings.wrap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Image::unloadVolatile()
|
||||
{
|
||||
settings.filter = getFilter();
|
||||
settings.wrap = getWrap();
|
||||
// Delete the hardware texture.
|
||||
if (texture != 0)
|
||||
{
|
||||
deleteTexture(texture);
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawv(const Matrix &t, const vertex *v) const
|
||||
{
|
||||
bind();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
bool Image::hasNpot()
|
||||
{
|
||||
return GLEE_ARB_texture_non_power_of_two != 0;
|
||||
}
|
||||
|
||||
void Image::setDefaultFilter(const Image::Filter &f)
|
||||
{
|
||||
defaultFilter = f;
|
||||
}
|
||||
|
||||
const Image::Filter &Image::getDefaultFilter()
|
||||
{
|
||||
return defaultFilter;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
+165
-165
@@ -1,165 +1,165 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Matrix.h"
|
||||
#include "common/math.h"
|
||||
#include "common/config.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "graphics/Image.h"
|
||||
|
||||
#include "OpenGL.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A drawable image based on OpenGL-textures. This class takes ImageData
|
||||
* objects and create textures on the GPU for fast drawing.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Image : public love::graphics::Image
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Image. Not that anything is ready to use
|
||||
* before load is called.
|
||||
*
|
||||
* @param file The file from which to load the image.
|
||||
**/
|
||||
Image(love::image::ImageData *data);
|
||||
|
||||
/**
|
||||
* Destructor. Deletes the hardware texture and other resources.
|
||||
**/
|
||||
virtual ~Image();
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
const vertex *getVertices() const;
|
||||
|
||||
love::image::ImageData *getData() const;
|
||||
|
||||
/**
|
||||
* Generate vertices according to a subimage.
|
||||
*
|
||||
* Note: out-of-range values will be clamped.
|
||||
* Note: the vertex colors will not be changed.
|
||||
*
|
||||
* @param x The top-left corner of the subimage along the x-axis.
|
||||
* @param y The top-left corner of the subimage along the y-axis.
|
||||
* @param w The width of the subimage.
|
||||
* @param h The height of the subimage.
|
||||
* @param vertices A vertex array of size four.
|
||||
**/
|
||||
void getRectangleVertices(int x, int y, int w, int h, vertex *vertices) const;
|
||||
|
||||
/**
|
||||
* @copydoc Drawable::draw()
|
||||
**/
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* @copydoc DrawQable::drawq()
|
||||
**/
|
||||
void drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* Sets the filter mode.
|
||||
*
|
||||
* @param mode The filter mode.
|
||||
**/
|
||||
void setFilter(const Image::Filter &f);
|
||||
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(Image::Wrap r);
|
||||
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
void bind() const;
|
||||
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
static bool hasNpot();
|
||||
|
||||
// The default filter.
|
||||
static void setDefaultFilter(const Image::Filter &f);
|
||||
static const Image::Filter &getDefaultFilter();
|
||||
|
||||
private:
|
||||
|
||||
void drawv(const Matrix &t, const vertex *v) const;
|
||||
|
||||
friend class PixelEffect;
|
||||
GLuint getTextureName() const
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
// The ImageData from which the texture is created.
|
||||
love::image::ImageData *data;
|
||||
|
||||
// Width and height of the hardware texture.
|
||||
float width, height;
|
||||
|
||||
// OpenGL texture identifier.
|
||||
GLuint texture;
|
||||
|
||||
// The source vertices of the image.
|
||||
vertex vertices[4];
|
||||
|
||||
// The settings we need to save when reloading.
|
||||
struct
|
||||
{
|
||||
Image::Filter filter;
|
||||
Image::Wrap wrap;
|
||||
} settings;
|
||||
|
||||
bool loadVolatilePOT();
|
||||
bool loadVolatileNPOT();
|
||||
|
||||
// The default image filter
|
||||
static Image::Filter defaultFilter;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Matrix.h"
|
||||
#include "common/math.h"
|
||||
#include "common/config.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "graphics/Image.h"
|
||||
|
||||
#include "OpenGL.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A drawable image based on OpenGL-textures. This class takes ImageData
|
||||
* objects and create textures on the GPU for fast drawing.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Image : public love::graphics::Image
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Image. Not that anything is ready to use
|
||||
* before load is called.
|
||||
*
|
||||
* @param file The file from which to load the image.
|
||||
**/
|
||||
Image(love::image::ImageData *data);
|
||||
|
||||
/**
|
||||
* Destructor. Deletes the hardware texture and other resources.
|
||||
**/
|
||||
virtual ~Image();
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
const vertex *getVertices() const;
|
||||
|
||||
love::image::ImageData *getData() const;
|
||||
|
||||
/**
|
||||
* Generate vertices according to a subimage.
|
||||
*
|
||||
* Note: out-of-range values will be clamped.
|
||||
* Note: the vertex colors will not be changed.
|
||||
*
|
||||
* @param x The top-left corner of the subimage along the x-axis.
|
||||
* @param y The top-left corner of the subimage along the y-axis.
|
||||
* @param w The width of the subimage.
|
||||
* @param h The height of the subimage.
|
||||
* @param vertices A vertex array of size four.
|
||||
**/
|
||||
void getRectangleVertices(int x, int y, int w, int h, vertex *vertices) const;
|
||||
|
||||
/**
|
||||
* @copydoc Drawable::draw()
|
||||
**/
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* @copydoc DrawQable::drawq()
|
||||
**/
|
||||
void drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* Sets the filter mode.
|
||||
*
|
||||
* @param mode The filter mode.
|
||||
**/
|
||||
void setFilter(const Image::Filter &f);
|
||||
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(Image::Wrap r);
|
||||
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
void bind() const;
|
||||
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
static bool hasNpot();
|
||||
|
||||
// The default filter.
|
||||
static void setDefaultFilter(const Image::Filter &f);
|
||||
static const Image::Filter &getDefaultFilter();
|
||||
|
||||
private:
|
||||
|
||||
void drawv(const Matrix &t, const vertex *v) const;
|
||||
|
||||
friend class PixelEffect;
|
||||
GLuint getTextureName() const
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
// The ImageData from which the texture is created.
|
||||
love::image::ImageData *data;
|
||||
|
||||
// Width and height of the hardware texture.
|
||||
float width, height;
|
||||
|
||||
// OpenGL texture identifier.
|
||||
GLuint texture;
|
||||
|
||||
// The source vertices of the image.
|
||||
vertex vertices[4];
|
||||
|
||||
// The settings we need to save when reloading.
|
||||
struct
|
||||
{
|
||||
Image::Filter filter;
|
||||
Image::Wrap wrap;
|
||||
} settings;
|
||||
|
||||
bool loadVolatilePOT();
|
||||
bool loadVolatileNPOT();
|
||||
|
||||
// The default image filter
|
||||
static Image::Filter defaultFilter;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "OpenGL.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
static GLuint boundTexture = 0;
|
||||
|
||||
void resetBoundTexture()
|
||||
{
|
||||
// OpenGL might not be initialized yet, so we can't do a real reset
|
||||
boundTexture = 0;
|
||||
}
|
||||
|
||||
void bindTexture(GLuint texture, bool override)
|
||||
{
|
||||
if (texture != boundTexture || texture == 0 || override)
|
||||
{
|
||||
boundTexture = texture;
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
}
|
||||
}
|
||||
|
||||
void deleteTexture(GLuint texture)
|
||||
{
|
||||
if (texture == boundTexture)
|
||||
boundTexture = 0;
|
||||
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "OpenGL.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
static GLuint boundTexture = 0;
|
||||
|
||||
void resetBoundTexture()
|
||||
{
|
||||
// OpenGL might not be initialized yet, so we can't do a real reset
|
||||
boundTexture = 0;
|
||||
}
|
||||
|
||||
void bindTexture(GLuint texture, bool override)
|
||||
{
|
||||
if (texture != boundTexture || texture == 0 || override)
|
||||
{
|
||||
boundTexture = texture;
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
}
|
||||
}
|
||||
|
||||
void deleteTexture(GLuint texture)
|
||||
{
|
||||
if (texture == boundTexture)
|
||||
boundTexture = 0;
|
||||
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_COMMON_OPENGL_H
|
||||
#define LOVE_COMMON_OPENGL_H
|
||||
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// resets the stored bound texture id
|
||||
void resetBoundTexture();
|
||||
|
||||
/**
|
||||
* Helper for binding an OpenGL texture.
|
||||
* Makes sure we aren't redundantly binding textures.
|
||||
* @param texture The texture to bind.
|
||||
* @param override Overrides the checks to guarantee texture bind
|
||||
**/
|
||||
void bindTexture(GLuint texture, bool override = false);
|
||||
|
||||
/**
|
||||
* Helper for deleting an OpenGL texture.
|
||||
* Cleans up if the texture is currently bound.
|
||||
* @param texture The texture to delete.
|
||||
**/
|
||||
void deleteTexture(GLuint texture);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_COMMON_OPENGL_H
|
||||
#define LOVE_COMMON_OPENGL_H
|
||||
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// resets the stored bound texture id
|
||||
void resetBoundTexture();
|
||||
|
||||
/**
|
||||
* Helper for binding an OpenGL texture.
|
||||
* Makes sure we aren't redundantly binding textures.
|
||||
* @param texture The texture to bind.
|
||||
* @param override Overrides the checks to guarantee texture bind
|
||||
**/
|
||||
void bindTexture(GLuint texture, bool override = false);
|
||||
|
||||
/**
|
||||
* Helper for deleting an OpenGL texture.
|
||||
* Cleans up if the texture is currently bound.
|
||||
* @param texture The texture to delete.
|
||||
**/
|
||||
void deleteTexture(GLuint texture);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,448 +1,448 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Vector.h"
|
||||
#include "graphics/Drawable.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "Image.h"
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Represents a single particle.
|
||||
struct particle
|
||||
{
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
float position[2];
|
||||
float direction;
|
||||
|
||||
// Particles gravitate towards this point.
|
||||
love::Vector origin;
|
||||
|
||||
love::Vector speed;
|
||||
float gravity;
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
float size;
|
||||
float sizeOffset;
|
||||
float sizeIntervalSize;
|
||||
|
||||
float rotation;
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
|
||||
Colorf color;
|
||||
};
|
||||
|
||||
/**
|
||||
* A class for creating, moving and drawing particles.
|
||||
* A big thanks to bobthebloke.org
|
||||
**/
|
||||
class ParticleSystem : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a particle system with the specified buffersize and sprite.
|
||||
**/
|
||||
ParticleSystem(Image *sprite, unsigned int buffer);
|
||||
|
||||
/**
|
||||
* Deletes any allocated memory.
|
||||
**/
|
||||
virtual ~ParticleSystem();
|
||||
|
||||
/**
|
||||
* Sets the sprite used in the particle system.
|
||||
* @param sprite The new sprite.
|
||||
**/
|
||||
void setSprite(Image *image);
|
||||
|
||||
/**
|
||||
* Clears the current buffer and allocates the appropriate amount of space for the buffer.
|
||||
* @param size The new buffer size.
|
||||
**/
|
||||
void setBufferSize(unsigned int size);
|
||||
|
||||
/**
|
||||
* Sets the emission rate.
|
||||
* @param rate The amount of particles per second.
|
||||
**/
|
||||
void setEmissionRate(int rate);
|
||||
|
||||
/**
|
||||
* Sets the lifetime of the particle emitter (-1 means eternal)
|
||||
* @param life The lifetime (in seconds).
|
||||
**/
|
||||
void setLifetime(float life);
|
||||
|
||||
/**
|
||||
* Sets the life range of the particles.
|
||||
* @param lifeMin The minimum life.
|
||||
* @param lifeMax The maximum life (if 0, then becomes the same as minimum life).
|
||||
**/
|
||||
void setParticleLife(float min, float max = 0);
|
||||
|
||||
/**
|
||||
* Sets the position of the center of the emitter and the direction (if set to relative).
|
||||
* Used to move the emitter without changing the position of already existing particles.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the direction and the spread of the particle emitter.
|
||||
* @param direction The direction (in degrees).
|
||||
**/
|
||||
void setDirection(float direction);
|
||||
|
||||
/**
|
||||
* Sets the spread of the particle emitter.
|
||||
* @param spread The spread (in degrees).
|
||||
**/
|
||||
void setSpread(float spread);
|
||||
|
||||
/**
|
||||
* Sets whether the direction should be relative to the particle emitters movement. Used in conjunction with setPosition.
|
||||
* @param relative Whether to have relative direction.
|
||||
**/
|
||||
void setRelativeDirection(bool relative);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param speed The speed.
|
||||
**/
|
||||
void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param min The minimum speed.
|
||||
* @param max The maximum speed.
|
||||
**/
|
||||
void setSpeed(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param gravity The amount of gravity.
|
||||
**/
|
||||
void setGravity(float gravity);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param min The minimum gravity.
|
||||
* @param max The maximum gravity.
|
||||
**/
|
||||
void setGravity(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite (1.0 being the default size).
|
||||
* @param size The size of the sprite.
|
||||
**/
|
||||
void setSize(float size);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite upon creation and upon death (1.0 being the default size) and any variation.
|
||||
* @param newSizes Array of sizes
|
||||
* @param variation The amount of variation on the starting size (0 being no variation and 1.0 a random size between start and end).
|
||||
**/
|
||||
void setSize(const std::vector<float> &newSizes, float variation = 0.0f);
|
||||
|
||||
/**
|
||||
* Sets the amount of variation to the sprite's beginning size (0 being no variation and 1.0 a random size between start and end).
|
||||
* @param variation The amount of variation.
|
||||
**/
|
||||
void setSizeVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with.
|
||||
* @param rotation The amount of rotation.
|
||||
**/
|
||||
void setRotation(float rotation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with (a random value between min and max).
|
||||
* @param min The minimum amount of rotation.
|
||||
* @param max The maximum amount of rotation.
|
||||
**/
|
||||
void setRotation(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite.
|
||||
* @param spin The spin of the sprite (in degrees).
|
||||
**/
|
||||
void setSpin(float spin);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
**/
|
||||
void setSpin(float start, float end);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death and the variation.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
* @param variation The variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
**/
|
||||
void setSpin(float start, float end, float variation);
|
||||
|
||||
/**
|
||||
* Sets the variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
* @param variation The variation in degrees.
|
||||
**/
|
||||
void setSpinVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param color The color.
|
||||
**/
|
||||
void setColor(const Color &color);
|
||||
|
||||
/**
|
||||
* Sets the particles' offsets for rotation.
|
||||
* @param x The x offset.
|
||||
* @param y The y offset.
|
||||
**/
|
||||
void setOffset(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param newColors Array of colors
|
||||
**/
|
||||
void setColor(const std::vector<Color> &newColors);
|
||||
|
||||
/**
|
||||
* Returns the x-coordinate of the emitter's position.
|
||||
**/
|
||||
float getX() const;
|
||||
|
||||
/**
|
||||
* Returns the y-coordinate of the emitter's position.
|
||||
**/
|
||||
float getY() const;
|
||||
|
||||
/**
|
||||
* Returns the position of the emitter.
|
||||
**/
|
||||
const love::Vector &getPosition() const;
|
||||
|
||||
/**
|
||||
* Returns the direction of the emitter (in degrees).
|
||||
**/
|
||||
float getDirection() const;
|
||||
|
||||
/**
|
||||
* Returns the directional spread of the emitter (in degrees).
|
||||
**/
|
||||
float getSpread() const;
|
||||
|
||||
/**
|
||||
* Returns the X offset of the particles.
|
||||
**/
|
||||
float getOffsetX() const;
|
||||
|
||||
/**
|
||||
* Returns the Y offset of the particles.
|
||||
**/
|
||||
float getOffsetY() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of particles that are currently active in the system.
|
||||
**/
|
||||
int count() const;
|
||||
|
||||
/**
|
||||
* Starts/resumes the particle emitter.
|
||||
**/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Stops the particle emitter and resets.
|
||||
**/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Pauses the particle emitter.
|
||||
**/
|
||||
void pause();
|
||||
|
||||
/**
|
||||
* Resets the particle emitter.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Returns whether the particle emitter is active.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Returns whether the particle system is empty of particles or not.
|
||||
**/
|
||||
bool isEmpty() const;
|
||||
|
||||
/**
|
||||
* Returns whether the amount of particles has reached the buffer limit or not.
|
||||
**/
|
||||
bool isFull() const;
|
||||
|
||||
/**
|
||||
* Draws the particle emitter at the specified position.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* Updates the particle system.
|
||||
* @param dt Time since last update.
|
||||
**/
|
||||
void update(float dt);
|
||||
protected:
|
||||
|
||||
// The max amount of particles.
|
||||
unsigned int bufferSize;
|
||||
|
||||
// Pointer to the first particle.
|
||||
particle *pStart;
|
||||
|
||||
// Pointer to the next available free space.
|
||||
particle *pLast;
|
||||
|
||||
// Pointer to the end of the memory allocation.
|
||||
particle *pEnd;
|
||||
|
||||
// The sprite to be drawn.
|
||||
Image *sprite;
|
||||
|
||||
// Whether the particle emitter is active.
|
||||
bool active;
|
||||
|
||||
// The emission rate (particles/sec).
|
||||
int emissionRate;
|
||||
|
||||
// Used to determine when a particle should be emitted.
|
||||
float emitCounter;
|
||||
|
||||
// The relative position of the particle emitter.
|
||||
love::Vector position;
|
||||
|
||||
// The lifetime of the particle emitter (-1 means infinite) and the life it has left.
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
// The particle life.
|
||||
float particleLifeMin;
|
||||
float particleLifeMax;
|
||||
|
||||
// The direction (and spread) the particles will be emitted in. Measured in radians.
|
||||
float direction;
|
||||
float spread;
|
||||
|
||||
// Whether the direction should be relative to the emitter's movement.
|
||||
bool relative;
|
||||
|
||||
// The speed.
|
||||
float speedMin;
|
||||
float speedMax;
|
||||
|
||||
// Acceleration towards the bottom of the screen
|
||||
float gravityMin;
|
||||
float gravityMax;
|
||||
|
||||
// Acceleration towards the emitter's center
|
||||
float radialAccelerationMin;
|
||||
float radialAccelerationMax;
|
||||
|
||||
// Acceleration perpendicular to the particle's direction.
|
||||
float tangentialAccelerationMin;
|
||||
float tangentialAccelerationMax;
|
||||
|
||||
// Size.
|
||||
std::vector<float> sizes;
|
||||
float sizeVariation;
|
||||
|
||||
// Rotation
|
||||
float rotationMin;
|
||||
float rotationMax;
|
||||
|
||||
// Spin.
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
float spinVariation;
|
||||
|
||||
// Offsets
|
||||
float offsetX;
|
||||
float offsetY;
|
||||
|
||||
// Color.
|
||||
std::vector<Colorf> colors;
|
||||
|
||||
void add();
|
||||
void remove(particle *p);
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Vector.h"
|
||||
#include "graphics/Drawable.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "Image.h"
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Represents a single particle.
|
||||
struct particle
|
||||
{
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
float position[2];
|
||||
float direction;
|
||||
|
||||
// Particles gravitate towards this point.
|
||||
love::Vector origin;
|
||||
|
||||
love::Vector speed;
|
||||
float gravity;
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
float size;
|
||||
float sizeOffset;
|
||||
float sizeIntervalSize;
|
||||
|
||||
float rotation;
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
|
||||
Colorf color;
|
||||
};
|
||||
|
||||
/**
|
||||
* A class for creating, moving and drawing particles.
|
||||
* A big thanks to bobthebloke.org
|
||||
**/
|
||||
class ParticleSystem : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a particle system with the specified buffersize and sprite.
|
||||
**/
|
||||
ParticleSystem(Image *sprite, unsigned int buffer);
|
||||
|
||||
/**
|
||||
* Deletes any allocated memory.
|
||||
**/
|
||||
virtual ~ParticleSystem();
|
||||
|
||||
/**
|
||||
* Sets the sprite used in the particle system.
|
||||
* @param sprite The new sprite.
|
||||
**/
|
||||
void setSprite(Image *image);
|
||||
|
||||
/**
|
||||
* Clears the current buffer and allocates the appropriate amount of space for the buffer.
|
||||
* @param size The new buffer size.
|
||||
**/
|
||||
void setBufferSize(unsigned int size);
|
||||
|
||||
/**
|
||||
* Sets the emission rate.
|
||||
* @param rate The amount of particles per second.
|
||||
**/
|
||||
void setEmissionRate(int rate);
|
||||
|
||||
/**
|
||||
* Sets the lifetime of the particle emitter (-1 means eternal)
|
||||
* @param life The lifetime (in seconds).
|
||||
**/
|
||||
void setLifetime(float life);
|
||||
|
||||
/**
|
||||
* Sets the life range of the particles.
|
||||
* @param lifeMin The minimum life.
|
||||
* @param lifeMax The maximum life (if 0, then becomes the same as minimum life).
|
||||
**/
|
||||
void setParticleLife(float min, float max = 0);
|
||||
|
||||
/**
|
||||
* Sets the position of the center of the emitter and the direction (if set to relative).
|
||||
* Used to move the emitter without changing the position of already existing particles.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the direction and the spread of the particle emitter.
|
||||
* @param direction The direction (in degrees).
|
||||
**/
|
||||
void setDirection(float direction);
|
||||
|
||||
/**
|
||||
* Sets the spread of the particle emitter.
|
||||
* @param spread The spread (in degrees).
|
||||
**/
|
||||
void setSpread(float spread);
|
||||
|
||||
/**
|
||||
* Sets whether the direction should be relative to the particle emitters movement. Used in conjunction with setPosition.
|
||||
* @param relative Whether to have relative direction.
|
||||
**/
|
||||
void setRelativeDirection(bool relative);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param speed The speed.
|
||||
**/
|
||||
void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param min The minimum speed.
|
||||
* @param max The maximum speed.
|
||||
**/
|
||||
void setSpeed(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param gravity The amount of gravity.
|
||||
**/
|
||||
void setGravity(float gravity);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param min The minimum gravity.
|
||||
* @param max The maximum gravity.
|
||||
**/
|
||||
void setGravity(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite (1.0 being the default size).
|
||||
* @param size The size of the sprite.
|
||||
**/
|
||||
void setSize(float size);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite upon creation and upon death (1.0 being the default size) and any variation.
|
||||
* @param newSizes Array of sizes
|
||||
* @param variation The amount of variation on the starting size (0 being no variation and 1.0 a random size between start and end).
|
||||
**/
|
||||
void setSize(const std::vector<float> &newSizes, float variation = 0.0f);
|
||||
|
||||
/**
|
||||
* Sets the amount of variation to the sprite's beginning size (0 being no variation and 1.0 a random size between start and end).
|
||||
* @param variation The amount of variation.
|
||||
**/
|
||||
void setSizeVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with.
|
||||
* @param rotation The amount of rotation.
|
||||
**/
|
||||
void setRotation(float rotation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with (a random value between min and max).
|
||||
* @param min The minimum amount of rotation.
|
||||
* @param max The maximum amount of rotation.
|
||||
**/
|
||||
void setRotation(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite.
|
||||
* @param spin The spin of the sprite (in degrees).
|
||||
**/
|
||||
void setSpin(float spin);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
**/
|
||||
void setSpin(float start, float end);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death and the variation.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
* @param variation The variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
**/
|
||||
void setSpin(float start, float end, float variation);
|
||||
|
||||
/**
|
||||
* Sets the variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
* @param variation The variation in degrees.
|
||||
**/
|
||||
void setSpinVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param color The color.
|
||||
**/
|
||||
void setColor(const Color &color);
|
||||
|
||||
/**
|
||||
* Sets the particles' offsets for rotation.
|
||||
* @param x The x offset.
|
||||
* @param y The y offset.
|
||||
**/
|
||||
void setOffset(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param newColors Array of colors
|
||||
**/
|
||||
void setColor(const std::vector<Color> &newColors);
|
||||
|
||||
/**
|
||||
* Returns the x-coordinate of the emitter's position.
|
||||
**/
|
||||
float getX() const;
|
||||
|
||||
/**
|
||||
* Returns the y-coordinate of the emitter's position.
|
||||
**/
|
||||
float getY() const;
|
||||
|
||||
/**
|
||||
* Returns the position of the emitter.
|
||||
**/
|
||||
const love::Vector &getPosition() const;
|
||||
|
||||
/**
|
||||
* Returns the direction of the emitter (in degrees).
|
||||
**/
|
||||
float getDirection() const;
|
||||
|
||||
/**
|
||||
* Returns the directional spread of the emitter (in degrees).
|
||||
**/
|
||||
float getSpread() const;
|
||||
|
||||
/**
|
||||
* Returns the X offset of the particles.
|
||||
**/
|
||||
float getOffsetX() const;
|
||||
|
||||
/**
|
||||
* Returns the Y offset of the particles.
|
||||
**/
|
||||
float getOffsetY() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of particles that are currently active in the system.
|
||||
**/
|
||||
int count() const;
|
||||
|
||||
/**
|
||||
* Starts/resumes the particle emitter.
|
||||
**/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Stops the particle emitter and resets.
|
||||
**/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Pauses the particle emitter.
|
||||
**/
|
||||
void pause();
|
||||
|
||||
/**
|
||||
* Resets the particle emitter.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Returns whether the particle emitter is active.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Returns whether the particle system is empty of particles or not.
|
||||
**/
|
||||
bool isEmpty() const;
|
||||
|
||||
/**
|
||||
* Returns whether the amount of particles has reached the buffer limit or not.
|
||||
**/
|
||||
bool isFull() const;
|
||||
|
||||
/**
|
||||
* Draws the particle emitter at the specified position.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
/**
|
||||
* Updates the particle system.
|
||||
* @param dt Time since last update.
|
||||
**/
|
||||
void update(float dt);
|
||||
protected:
|
||||
|
||||
// The max amount of particles.
|
||||
unsigned int bufferSize;
|
||||
|
||||
// Pointer to the first particle.
|
||||
particle *pStart;
|
||||
|
||||
// Pointer to the next available free space.
|
||||
particle *pLast;
|
||||
|
||||
// Pointer to the end of the memory allocation.
|
||||
particle *pEnd;
|
||||
|
||||
// The sprite to be drawn.
|
||||
Image *sprite;
|
||||
|
||||
// Whether the particle emitter is active.
|
||||
bool active;
|
||||
|
||||
// The emission rate (particles/sec).
|
||||
int emissionRate;
|
||||
|
||||
// Used to determine when a particle should be emitted.
|
||||
float emitCounter;
|
||||
|
||||
// The relative position of the particle emitter.
|
||||
love::Vector position;
|
||||
|
||||
// The lifetime of the particle emitter (-1 means infinite) and the life it has left.
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
// The particle life.
|
||||
float particleLifeMin;
|
||||
float particleLifeMax;
|
||||
|
||||
// The direction (and spread) the particles will be emitted in. Measured in radians.
|
||||
float direction;
|
||||
float spread;
|
||||
|
||||
// Whether the direction should be relative to the emitter's movement.
|
||||
bool relative;
|
||||
|
||||
// The speed.
|
||||
float speedMin;
|
||||
float speedMax;
|
||||
|
||||
// Acceleration towards the bottom of the screen
|
||||
float gravityMin;
|
||||
float gravityMax;
|
||||
|
||||
// Acceleration towards the emitter's center
|
||||
float radialAccelerationMin;
|
||||
float radialAccelerationMax;
|
||||
|
||||
// Acceleration perpendicular to the particle's direction.
|
||||
float tangentialAccelerationMin;
|
||||
float tangentialAccelerationMax;
|
||||
|
||||
// Size.
|
||||
std::vector<float> sizes;
|
||||
float sizeVariation;
|
||||
|
||||
// Rotation
|
||||
float rotationMin;
|
||||
float rotationMax;
|
||||
|
||||
// Spin.
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
float spinVariation;
|
||||
|
||||
// Offsets
|
||||
float offsetX;
|
||||
float offsetY;
|
||||
|
||||
// Color.
|
||||
std::vector<Colorf> colors;
|
||||
|
||||
void add();
|
||||
void remove(particle *p);
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
|
||||
@@ -1,328 +1,328 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PixelEffect.h"
|
||||
#include "GLee.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
// temporarily attaches a shader program (for setting uniforms, etc)
|
||||
// reattaches the originally active program when destroyed
|
||||
struct TemporaryAttacher
|
||||
{
|
||||
TemporaryAttacher(love::graphics::opengl::PixelEffect *sp) : s(sp)
|
||||
{
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
|
||||
s->attach();
|
||||
}
|
||||
~TemporaryAttacher()
|
||||
{
|
||||
glUseProgram(activeProgram);
|
||||
}
|
||||
love::graphics::opengl::PixelEffect *s;
|
||||
GLint activeProgram;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
PixelEffect *PixelEffect::current = NULL;
|
||||
|
||||
std::map<std::string, GLint> PixelEffect::_texture_unit_pool;
|
||||
GLint PixelEffect::_current_texture_unit = 0;
|
||||
GLint PixelEffect::_max_texture_units = 0;
|
||||
|
||||
GLint PixelEffect::getTextureUnit(const std::string &name)
|
||||
{
|
||||
std::map<std::string, GLint>::const_iterator it = _texture_unit_pool.find(name);
|
||||
|
||||
if (it != _texture_unit_pool.end())
|
||||
return it->second;
|
||||
|
||||
if (++_current_texture_unit >= _max_texture_units)
|
||||
throw love::Exception("No more texture units available");
|
||||
|
||||
_texture_unit_pool[name] = _current_texture_unit;
|
||||
return _current_texture_unit;
|
||||
}
|
||||
|
||||
PixelEffect::PixelEffect(const std::string &code)
|
||||
: _program(0)
|
||||
, _code(code)
|
||||
{
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &_max_texture_units);
|
||||
loadVolatile();
|
||||
}
|
||||
|
||||
bool PixelEffect::loadVolatile()
|
||||
{
|
||||
_program = glCreateProgram();
|
||||
// should only fail if this is called between a glBegin()/glEnd() pair
|
||||
if (_program == 0)
|
||||
throw love::Exception("Cannot create shader program object.");
|
||||
|
||||
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
// should only fail if this is called between a glBegin()/glEnd() pair
|
||||
if (shader == 0)
|
||||
{
|
||||
glDeleteProgram(_program);
|
||||
throw love::Exception("Cannot create shader object.");
|
||||
}
|
||||
|
||||
// compile fragment shader code
|
||||
const char *src = _code.c_str();
|
||||
GLint strlen = _code.length();
|
||||
glShaderSource(shader, 1, (const GLchar **)&src, &strlen);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint compile_ok;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_ok);
|
||||
if (GL_FALSE == compile_ok)
|
||||
{
|
||||
// get compiler error
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strlen);
|
||||
char *error_str = new char[strlen];
|
||||
glGetShaderInfoLog(shader, strlen, NULL, error_str);
|
||||
std::string tmp(error_str);
|
||||
|
||||
// cleanup before throw
|
||||
delete[] error_str;
|
||||
glDeleteShader(shader);
|
||||
glDeleteProgram(_program);
|
||||
|
||||
// XXX: errorlog may contain escape sequences.
|
||||
throw love::Exception("Cannot compile shader:\n%s", tmp.c_str());
|
||||
}
|
||||
|
||||
// link fragment shader
|
||||
GLint link_ok;
|
||||
glAttachShader(_program, shader);
|
||||
glLinkProgram(_program);
|
||||
glGetProgramiv(_program, GL_LINK_STATUS, &link_ok);
|
||||
if (GL_FALSE == link_ok)
|
||||
{
|
||||
// this should not happen if compiling is ok, but one can never be too careful
|
||||
// get linker error
|
||||
std::string tmp(getWarnings());
|
||||
|
||||
// cleanup before throw
|
||||
glDeleteShader(shader);
|
||||
glDeleteProgram(_program);
|
||||
throw love::Exception("Cannot compile shader:\n%s", tmp.c_str());
|
||||
}
|
||||
|
||||
glDeleteShader(shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
PixelEffect::~PixelEffect()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
void PixelEffect::unloadVolatile()
|
||||
{
|
||||
glDeleteProgram(_program);
|
||||
}
|
||||
|
||||
std::string PixelEffect::getGLSLVersion()
|
||||
{
|
||||
// GL_SHADING_LANGUAGE_VERSION is not available in OpenGL < 2.1.
|
||||
// Be very pessimistic about the GLSL version in that case.
|
||||
if (!GLEE_VERSION_2_1)
|
||||
return "0.0";
|
||||
|
||||
// the version string always begins with a version number of the format
|
||||
// major_number.minor_number
|
||||
// or
|
||||
// major_number.minor_number.release_number
|
||||
std::string versionString((const char *)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
size_t minorEndPos = versionString.find(" ");
|
||||
return versionString.substr(0, minorEndPos);
|
||||
}
|
||||
|
||||
|
||||
bool PixelEffect::isSupported()
|
||||
{
|
||||
return GLEE_VERSION_2_0 && GLEE_ARB_shader_objects && GLEE_ARB_fragment_shader && getGLSLVersion() >= "1.2";
|
||||
}
|
||||
|
||||
std::string PixelEffect::getWarnings() const
|
||||
{
|
||||
GLint strlen, nullpos;
|
||||
glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &strlen);
|
||||
char *temp_str = new char[strlen+1];
|
||||
// be extra sure that the error string will be 0-terminated
|
||||
memset(temp_str, '\0', strlen+1);
|
||||
glGetProgramInfoLog(_program, strlen, &nullpos, temp_str);
|
||||
temp_str[nullpos] = '\0';
|
||||
|
||||
std::string warnings(temp_str);
|
||||
delete[] temp_str;
|
||||
return warnings;
|
||||
}
|
||||
|
||||
void PixelEffect::attach()
|
||||
{
|
||||
glUseProgram(_program);
|
||||
current = this;
|
||||
}
|
||||
|
||||
void PixelEffect::detach()
|
||||
{
|
||||
glUseProgram(0);
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
void PixelEffect::sendFloat(const std::string &name, int size, const GLfloat *vec, int count)
|
||||
{
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
if (size < 1 || size > 4)
|
||||
{
|
||||
throw love::Exception("Invalid variable size: %d (expected 1-4).", size);
|
||||
}
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 4:
|
||||
glUniform4fv(location, count, vec);
|
||||
break;
|
||||
case 3:
|
||||
glUniform3fv(location, count, vec);
|
||||
break;
|
||||
case 2:
|
||||
glUniform2fv(location, count, vec);
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
glUniform1fv(location, count, vec);
|
||||
break;
|
||||
}
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
void PixelEffect::sendMatrix(const std::string &name, int size, const GLfloat *m, int count)
|
||||
{
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
if (size < 2 || size > 4)
|
||||
{
|
||||
throw love::Exception("Invalid matrix size: %dx%d "
|
||||
"(can only set 2x2, 3x3 or 4x4 matrices).", size,size);
|
||||
}
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 4:
|
||||
glUniformMatrix4fv(location, count, GL_FALSE, m);
|
||||
break;
|
||||
case 3:
|
||||
glUniformMatrix3fv(location, count, GL_FALSE, m);
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
glUniformMatrix2fv(location, count, GL_FALSE, m);
|
||||
break;
|
||||
}
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
void PixelEffect::sendImage(const std::string &name, const Image &image)
|
||||
{
|
||||
GLint texture_unit = getTextureUnit(name);
|
||||
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_unit);
|
||||
bindTexture(image.getTextureName(), true); // guarantee it gets bound
|
||||
glUniform1i(location, texture_unit);
|
||||
|
||||
// reset texture unit
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
void PixelEffect::sendCanvas(const std::string &name, const Canvas &canvas)
|
||||
{
|
||||
GLint texture_unit = getTextureUnit(name);
|
||||
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_unit);
|
||||
bindTexture(canvas.getTextureName(), true); // guarantee it gets bound
|
||||
glUniform1i(location, texture_unit);
|
||||
|
||||
// reset texture unit
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
GLint PixelEffect::getUniformLocation(const std::string &name)
|
||||
{
|
||||
std::map<std::string, GLint>::const_iterator it = _uniforms.find(name);
|
||||
if (it != _uniforms.end())
|
||||
return it->second;
|
||||
|
||||
GLint location = glGetUniformLocation(_program, name.c_str());
|
||||
if (location == -1)
|
||||
{
|
||||
throw love::Exception(
|
||||
"Cannot get location of shader variable `%s'.\n"
|
||||
"A common error is to define but not use the variable.", name.c_str());
|
||||
}
|
||||
|
||||
_uniforms[name] = location;
|
||||
return location;
|
||||
}
|
||||
|
||||
void PixelEffect::checkSetUniformError()
|
||||
{
|
||||
GLenum error_code = glGetError();
|
||||
if (GL_INVALID_OPERATION == error_code)
|
||||
{
|
||||
throw love::Exception(
|
||||
"Invalid operation:\n"
|
||||
"- Trying to send the wrong value type to shader variable, or\n"
|
||||
"- Trying to send array values with wrong dimension, or\n"
|
||||
"- Invalid variable name.");
|
||||
}
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PixelEffect.h"
|
||||
#include "GLee.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
// temporarily attaches a shader program (for setting uniforms, etc)
|
||||
// reattaches the originally active program when destroyed
|
||||
struct TemporaryAttacher
|
||||
{
|
||||
TemporaryAttacher(love::graphics::opengl::PixelEffect *sp) : s(sp)
|
||||
{
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
|
||||
s->attach();
|
||||
}
|
||||
~TemporaryAttacher()
|
||||
{
|
||||
glUseProgram(activeProgram);
|
||||
}
|
||||
love::graphics::opengl::PixelEffect *s;
|
||||
GLint activeProgram;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
PixelEffect *PixelEffect::current = NULL;
|
||||
|
||||
std::map<std::string, GLint> PixelEffect::_texture_unit_pool;
|
||||
GLint PixelEffect::_current_texture_unit = 0;
|
||||
GLint PixelEffect::_max_texture_units = 0;
|
||||
|
||||
GLint PixelEffect::getTextureUnit(const std::string &name)
|
||||
{
|
||||
std::map<std::string, GLint>::const_iterator it = _texture_unit_pool.find(name);
|
||||
|
||||
if (it != _texture_unit_pool.end())
|
||||
return it->second;
|
||||
|
||||
if (++_current_texture_unit >= _max_texture_units)
|
||||
throw love::Exception("No more texture units available");
|
||||
|
||||
_texture_unit_pool[name] = _current_texture_unit;
|
||||
return _current_texture_unit;
|
||||
}
|
||||
|
||||
PixelEffect::PixelEffect(const std::string &code)
|
||||
: _program(0)
|
||||
, _code(code)
|
||||
{
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &_max_texture_units);
|
||||
loadVolatile();
|
||||
}
|
||||
|
||||
bool PixelEffect::loadVolatile()
|
||||
{
|
||||
_program = glCreateProgram();
|
||||
// should only fail if this is called between a glBegin()/glEnd() pair
|
||||
if (_program == 0)
|
||||
throw love::Exception("Cannot create shader program object.");
|
||||
|
||||
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
// should only fail if this is called between a glBegin()/glEnd() pair
|
||||
if (shader == 0)
|
||||
{
|
||||
glDeleteProgram(_program);
|
||||
throw love::Exception("Cannot create shader object.");
|
||||
}
|
||||
|
||||
// compile fragment shader code
|
||||
const char *src = _code.c_str();
|
||||
GLint strlen = _code.length();
|
||||
glShaderSource(shader, 1, (const GLchar **)&src, &strlen);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint compile_ok;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_ok);
|
||||
if (GL_FALSE == compile_ok)
|
||||
{
|
||||
// get compiler error
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strlen);
|
||||
char *error_str = new char[strlen];
|
||||
glGetShaderInfoLog(shader, strlen, NULL, error_str);
|
||||
std::string tmp(error_str);
|
||||
|
||||
// cleanup before throw
|
||||
delete[] error_str;
|
||||
glDeleteShader(shader);
|
||||
glDeleteProgram(_program);
|
||||
|
||||
// XXX: errorlog may contain escape sequences.
|
||||
throw love::Exception("Cannot compile shader:\n%s", tmp.c_str());
|
||||
}
|
||||
|
||||
// link fragment shader
|
||||
GLint link_ok;
|
||||
glAttachShader(_program, shader);
|
||||
glLinkProgram(_program);
|
||||
glGetProgramiv(_program, GL_LINK_STATUS, &link_ok);
|
||||
if (GL_FALSE == link_ok)
|
||||
{
|
||||
// this should not happen if compiling is ok, but one can never be too careful
|
||||
// get linker error
|
||||
std::string tmp(getWarnings());
|
||||
|
||||
// cleanup before throw
|
||||
glDeleteShader(shader);
|
||||
glDeleteProgram(_program);
|
||||
throw love::Exception("Cannot compile shader:\n%s", tmp.c_str());
|
||||
}
|
||||
|
||||
glDeleteShader(shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
PixelEffect::~PixelEffect()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
void PixelEffect::unloadVolatile()
|
||||
{
|
||||
glDeleteProgram(_program);
|
||||
}
|
||||
|
||||
std::string PixelEffect::getGLSLVersion()
|
||||
{
|
||||
// GL_SHADING_LANGUAGE_VERSION is not available in OpenGL < 2.1.
|
||||
// Be very pessimistic about the GLSL version in that case.
|
||||
if (!GLEE_VERSION_2_1)
|
||||
return "0.0";
|
||||
|
||||
// the version string always begins with a version number of the format
|
||||
// major_number.minor_number
|
||||
// or
|
||||
// major_number.minor_number.release_number
|
||||
std::string versionString((const char *)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
size_t minorEndPos = versionString.find(" ");
|
||||
return versionString.substr(0, minorEndPos);
|
||||
}
|
||||
|
||||
|
||||
bool PixelEffect::isSupported()
|
||||
{
|
||||
return GLEE_VERSION_2_0 && GLEE_ARB_shader_objects && GLEE_ARB_fragment_shader && getGLSLVersion() >= "1.2";
|
||||
}
|
||||
|
||||
std::string PixelEffect::getWarnings() const
|
||||
{
|
||||
GLint strlen, nullpos;
|
||||
glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &strlen);
|
||||
char *temp_str = new char[strlen+1];
|
||||
// be extra sure that the error string will be 0-terminated
|
||||
memset(temp_str, '\0', strlen+1);
|
||||
glGetProgramInfoLog(_program, strlen, &nullpos, temp_str);
|
||||
temp_str[nullpos] = '\0';
|
||||
|
||||
std::string warnings(temp_str);
|
||||
delete[] temp_str;
|
||||
return warnings;
|
||||
}
|
||||
|
||||
void PixelEffect::attach()
|
||||
{
|
||||
glUseProgram(_program);
|
||||
current = this;
|
||||
}
|
||||
|
||||
void PixelEffect::detach()
|
||||
{
|
||||
glUseProgram(0);
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
void PixelEffect::sendFloat(const std::string &name, int size, const GLfloat *vec, int count)
|
||||
{
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
if (size < 1 || size > 4)
|
||||
{
|
||||
throw love::Exception("Invalid variable size: %d (expected 1-4).", size);
|
||||
}
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 4:
|
||||
glUniform4fv(location, count, vec);
|
||||
break;
|
||||
case 3:
|
||||
glUniform3fv(location, count, vec);
|
||||
break;
|
||||
case 2:
|
||||
glUniform2fv(location, count, vec);
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
glUniform1fv(location, count, vec);
|
||||
break;
|
||||
}
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
void PixelEffect::sendMatrix(const std::string &name, int size, const GLfloat *m, int count)
|
||||
{
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
if (size < 2 || size > 4)
|
||||
{
|
||||
throw love::Exception("Invalid matrix size: %dx%d "
|
||||
"(can only set 2x2, 3x3 or 4x4 matrices).", size,size);
|
||||
}
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 4:
|
||||
glUniformMatrix4fv(location, count, GL_FALSE, m);
|
||||
break;
|
||||
case 3:
|
||||
glUniformMatrix3fv(location, count, GL_FALSE, m);
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
glUniformMatrix2fv(location, count, GL_FALSE, m);
|
||||
break;
|
||||
}
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
void PixelEffect::sendImage(const std::string &name, const Image &image)
|
||||
{
|
||||
GLint texture_unit = getTextureUnit(name);
|
||||
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_unit);
|
||||
bindTexture(image.getTextureName(), true); // guarantee it gets bound
|
||||
glUniform1i(location, texture_unit);
|
||||
|
||||
// reset texture unit
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
void PixelEffect::sendCanvas(const std::string &name, const Canvas &canvas)
|
||||
{
|
||||
GLint texture_unit = getTextureUnit(name);
|
||||
|
||||
TemporaryAttacher attacher(this);
|
||||
GLint location = getUniformLocation(name);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_unit);
|
||||
bindTexture(canvas.getTextureName(), true); // guarantee it gets bound
|
||||
glUniform1i(location, texture_unit);
|
||||
|
||||
// reset texture unit
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// throw error if needed
|
||||
checkSetUniformError();
|
||||
}
|
||||
|
||||
GLint PixelEffect::getUniformLocation(const std::string &name)
|
||||
{
|
||||
std::map<std::string, GLint>::const_iterator it = _uniforms.find(name);
|
||||
if (it != _uniforms.end())
|
||||
return it->second;
|
||||
|
||||
GLint location = glGetUniformLocation(_program, name.c_str());
|
||||
if (location == -1)
|
||||
{
|
||||
throw love::Exception(
|
||||
"Cannot get location of shader variable `%s'.\n"
|
||||
"A common error is to define but not use the variable.", name.c_str());
|
||||
}
|
||||
|
||||
_uniforms[name] = location;
|
||||
return location;
|
||||
}
|
||||
|
||||
void PixelEffect::checkSetUniformError()
|
||||
{
|
||||
GLenum error_code = glGetError();
|
||||
if (GL_INVALID_OPERATION == error_code)
|
||||
{
|
||||
throw love::Exception(
|
||||
"Invalid operation:\n"
|
||||
"- Trying to send the wrong value type to shader variable, or\n"
|
||||
"- Trying to send array values with wrong dimension, or\n"
|
||||
"- Invalid variable name.");
|
||||
}
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_EFFECT_H
|
||||
#define LOVE_GRAPHICS_EFFECT_H
|
||||
|
||||
#include "common/Object.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "OpenGL.h"
|
||||
#include "Image.h"
|
||||
#include "Canvas.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// A fragment shader
|
||||
class PixelEffect : public Object, public Volatile
|
||||
{
|
||||
public:
|
||||
PixelEffect(const std::string &code);
|
||||
virtual ~PixelEffect();
|
||||
std::string getWarnings() const;
|
||||
|
||||
virtual bool loadVolatile();
|
||||
virtual void unloadVolatile();
|
||||
|
||||
void attach();
|
||||
static void detach();
|
||||
static std::string getGLSLVersion();
|
||||
static bool isSupported();
|
||||
|
||||
static PixelEffect *current;
|
||||
|
||||
void sendFloat(const std::string &name, int size, const GLfloat *vec, int count);
|
||||
void sendMatrix(const std::string &name, int size, const GLfloat *m, int count);
|
||||
void sendImage(const std::string &name, const Image &image);
|
||||
void sendCanvas(const std::string &name, const Canvas &canvas);
|
||||
|
||||
private:
|
||||
GLint getUniformLocation(const std::string &name);
|
||||
void checkSetUniformError();
|
||||
GLuint _program;
|
||||
std::string _code; // volatile and stuff
|
||||
|
||||
// uniform location buffer
|
||||
std::map<std::string, GLint> _uniforms;
|
||||
|
||||
// texture unit pool for setting images
|
||||
static std::map<std::string, GLint> _texture_unit_pool;
|
||||
static GLint _current_texture_unit;
|
||||
static GLint _max_texture_units;
|
||||
static GLint getTextureUnit(const std::string &name);
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_EFFECT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_EFFECT_H
|
||||
#define LOVE_GRAPHICS_EFFECT_H
|
||||
|
||||
#include "common/Object.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "OpenGL.h"
|
||||
#include "Image.h"
|
||||
#include "Canvas.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// A fragment shader
|
||||
class PixelEffect : public Object, public Volatile
|
||||
{
|
||||
public:
|
||||
PixelEffect(const std::string &code);
|
||||
virtual ~PixelEffect();
|
||||
std::string getWarnings() const;
|
||||
|
||||
virtual bool loadVolatile();
|
||||
virtual void unloadVolatile();
|
||||
|
||||
void attach();
|
||||
static void detach();
|
||||
static std::string getGLSLVersion();
|
||||
static bool isSupported();
|
||||
|
||||
static PixelEffect *current;
|
||||
|
||||
void sendFloat(const std::string &name, int size, const GLfloat *vec, int count);
|
||||
void sendMatrix(const std::string &name, int size, const GLfloat *m, int count);
|
||||
void sendImage(const std::string &name, const Image &image);
|
||||
void sendCanvas(const std::string &name, const Canvas &canvas);
|
||||
|
||||
private:
|
||||
GLint getUniformLocation(const std::string &name);
|
||||
void checkSetUniformError();
|
||||
GLuint _program;
|
||||
std::string _code; // volatile and stuff
|
||||
|
||||
// uniform location buffer
|
||||
std::map<std::string, GLint> _uniforms;
|
||||
|
||||
// texture unit pool for setting images
|
||||
static std::map<std::string, GLint> _texture_unit_pool;
|
||||
static GLint _current_texture_unit;
|
||||
static GLint _max_texture_units;
|
||||
static GLint getTextureUnit(const std::string &name);
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_EFFECT_H
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Quad.h"
|
||||
#include "common/Matrix.h"
|
||||
|
||||
// GLee
|
||||
#include "GLee.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Quad::Quad(const Viewport &v, float sw, float sh)
|
||||
: sw(sw)
|
||||
, sh(sh)
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*NUM_VERTICES);
|
||||
refresh(v, sw, sh);
|
||||
}
|
||||
|
||||
Quad::~Quad()
|
||||
{
|
||||
}
|
||||
|
||||
void Quad::refresh(const Viewport &v, float sw, float sh)
|
||||
{
|
||||
if (!GLEE_ARB_texture_non_power_of_two)
|
||||
{
|
||||
sw = next_p2(sw);
|
||||
sh = next_p2(sh);
|
||||
}
|
||||
viewport = v;
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = v.h;
|
||||
vertices[2].x = v.w;
|
||||
vertices[2].y = v.h;
|
||||
vertices[3].x = v.w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = v.x/sw;
|
||||
vertices[0].t = v.y/sh;
|
||||
vertices[1].s = v.x/sw;
|
||||
vertices[1].t = (v.y+v.h)/sh;
|
||||
vertices[2].s = (v.x+v.w)/sw;
|
||||
vertices[2].t = (v.y+v.h)/sh;
|
||||
vertices[3].s = (v.x+v.w)/sw;
|
||||
vertices[3].t = v.y/sh;
|
||||
}
|
||||
|
||||
void Quad::setViewport(const Quad::Viewport &v)
|
||||
{
|
||||
refresh(v, sw, sh);
|
||||
}
|
||||
|
||||
Quad::Viewport Quad::getViewport() const
|
||||
{
|
||||
return viewport;
|
||||
}
|
||||
|
||||
void Quad::flip(bool x, bool y)
|
||||
{
|
||||
vertex temp[4];
|
||||
if (x)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
|
||||
vertices[0].s = temp[3].s;
|
||||
vertices[0].t = temp[3].t;
|
||||
vertices[1].s = temp[2].s;
|
||||
vertices[1].t = temp[2].t;
|
||||
vertices[2].s = temp[1].s;
|
||||
vertices[2].t = temp[1].t;
|
||||
vertices[3].s = temp[0].s;
|
||||
vertices[3].t = temp[0].t;
|
||||
}
|
||||
if (y)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
|
||||
vertices[0].s = temp[1].s;
|
||||
vertices[0].t = temp[1].t;
|
||||
vertices[1].s = temp[0].s;
|
||||
vertices[1].t = temp[0].t;
|
||||
vertices[2].s = temp[3].s;
|
||||
vertices[2].t = temp[3].t;
|
||||
vertices[3].s = temp[2].s;
|
||||
vertices[3].t = temp[2].t;
|
||||
}
|
||||
}
|
||||
|
||||
void Quad::mirror(bool x, bool y)
|
||||
{
|
||||
for (size_t i = 0; i < NUM_VERTICES; ++i)
|
||||
{
|
||||
if (x)
|
||||
vertices[i].s = 1.0f - vertices[i].s;
|
||||
if (y)
|
||||
vertices[i].t = 1.0f - vertices[i].t;
|
||||
}
|
||||
}
|
||||
|
||||
const vertex *Quad::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Quad.h"
|
||||
#include "common/Matrix.h"
|
||||
|
||||
// GLee
|
||||
#include "GLee.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Quad::Quad(const Viewport &v, float sw, float sh)
|
||||
: sw(sw)
|
||||
, sh(sh)
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*NUM_VERTICES);
|
||||
refresh(v, sw, sh);
|
||||
}
|
||||
|
||||
Quad::~Quad()
|
||||
{
|
||||
}
|
||||
|
||||
void Quad::refresh(const Viewport &v, float sw, float sh)
|
||||
{
|
||||
if (!GLEE_ARB_texture_non_power_of_two)
|
||||
{
|
||||
sw = next_p2(sw);
|
||||
sh = next_p2(sh);
|
||||
}
|
||||
viewport = v;
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = v.h;
|
||||
vertices[2].x = v.w;
|
||||
vertices[2].y = v.h;
|
||||
vertices[3].x = v.w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = v.x/sw;
|
||||
vertices[0].t = v.y/sh;
|
||||
vertices[1].s = v.x/sw;
|
||||
vertices[1].t = (v.y+v.h)/sh;
|
||||
vertices[2].s = (v.x+v.w)/sw;
|
||||
vertices[2].t = (v.y+v.h)/sh;
|
||||
vertices[3].s = (v.x+v.w)/sw;
|
||||
vertices[3].t = v.y/sh;
|
||||
}
|
||||
|
||||
void Quad::setViewport(const Quad::Viewport &v)
|
||||
{
|
||||
refresh(v, sw, sh);
|
||||
}
|
||||
|
||||
Quad::Viewport Quad::getViewport() const
|
||||
{
|
||||
return viewport;
|
||||
}
|
||||
|
||||
void Quad::flip(bool x, bool y)
|
||||
{
|
||||
vertex temp[4];
|
||||
if (x)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
|
||||
vertices[0].s = temp[3].s;
|
||||
vertices[0].t = temp[3].t;
|
||||
vertices[1].s = temp[2].s;
|
||||
vertices[1].t = temp[2].t;
|
||||
vertices[2].s = temp[1].s;
|
||||
vertices[2].t = temp[1].t;
|
||||
vertices[3].s = temp[0].s;
|
||||
vertices[3].t = temp[0].t;
|
||||
}
|
||||
if (y)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
|
||||
vertices[0].s = temp[1].s;
|
||||
vertices[0].t = temp[1].t;
|
||||
vertices[1].s = temp[0].s;
|
||||
vertices[1].t = temp[0].t;
|
||||
vertices[2].s = temp[3].s;
|
||||
vertices[2].t = temp[3].t;
|
||||
vertices[3].s = temp[2].s;
|
||||
vertices[3].t = temp[2].t;
|
||||
}
|
||||
}
|
||||
|
||||
void Quad::mirror(bool x, bool y)
|
||||
{
|
||||
for (size_t i = 0; i < NUM_VERTICES; ++i)
|
||||
{
|
||||
if (x)
|
||||
vertices[i].s = 1.0f - vertices[i].s;
|
||||
if (y)
|
||||
vertices[i].t = 1.0f - vertices[i].t;
|
||||
}
|
||||
}
|
||||
|
||||
const vertex *Quad::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_QUAD_H
|
||||
#define LOVE_GRAPHICS_OPENGL_QUAD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include <graphics/Quad.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Quad : public love::graphics::Quad
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Quad of size (w,h), using (x,y) as the top-left
|
||||
* anchor point in the source image. The size of the source image is
|
||||
* is specified by (sw,sh).
|
||||
*
|
||||
* @param sw Width of the source image.
|
||||
* @param sh Height of the source image.
|
||||
**/
|
||||
Quad(const Viewport &v, float sw, float sh);
|
||||
|
||||
virtual ~Quad();
|
||||
|
||||
void refresh(const Viewport &v, float sw, float sh);
|
||||
|
||||
void setViewport(const Viewport &v);
|
||||
Viewport getViewport() const;
|
||||
|
||||
void flip(bool x, bool y);
|
||||
void mirror(bool x, bool y);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
const vertex *getVertices() const;
|
||||
|
||||
protected:
|
||||
|
||||
static const unsigned int NUM_VERTICES = 4;
|
||||
vertex vertices[NUM_VERTICES];
|
||||
|
||||
Viewport viewport;
|
||||
float sw, sh;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_QUAD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_QUAD_H
|
||||
#define LOVE_GRAPHICS_OPENGL_QUAD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include <graphics/Quad.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Quad : public love::graphics::Quad
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Quad of size (w,h), using (x,y) as the top-left
|
||||
* anchor point in the source image. The size of the source image is
|
||||
* is specified by (sw,sh).
|
||||
*
|
||||
* @param sw Width of the source image.
|
||||
* @param sh Height of the source image.
|
||||
**/
|
||||
Quad(const Viewport &v, float sw, float sh);
|
||||
|
||||
virtual ~Quad();
|
||||
|
||||
void refresh(const Viewport &v, float sw, float sh);
|
||||
|
||||
void setViewport(const Viewport &v);
|
||||
Viewport getViewport() const;
|
||||
|
||||
void flip(bool x, bool y);
|
||||
void mirror(bool x, bool y);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
const vertex *getVertices() const;
|
||||
|
||||
protected:
|
||||
|
||||
static const unsigned int NUM_VERTICES = 4;
|
||||
vertex vertices[NUM_VERTICES];
|
||||
|
||||
Viewport viewport;
|
||||
float sw, sh;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_QUAD_H
|
||||
|
||||
@@ -1,288 +1,288 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
// LOVE
|
||||
#include "Image.h"
|
||||
#include "Quad.h"
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
SpriteBatch::SpriteBatch(Image *image, int size, int usage)
|
||||
: image(image)
|
||||
, size(size)
|
||||
, next(0)
|
||||
, color(0)
|
||||
, array_buf(0)
|
||||
, element_buf(0)
|
||||
{
|
||||
image->retain();
|
||||
|
||||
GLenum gl_usage;
|
||||
|
||||
switch (usage)
|
||||
{
|
||||
default:
|
||||
case USAGE_DYNAMIC:
|
||||
gl_usage = GL_DYNAMIC_DRAW;
|
||||
break;
|
||||
case USAGE_STATIC:
|
||||
gl_usage = GL_STATIC_DRAW;
|
||||
break;
|
||||
case USAGE_STREAM:
|
||||
gl_usage = GL_STREAM_DRAW;
|
||||
break;
|
||||
}
|
||||
|
||||
int vertex_size = sizeof(vertex) * 4 * size;
|
||||
int element_size = sizeof(GLushort) * 6 * size;
|
||||
|
||||
array_buf = VertexBuffer::Create(vertex_size, GL_ARRAY_BUFFER, gl_usage);
|
||||
element_buf = VertexBuffer::Create(element_size, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW);
|
||||
|
||||
// Fill element buffer.
|
||||
{
|
||||
VertexBuffer::Bind bind(*element_buf);
|
||||
VertexBuffer::Mapper mapper(*element_buf);
|
||||
|
||||
GLushort *indices = static_cast<GLushort *>(mapper.get());
|
||||
|
||||
if (indices)
|
||||
{
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
indices[i*6+0] = 0+(i*4);
|
||||
indices[i*6+1] = 1+(i*4);
|
||||
indices[i*6+2] = 2+(i*4);
|
||||
|
||||
indices[i*6+3] = 0+(i*4);
|
||||
indices[i*6+4] = 2+(i*4);
|
||||
indices[i*6+5] = 3+(i*4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SpriteBatch::~SpriteBatch()
|
||||
{
|
||||
image->release();
|
||||
|
||||
delete color;
|
||||
delete array_buf;
|
||||
delete element_buf;
|
||||
}
|
||||
|
||||
int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if ((index == -1 && next >= size) || index < -1 || index >= size)
|
||||
return -1;
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, image->getVertices(), sizeof(vertex)*4);
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
addv(sprite, (index == -1 ? next : index));
|
||||
|
||||
// Increment counter.
|
||||
if (index == -1)
|
||||
return next++;
|
||||
return index;
|
||||
}
|
||||
|
||||
int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if ((index == -1 && next >= size) || index < -1 || index >= next)
|
||||
return -1;
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, quad->getVertices(), sizeof(vertex)*4);
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
addv(sprite, (index == -1 ? next : index));
|
||||
|
||||
// Increment counter.
|
||||
if (index == -1)
|
||||
return next++;
|
||||
return index;
|
||||
}
|
||||
|
||||
void SpriteBatch::clear()
|
||||
{
|
||||
// Reset the position of the next index.
|
||||
next = 0;
|
||||
}
|
||||
|
||||
void *SpriteBatch::lock()
|
||||
{
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
return array_buf->map();
|
||||
}
|
||||
|
||||
void SpriteBatch::unlock()
|
||||
{
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
array_buf->unmap();
|
||||
}
|
||||
|
||||
void SpriteBatch::setImage(Image *newimage)
|
||||
{
|
||||
image->release();
|
||||
image = newimage;
|
||||
image->retain();
|
||||
}
|
||||
|
||||
Image *SpriteBatch::getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
void SpriteBatch::setColor(const Color &color)
|
||||
{
|
||||
if (!this->color)
|
||||
this->color = new Color(color);
|
||||
else
|
||||
*(this->color) = color;
|
||||
}
|
||||
|
||||
void SpriteBatch::setColor()
|
||||
{
|
||||
delete color;
|
||||
color = 0;
|
||||
}
|
||||
|
||||
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
const int color_offset = 0;
|
||||
const int vertex_offset = sizeof(unsigned char) * 4;
|
||||
const int texel_offset = sizeof(unsigned char) * 4 + sizeof(float) * 2;
|
||||
|
||||
static Matrix t;
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
image->bind();
|
||||
|
||||
VertexBuffer::Bind array_bind(*array_buf);
|
||||
VertexBuffer::Bind element_bind(*element_buf);
|
||||
|
||||
// Apply per-sprite color, if a color is set.
|
||||
if (color)
|
||||
{
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), array_buf->getPointer(color_offset));
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(vertex_offset));
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(texel_offset));
|
||||
|
||||
glDrawElements(GL_TRIANGLES, next*6, GL_UNSIGNED_SHORT, element_buf->getPointer(0));
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void SpriteBatch::addv(const vertex *v, int index)
|
||||
{
|
||||
int sprite_size = sizeof(vertex) * 4;
|
||||
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
array_buf->fill(index * sprite_size, sprite_size, v);
|
||||
}
|
||||
|
||||
void SpriteBatch::setColorv(vertex *v, const Color &color)
|
||||
{
|
||||
v[0].r = color.r;
|
||||
v[0].g = color.g;
|
||||
v[0].b = color.b;
|
||||
v[0].a = color.a;
|
||||
v[1].r = color.r;
|
||||
v[1].g = color.g;
|
||||
v[1].b = color.b;
|
||||
v[1].a = color.a;
|
||||
v[2].r = color.r;
|
||||
v[2].g = color.g;
|
||||
v[2].b = color.b;
|
||||
v[2].a = color.a;
|
||||
v[3].r = color.r;
|
||||
v[3].g = color.g;
|
||||
v[3].b = color.b;
|
||||
v[3].a = color.a;
|
||||
}
|
||||
|
||||
bool SpriteBatch::getConstant(const char *in, UsageHint &out)
|
||||
{
|
||||
return usageHints.find(in, out);
|
||||
}
|
||||
|
||||
bool SpriteBatch::getConstant(UsageHint in, const char *&out)
|
||||
{
|
||||
return usageHints.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<SpriteBatch::UsageHint, SpriteBatch::USAGE_MAX_ENUM>::Entry SpriteBatch::usageHintEntries[] =
|
||||
{
|
||||
{"dynamic", SpriteBatch::USAGE_DYNAMIC},
|
||||
{"static", SpriteBatch::USAGE_STATIC},
|
||||
{"stream", SpriteBatch::USAGE_STREAM},
|
||||
};
|
||||
|
||||
StringMap<SpriteBatch::UsageHint, SpriteBatch::USAGE_MAX_ENUM> SpriteBatch::usageHints(usageHintEntries, sizeof(usageHintEntries));
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
// LOVE
|
||||
#include "Image.h"
|
||||
#include "Quad.h"
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
SpriteBatch::SpriteBatch(Image *image, int size, int usage)
|
||||
: image(image)
|
||||
, size(size)
|
||||
, next(0)
|
||||
, color(0)
|
||||
, array_buf(0)
|
||||
, element_buf(0)
|
||||
{
|
||||
image->retain();
|
||||
|
||||
GLenum gl_usage;
|
||||
|
||||
switch (usage)
|
||||
{
|
||||
default:
|
||||
case USAGE_DYNAMIC:
|
||||
gl_usage = GL_DYNAMIC_DRAW;
|
||||
break;
|
||||
case USAGE_STATIC:
|
||||
gl_usage = GL_STATIC_DRAW;
|
||||
break;
|
||||
case USAGE_STREAM:
|
||||
gl_usage = GL_STREAM_DRAW;
|
||||
break;
|
||||
}
|
||||
|
||||
int vertex_size = sizeof(vertex) * 4 * size;
|
||||
int element_size = sizeof(GLushort) * 6 * size;
|
||||
|
||||
array_buf = VertexBuffer::Create(vertex_size, GL_ARRAY_BUFFER, gl_usage);
|
||||
element_buf = VertexBuffer::Create(element_size, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW);
|
||||
|
||||
// Fill element buffer.
|
||||
{
|
||||
VertexBuffer::Bind bind(*element_buf);
|
||||
VertexBuffer::Mapper mapper(*element_buf);
|
||||
|
||||
GLushort *indices = static_cast<GLushort *>(mapper.get());
|
||||
|
||||
if (indices)
|
||||
{
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
indices[i*6+0] = 0+(i*4);
|
||||
indices[i*6+1] = 1+(i*4);
|
||||
indices[i*6+2] = 2+(i*4);
|
||||
|
||||
indices[i*6+3] = 0+(i*4);
|
||||
indices[i*6+4] = 2+(i*4);
|
||||
indices[i*6+5] = 3+(i*4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SpriteBatch::~SpriteBatch()
|
||||
{
|
||||
image->release();
|
||||
|
||||
delete color;
|
||||
delete array_buf;
|
||||
delete element_buf;
|
||||
}
|
||||
|
||||
int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if ((index == -1 && next >= size) || index < -1 || index >= size)
|
||||
return -1;
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, image->getVertices(), sizeof(vertex)*4);
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
addv(sprite, (index == -1 ? next : index));
|
||||
|
||||
// Increment counter.
|
||||
if (index == -1)
|
||||
return next++;
|
||||
return index;
|
||||
}
|
||||
|
||||
int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if ((index == -1 && next >= size) || index < -1 || index >= next)
|
||||
return -1;
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, quad->getVertices(), sizeof(vertex)*4);
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
addv(sprite, (index == -1 ? next : index));
|
||||
|
||||
// Increment counter.
|
||||
if (index == -1)
|
||||
return next++;
|
||||
return index;
|
||||
}
|
||||
|
||||
void SpriteBatch::clear()
|
||||
{
|
||||
// Reset the position of the next index.
|
||||
next = 0;
|
||||
}
|
||||
|
||||
void *SpriteBatch::lock()
|
||||
{
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
return array_buf->map();
|
||||
}
|
||||
|
||||
void SpriteBatch::unlock()
|
||||
{
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
array_buf->unmap();
|
||||
}
|
||||
|
||||
void SpriteBatch::setImage(Image *newimage)
|
||||
{
|
||||
image->release();
|
||||
image = newimage;
|
||||
image->retain();
|
||||
}
|
||||
|
||||
Image *SpriteBatch::getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
void SpriteBatch::setColor(const Color &color)
|
||||
{
|
||||
if (!this->color)
|
||||
this->color = new Color(color);
|
||||
else
|
||||
*(this->color) = color;
|
||||
}
|
||||
|
||||
void SpriteBatch::setColor()
|
||||
{
|
||||
delete color;
|
||||
color = 0;
|
||||
}
|
||||
|
||||
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
const int color_offset = 0;
|
||||
const int vertex_offset = sizeof(unsigned char) * 4;
|
||||
const int texel_offset = sizeof(unsigned char) * 4 + sizeof(float) * 2;
|
||||
|
||||
static Matrix t;
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
image->bind();
|
||||
|
||||
VertexBuffer::Bind array_bind(*array_buf);
|
||||
VertexBuffer::Bind element_bind(*element_buf);
|
||||
|
||||
// Apply per-sprite color, if a color is set.
|
||||
if (color)
|
||||
{
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), array_buf->getPointer(color_offset));
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(vertex_offset));
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(texel_offset));
|
||||
|
||||
glDrawElements(GL_TRIANGLES, next*6, GL_UNSIGNED_SHORT, element_buf->getPointer(0));
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void SpriteBatch::addv(const vertex *v, int index)
|
||||
{
|
||||
int sprite_size = sizeof(vertex) * 4;
|
||||
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
array_buf->fill(index * sprite_size, sprite_size, v);
|
||||
}
|
||||
|
||||
void SpriteBatch::setColorv(vertex *v, const Color &color)
|
||||
{
|
||||
v[0].r = color.r;
|
||||
v[0].g = color.g;
|
||||
v[0].b = color.b;
|
||||
v[0].a = color.a;
|
||||
v[1].r = color.r;
|
||||
v[1].g = color.g;
|
||||
v[1].b = color.b;
|
||||
v[1].a = color.a;
|
||||
v[2].r = color.r;
|
||||
v[2].g = color.g;
|
||||
v[2].b = color.b;
|
||||
v[2].a = color.a;
|
||||
v[3].r = color.r;
|
||||
v[3].g = color.g;
|
||||
v[3].b = color.b;
|
||||
v[3].a = color.a;
|
||||
}
|
||||
|
||||
bool SpriteBatch::getConstant(const char *in, UsageHint &out)
|
||||
{
|
||||
return usageHints.find(in, out);
|
||||
}
|
||||
|
||||
bool SpriteBatch::getConstant(UsageHint in, const char *&out)
|
||||
{
|
||||
return usageHints.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<SpriteBatch::UsageHint, SpriteBatch::USAGE_MAX_ENUM>::Entry SpriteBatch::usageHintEntries[] =
|
||||
{
|
||||
{"dynamic", SpriteBatch::USAGE_DYNAMIC},
|
||||
{"static", SpriteBatch::USAGE_STATIC},
|
||||
{"stream", SpriteBatch::USAGE_STREAM},
|
||||
};
|
||||
|
||||
StringMap<SpriteBatch::UsageHint, SpriteBatch::USAGE_MAX_ENUM> SpriteBatch::usageHints(usageHintEntries, sizeof(usageHintEntries));
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,136 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
|
||||
// C
|
||||
#include <cstring>
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "common/Object.h"
|
||||
#include "common/Vector.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "graphics/Drawable.h"
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/Color.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Forward declarations.
|
||||
class Image;
|
||||
class Quad;
|
||||
class VertexBuffer;
|
||||
|
||||
class SpriteBatch : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
enum UsageHint
|
||||
{
|
||||
USAGE_DYNAMIC = 1,
|
||||
USAGE_STATIC,
|
||||
USAGE_STREAM,
|
||||
USAGE_MAX_ENUM
|
||||
};
|
||||
|
||||
SpriteBatch(Image *image, int size, int usage);
|
||||
virtual ~SpriteBatch();
|
||||
|
||||
int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
|
||||
int addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
|
||||
void clear();
|
||||
|
||||
void *lock();
|
||||
void unlock();
|
||||
|
||||
void setImage(Image *newimage);
|
||||
Image *getImage();
|
||||
|
||||
/**
|
||||
* Set the current color for this SpriteBatch. The geometry added
|
||||
* after this call will use this color. Note that global color
|
||||
* will not longer apply to the SpriteBatch if this is used.
|
||||
*
|
||||
* @param color The color to use for the following geometry.
|
||||
*/
|
||||
void setColor(const Color &color);
|
||||
|
||||
/**
|
||||
* Disable per-quad colors for this SpriteBatch. The next call to
|
||||
* draw will use the global color for all sprites.
|
||||
*/
|
||||
void setColor();
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
static bool getConstant(const char *in, UsageHint &out);
|
||||
static bool getConstant(UsageHint in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
void addv(const vertex *v, int index);
|
||||
|
||||
/**
|
||||
* Set the color for vertices.
|
||||
*
|
||||
* @param v The vertices to set the color for. Must be an array of
|
||||
* of size 4.
|
||||
* @param color The color to assign to each vertex.
|
||||
*/
|
||||
void setColorv(vertex *v, const Color &color);
|
||||
|
||||
static StringMap<UsageHint, USAGE_MAX_ENUM>::Entry usageHintEntries[];
|
||||
static StringMap<UsageHint, USAGE_MAX_ENUM> usageHints;
|
||||
|
||||
Image *image;
|
||||
|
||||
// Max number of sprites in the batch.
|
||||
int size;
|
||||
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
vertex sprite[4];
|
||||
|
||||
// Current color. This color, if present, will be applied to the next
|
||||
// added quad.
|
||||
Color *color;
|
||||
|
||||
VertexBuffer *array_buf;
|
||||
VertexBuffer *element_buf;
|
||||
}; // SpriteBatch
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
|
||||
// C
|
||||
#include <cstring>
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "common/Object.h"
|
||||
#include "common/Vector.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "graphics/Drawable.h"
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/Color.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Forward declarations.
|
||||
class Image;
|
||||
class Quad;
|
||||
class VertexBuffer;
|
||||
|
||||
class SpriteBatch : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
enum UsageHint
|
||||
{
|
||||
USAGE_DYNAMIC = 1,
|
||||
USAGE_STATIC,
|
||||
USAGE_STREAM,
|
||||
USAGE_MAX_ENUM
|
||||
};
|
||||
|
||||
SpriteBatch(Image *image, int size, int usage);
|
||||
virtual ~SpriteBatch();
|
||||
|
||||
int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
|
||||
int addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
|
||||
void clear();
|
||||
|
||||
void *lock();
|
||||
void unlock();
|
||||
|
||||
void setImage(Image *newimage);
|
||||
Image *getImage();
|
||||
|
||||
/**
|
||||
* Set the current color for this SpriteBatch. The geometry added
|
||||
* after this call will use this color. Note that global color
|
||||
* will not longer apply to the SpriteBatch if this is used.
|
||||
*
|
||||
* @param color The color to use for the following geometry.
|
||||
*/
|
||||
void setColor(const Color &color);
|
||||
|
||||
/**
|
||||
* Disable per-quad colors for this SpriteBatch. The next call to
|
||||
* draw will use the global color for all sprites.
|
||||
*/
|
||||
void setColor();
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
||||
|
||||
static bool getConstant(const char *in, UsageHint &out);
|
||||
static bool getConstant(UsageHint in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
void addv(const vertex *v, int index);
|
||||
|
||||
/**
|
||||
* Set the color for vertices.
|
||||
*
|
||||
* @param v The vertices to set the color for. Must be an array of
|
||||
* of size 4.
|
||||
* @param color The color to assign to each vertex.
|
||||
*/
|
||||
void setColorv(vertex *v, const Color &color);
|
||||
|
||||
static StringMap<UsageHint, USAGE_MAX_ENUM>::Entry usageHintEntries[];
|
||||
static StringMap<UsageHint, USAGE_MAX_ENUM> usageHints;
|
||||
|
||||
Image *image;
|
||||
|
||||
// Max number of sprites in the batch.
|
||||
int size;
|
||||
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
vertex sprite[4];
|
||||
|
||||
// Current color. This color, if present, will be applied to the next
|
||||
// added quad.
|
||||
Color *color;
|
||||
|
||||
VertexBuffer *array_buf;
|
||||
VertexBuffer *element_buf;
|
||||
}; // SpriteBatch
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
|
||||
@@ -1,233 +1,233 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
#include "common/Exception.h"
|
||||
#include "common/config.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// VertexBuffer
|
||||
|
||||
VertexBuffer *VertexBuffer::Create(size_t size, GLenum target, GLenum usage)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try to create a VBO.
|
||||
return new VBO(size, target, usage);
|
||||
}
|
||||
catch(const love::Exception &)
|
||||
{
|
||||
// VBO not supported ... create regular array.
|
||||
return new VertexArray(size, target, usage);
|
||||
}
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(size_t size, GLenum target, GLenum usage)
|
||||
: size(size)
|
||||
, target(target)
|
||||
, usage(usage)
|
||||
{
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
// VertexArray
|
||||
|
||||
VertexArray::VertexArray(size_t size, GLenum target, GLenum usage)
|
||||
: VertexBuffer(size, target, usage)
|
||||
, buf(new char[size])
|
||||
{
|
||||
}
|
||||
|
||||
VertexArray::~VertexArray()
|
||||
{
|
||||
delete [] buf;
|
||||
}
|
||||
|
||||
void *VertexArray::map()
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
|
||||
void VertexArray::unmap()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexArray::bind()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexArray::unbind()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexArray::fill(size_t offset, size_t size, const void *data)
|
||||
{
|
||||
memcpy(buf + offset, data, size);
|
||||
}
|
||||
|
||||
const void *VertexArray::getPointer(size_t offset) const
|
||||
{
|
||||
return buf + offset;
|
||||
}
|
||||
|
||||
// VBO
|
||||
|
||||
VBO::VBO(size_t size, GLenum target, GLenum usage)
|
||||
: VertexBuffer(size, target, usage)
|
||||
, vbo(0)
|
||||
, buffer_copy(0)
|
||||
, mapped(0)
|
||||
{
|
||||
if (!(GLEE_ARB_vertex_buffer_object || GLEE_VERSION_1_5))
|
||||
throw love::Exception("Not supported");
|
||||
|
||||
bool ok = load(false);
|
||||
|
||||
if (!ok)
|
||||
throw love::Exception("Could not load VBO.");
|
||||
}
|
||||
|
||||
VBO::~VBO()
|
||||
{
|
||||
if (vbo != 0)
|
||||
unload(false);
|
||||
}
|
||||
|
||||
void *VBO::map()
|
||||
{
|
||||
// mapping twice could result in memory leaks
|
||||
if (mapped)
|
||||
throw love::Exception("VBO is already mapped!");
|
||||
|
||||
mapped = malloc(getSize());
|
||||
if (!mapped)
|
||||
throw love::Exception("Out of memory (oh the humanity!)");
|
||||
glGetBufferSubDataARB(getTarget(), 0, getSize(), mapped);
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
||||
void VBO::unmap()
|
||||
{
|
||||
glBufferSubDataARB(getTarget(), 0, getSize(), mapped);
|
||||
free(mapped);
|
||||
mapped = 0;
|
||||
}
|
||||
|
||||
void VBO::bind()
|
||||
{
|
||||
glBindBufferARB(getTarget(), vbo);
|
||||
}
|
||||
|
||||
void VBO::unbind()
|
||||
{
|
||||
glBindBufferARB(getTarget(), 0);
|
||||
}
|
||||
|
||||
void VBO::fill(size_t offset, size_t size, const void *data)
|
||||
{
|
||||
if (mapped)
|
||||
memcpy(static_cast<char *>(mapped) + offset, data, size);
|
||||
else
|
||||
glBufferSubDataARB(getTarget(), offset, size, data);
|
||||
}
|
||||
|
||||
const void *VBO::getPointer(size_t offset) const
|
||||
{
|
||||
return reinterpret_cast<const void *>(offset);
|
||||
}
|
||||
|
||||
bool VBO::loadVolatile()
|
||||
{
|
||||
return load(true);
|
||||
}
|
||||
|
||||
void VBO::unloadVolatile()
|
||||
{
|
||||
unload(true);
|
||||
}
|
||||
|
||||
bool VBO::load(bool restore)
|
||||
{
|
||||
glGenBuffersARB(1, &vbo);
|
||||
|
||||
VertexBuffer::Bind bind(*this);
|
||||
|
||||
// Copy the old buffer only if 'restore' was requested.
|
||||
const GLvoid *src = restore ? buffer_copy : 0;
|
||||
|
||||
while (GL_NO_ERROR != glGetError())
|
||||
/* clear error messages */;
|
||||
|
||||
// Note that if 'src' is '0', no data will be copied.
|
||||
glBufferDataARB(getTarget(), getSize(), src, getUsage());
|
||||
GLenum err = glGetError();
|
||||
|
||||
// Clean up buffer_copy, if it exists.
|
||||
delete[] buffer_copy;
|
||||
buffer_copy = 0;
|
||||
|
||||
return (GL_NO_ERROR == err);
|
||||
}
|
||||
|
||||
void VBO::unload(bool save)
|
||||
{
|
||||
// Clean up buffer_copy, if it exists.
|
||||
delete[] buffer_copy;
|
||||
buffer_copy = 0;
|
||||
|
||||
// Save data before unloading.
|
||||
if (save)
|
||||
{
|
||||
VertexBuffer::Bind bind(*this);
|
||||
|
||||
GLint size;
|
||||
glGetBufferParameterivARB(getTarget(), GL_BUFFER_SIZE, &size);
|
||||
|
||||
const char *src = static_cast<char *>(map());
|
||||
|
||||
if (src)
|
||||
{
|
||||
buffer_copy = new char[size];
|
||||
memcpy(buffer_copy, src, size);
|
||||
unmap();
|
||||
}
|
||||
}
|
||||
|
||||
glDeleteBuffers(1, &vbo);
|
||||
vbo = 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
#include "common/Exception.h"
|
||||
#include "common/config.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// VertexBuffer
|
||||
|
||||
VertexBuffer *VertexBuffer::Create(size_t size, GLenum target, GLenum usage)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try to create a VBO.
|
||||
return new VBO(size, target, usage);
|
||||
}
|
||||
catch(const love::Exception &)
|
||||
{
|
||||
// VBO not supported ... create regular array.
|
||||
return new VertexArray(size, target, usage);
|
||||
}
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(size_t size, GLenum target, GLenum usage)
|
||||
: size(size)
|
||||
, target(target)
|
||||
, usage(usage)
|
||||
{
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
// VertexArray
|
||||
|
||||
VertexArray::VertexArray(size_t size, GLenum target, GLenum usage)
|
||||
: VertexBuffer(size, target, usage)
|
||||
, buf(new char[size])
|
||||
{
|
||||
}
|
||||
|
||||
VertexArray::~VertexArray()
|
||||
{
|
||||
delete [] buf;
|
||||
}
|
||||
|
||||
void *VertexArray::map()
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
|
||||
void VertexArray::unmap()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexArray::bind()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexArray::unbind()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexArray::fill(size_t offset, size_t size, const void *data)
|
||||
{
|
||||
memcpy(buf + offset, data, size);
|
||||
}
|
||||
|
||||
const void *VertexArray::getPointer(size_t offset) const
|
||||
{
|
||||
return buf + offset;
|
||||
}
|
||||
|
||||
// VBO
|
||||
|
||||
VBO::VBO(size_t size, GLenum target, GLenum usage)
|
||||
: VertexBuffer(size, target, usage)
|
||||
, vbo(0)
|
||||
, buffer_copy(0)
|
||||
, mapped(0)
|
||||
{
|
||||
if (!(GLEE_ARB_vertex_buffer_object || GLEE_VERSION_1_5))
|
||||
throw love::Exception("Not supported");
|
||||
|
||||
bool ok = load(false);
|
||||
|
||||
if (!ok)
|
||||
throw love::Exception("Could not load VBO.");
|
||||
}
|
||||
|
||||
VBO::~VBO()
|
||||
{
|
||||
if (vbo != 0)
|
||||
unload(false);
|
||||
}
|
||||
|
||||
void *VBO::map()
|
||||
{
|
||||
// mapping twice could result in memory leaks
|
||||
if (mapped)
|
||||
throw love::Exception("VBO is already mapped!");
|
||||
|
||||
mapped = malloc(getSize());
|
||||
if (!mapped)
|
||||
throw love::Exception("Out of memory (oh the humanity!)");
|
||||
glGetBufferSubDataARB(getTarget(), 0, getSize(), mapped);
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
||||
void VBO::unmap()
|
||||
{
|
||||
glBufferSubDataARB(getTarget(), 0, getSize(), mapped);
|
||||
free(mapped);
|
||||
mapped = 0;
|
||||
}
|
||||
|
||||
void VBO::bind()
|
||||
{
|
||||
glBindBufferARB(getTarget(), vbo);
|
||||
}
|
||||
|
||||
void VBO::unbind()
|
||||
{
|
||||
glBindBufferARB(getTarget(), 0);
|
||||
}
|
||||
|
||||
void VBO::fill(size_t offset, size_t size, const void *data)
|
||||
{
|
||||
if (mapped)
|
||||
memcpy(static_cast<char *>(mapped) + offset, data, size);
|
||||
else
|
||||
glBufferSubDataARB(getTarget(), offset, size, data);
|
||||
}
|
||||
|
||||
const void *VBO::getPointer(size_t offset) const
|
||||
{
|
||||
return reinterpret_cast<const void *>(offset);
|
||||
}
|
||||
|
||||
bool VBO::loadVolatile()
|
||||
{
|
||||
return load(true);
|
||||
}
|
||||
|
||||
void VBO::unloadVolatile()
|
||||
{
|
||||
unload(true);
|
||||
}
|
||||
|
||||
bool VBO::load(bool restore)
|
||||
{
|
||||
glGenBuffersARB(1, &vbo);
|
||||
|
||||
VertexBuffer::Bind bind(*this);
|
||||
|
||||
// Copy the old buffer only if 'restore' was requested.
|
||||
const GLvoid *src = restore ? buffer_copy : 0;
|
||||
|
||||
while (GL_NO_ERROR != glGetError())
|
||||
/* clear error messages */;
|
||||
|
||||
// Note that if 'src' is '0', no data will be copied.
|
||||
glBufferDataARB(getTarget(), getSize(), src, getUsage());
|
||||
GLenum err = glGetError();
|
||||
|
||||
// Clean up buffer_copy, if it exists.
|
||||
delete[] buffer_copy;
|
||||
buffer_copy = 0;
|
||||
|
||||
return (GL_NO_ERROR == err);
|
||||
}
|
||||
|
||||
void VBO::unload(bool save)
|
||||
{
|
||||
// Clean up buffer_copy, if it exists.
|
||||
delete[] buffer_copy;
|
||||
buffer_copy = 0;
|
||||
|
||||
// Save data before unloading.
|
||||
if (save)
|
||||
{
|
||||
VertexBuffer::Bind bind(*this);
|
||||
|
||||
GLint size;
|
||||
glGetBufferParameterivARB(getTarget(), GL_BUFFER_SIZE, &size);
|
||||
|
||||
const char *src = static_cast<char *>(map());
|
||||
|
||||
if (src)
|
||||
{
|
||||
buffer_copy = new char[size];
|
||||
memcpy(buffer_copy, src, size);
|
||||
unmap();
|
||||
}
|
||||
}
|
||||
|
||||
glDeleteBuffers(1, &vbo);
|
||||
vbo = 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,339 +1,339 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
#define LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
|
||||
// LOVE
|
||||
#include "graphics/Volatile.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* VertexBuffer is an abstraction over VBOs (Vertex Buffer Objecys), which
|
||||
* falls back to regular vertex arrays if VBOs are not supported.
|
||||
*
|
||||
* This allows code to take advantage of VBOs where available, but still
|
||||
* work on older systems where it's *not* available. Everyone's happy.
|
||||
*
|
||||
* The class is (for now) meant for internal use.
|
||||
*/
|
||||
class VertexBuffer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new VertexBuffer (either a plain vertex array, or a VBO),
|
||||
* based on what's supported on the system.
|
||||
*
|
||||
* If VBOs are not supported, a plain vertex array will automatically
|
||||
* be created and returned instead.
|
||||
*
|
||||
* @param size The size of the VertexBuffer (in bytes).
|
||||
* @param target GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER.
|
||||
* @param usage GL_DYNAMIC_DRAW, etc.
|
||||
* @return A new VertexBuffer.
|
||||
*/
|
||||
static VertexBuffer *Create(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param size The size of the VertexBuffer in bytes.
|
||||
* @param target The target VertexBuffer object, e.g. GL_ARRAY_BUFFER.
|
||||
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
|
||||
*/
|
||||
VertexBuffer(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Destructor. Does nothing, but must be declared virtual.
|
||||
*/
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
/**
|
||||
* Get the size of the VertexBuffer, in bytes.
|
||||
*
|
||||
* @return The size of the VertexBuffer.
|
||||
*/
|
||||
size_t getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target buffer object.
|
||||
*
|
||||
* @return The target buffer object, e.g. GL_ARRAY_BUFFER.
|
||||
*/
|
||||
GLenum getTarget() const
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the usage hint for this VertexBuffer.
|
||||
*
|
||||
* @return The usage hint, e.g. GL_DYNAMIC_DRAW.
|
||||
*/
|
||||
GLenum getUsage() const
|
||||
{
|
||||
return usage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the VertexBuffer to client memory.
|
||||
*
|
||||
* This can be faster for large changes to the buffer. For smaller
|
||||
* changes, see fill().
|
||||
*
|
||||
* The VertexBuffer must be bound to use this function.
|
||||
*
|
||||
* @return A pointer to memory which represents the buffer.
|
||||
*/
|
||||
virtual void *map() = 0;
|
||||
|
||||
/**
|
||||
* Unmap a previously mapped VertexBuffer. The buffer must be unmapped
|
||||
* when used to draw elements.
|
||||
*
|
||||
* The VertexBuffer must be bound to use this function.
|
||||
*/
|
||||
virtual void unmap() = 0;
|
||||
|
||||
/**
|
||||
* Bind the VertexBuffer to the specified target.
|
||||
* (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
|
||||
*
|
||||
* @param target GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Unbind a prevously bound VertexBuffer.
|
||||
*/
|
||||
virtual void unbind() = 0;
|
||||
|
||||
/**
|
||||
* Fill a portion of the buffer with data.
|
||||
*
|
||||
* The VertexBuffer must be bound to use this function.
|
||||
*
|
||||
* @param offset The offset in the VertexBuffer to store the data.
|
||||
* @param size The size of the incoming data.
|
||||
* @param data Pointer to memory to copy data from.
|
||||
*/
|
||||
virtual void fill(size_t offset, size_t size, const void *data) = 0;
|
||||
|
||||
/**
|
||||
* Get a pointer which represents the specified byte offset.
|
||||
*
|
||||
* @param offset The byte offset. (0 is first byte).
|
||||
* @return A pointer which represents the offset.
|
||||
*/
|
||||
virtual const void *getPointer(size_t offset) const = 0;
|
||||
|
||||
/**
|
||||
* This helper class can bind a VertexArray temporarily, and
|
||||
* automatically un-bind when it's destroyed.
|
||||
*/
|
||||
class Bind
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Bind a VertexBuffer.
|
||||
*/
|
||||
Bind(VertexBuffer &buf)
|
||||
: buf(buf)
|
||||
{
|
||||
buf.bind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds a VertexBuffer.
|
||||
*/
|
||||
~Bind()
|
||||
{
|
||||
buf.unbind();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// VertexBuffer to work on.
|
||||
VertexBuffer &buf;
|
||||
};
|
||||
|
||||
class Mapper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Memory-maps a VertexBuffer.
|
||||
*/
|
||||
Mapper(VertexBuffer &buffer)
|
||||
: buf(buffer)
|
||||
{
|
||||
elems = buf.map();
|
||||
}
|
||||
|
||||
/**
|
||||
* unmaps the buffer
|
||||
*/
|
||||
~Mapper()
|
||||
{
|
||||
buf.unmap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pointer to memory mapped region
|
||||
*/
|
||||
void *get()
|
||||
{
|
||||
return elems;
|
||||
}
|
||||
|
||||
private:
|
||||
VertexBuffer &buf;
|
||||
void *elems;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// The size of the buffer, in bytes.
|
||||
size_t size;
|
||||
|
||||
// The target buffer object. (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
|
||||
GLenum target;
|
||||
|
||||
// Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW.
|
||||
GLenum usage;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of VertexBuffer which uses plain arrays to store the data.
|
||||
*
|
||||
* This implementation should be supported everywhere, and acts as a fallback
|
||||
* on systems which do not support VBOs.
|
||||
*/
|
||||
class VertexArray : public VertexBuffer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @copydoc VertexBuffer(int, GLenum, GLenum)
|
||||
*/
|
||||
VertexArray(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Frees the data we've allocated.
|
||||
*/
|
||||
virtual ~VertexArray();
|
||||
|
||||
// Implements VertexBuffer.
|
||||
virtual void *map();
|
||||
virtual void unmap();
|
||||
virtual void bind();
|
||||
virtual void unbind();
|
||||
virtual void fill(size_t offset, size_t size, const void *data);
|
||||
virtual const void *getPointer(size_t offset) const ;
|
||||
|
||||
private:
|
||||
// Holds the data.
|
||||
char *buf;
|
||||
};
|
||||
|
||||
/**
|
||||
* Vertex Buffer Object (VBO) implementation of VertexBuffer.
|
||||
*
|
||||
* This will be used on all systems that support it. It's in general
|
||||
* faster than vertex arrays, but especially in use-cases where there
|
||||
* is no need to update the data every frame.
|
||||
*/
|
||||
class VBO : public VertexBuffer, public Volatile
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @copydoc VertexBuffer(size_t, GLenum, GLenum)
|
||||
*/
|
||||
VBO(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Deletes the VBOs from OpenGL.
|
||||
*/
|
||||
virtual ~VBO();
|
||||
|
||||
// Implements VertexBuffer.
|
||||
virtual void *map();
|
||||
virtual void unmap();
|
||||
virtual void bind();
|
||||
virtual void unbind();
|
||||
virtual void fill(size_t offset, size_t size, const void *data);
|
||||
virtual const void *getPointer(size_t offset) const ;
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Creates the VBO, and optionally restores data we saved earlier.
|
||||
*
|
||||
* @param restore True to restore data previously saved with 'unload'.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
bool load(bool restore);
|
||||
|
||||
/**
|
||||
* Optionally save the data in the VBO, then delete it.
|
||||
*
|
||||
* @param save True to save the data before deleting.
|
||||
*/
|
||||
void unload(bool save);
|
||||
|
||||
// The VBO identifier. Assigned by OpenGL.
|
||||
GLuint vbo;
|
||||
|
||||
// *May* contain data saved by 'unload'.
|
||||
char *buffer_copy;
|
||||
|
||||
// A pointer to mapped memory. Zero if memory is currently
|
||||
// not mapped.
|
||||
void *mapped;
|
||||
|
||||
// Usage hint for map()/unmap() pair. Same as `access' parameter in
|
||||
// glBufferData or 0 if not mapped.
|
||||
GLenum mapped_access;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
#define LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
|
||||
// LOVE
|
||||
#include "graphics/Volatile.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* VertexBuffer is an abstraction over VBOs (Vertex Buffer Objecys), which
|
||||
* falls back to regular vertex arrays if VBOs are not supported.
|
||||
*
|
||||
* This allows code to take advantage of VBOs where available, but still
|
||||
* work on older systems where it's *not* available. Everyone's happy.
|
||||
*
|
||||
* The class is (for now) meant for internal use.
|
||||
*/
|
||||
class VertexBuffer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new VertexBuffer (either a plain vertex array, or a VBO),
|
||||
* based on what's supported on the system.
|
||||
*
|
||||
* If VBOs are not supported, a plain vertex array will automatically
|
||||
* be created and returned instead.
|
||||
*
|
||||
* @param size The size of the VertexBuffer (in bytes).
|
||||
* @param target GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER.
|
||||
* @param usage GL_DYNAMIC_DRAW, etc.
|
||||
* @return A new VertexBuffer.
|
||||
*/
|
||||
static VertexBuffer *Create(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param size The size of the VertexBuffer in bytes.
|
||||
* @param target The target VertexBuffer object, e.g. GL_ARRAY_BUFFER.
|
||||
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
|
||||
*/
|
||||
VertexBuffer(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Destructor. Does nothing, but must be declared virtual.
|
||||
*/
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
/**
|
||||
* Get the size of the VertexBuffer, in bytes.
|
||||
*
|
||||
* @return The size of the VertexBuffer.
|
||||
*/
|
||||
size_t getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target buffer object.
|
||||
*
|
||||
* @return The target buffer object, e.g. GL_ARRAY_BUFFER.
|
||||
*/
|
||||
GLenum getTarget() const
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the usage hint for this VertexBuffer.
|
||||
*
|
||||
* @return The usage hint, e.g. GL_DYNAMIC_DRAW.
|
||||
*/
|
||||
GLenum getUsage() const
|
||||
{
|
||||
return usage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the VertexBuffer to client memory.
|
||||
*
|
||||
* This can be faster for large changes to the buffer. For smaller
|
||||
* changes, see fill().
|
||||
*
|
||||
* The VertexBuffer must be bound to use this function.
|
||||
*
|
||||
* @return A pointer to memory which represents the buffer.
|
||||
*/
|
||||
virtual void *map() = 0;
|
||||
|
||||
/**
|
||||
* Unmap a previously mapped VertexBuffer. The buffer must be unmapped
|
||||
* when used to draw elements.
|
||||
*
|
||||
* The VertexBuffer must be bound to use this function.
|
||||
*/
|
||||
virtual void unmap() = 0;
|
||||
|
||||
/**
|
||||
* Bind the VertexBuffer to the specified target.
|
||||
* (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
|
||||
*
|
||||
* @param target GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Unbind a prevously bound VertexBuffer.
|
||||
*/
|
||||
virtual void unbind() = 0;
|
||||
|
||||
/**
|
||||
* Fill a portion of the buffer with data.
|
||||
*
|
||||
* The VertexBuffer must be bound to use this function.
|
||||
*
|
||||
* @param offset The offset in the VertexBuffer to store the data.
|
||||
* @param size The size of the incoming data.
|
||||
* @param data Pointer to memory to copy data from.
|
||||
*/
|
||||
virtual void fill(size_t offset, size_t size, const void *data) = 0;
|
||||
|
||||
/**
|
||||
* Get a pointer which represents the specified byte offset.
|
||||
*
|
||||
* @param offset The byte offset. (0 is first byte).
|
||||
* @return A pointer which represents the offset.
|
||||
*/
|
||||
virtual const void *getPointer(size_t offset) const = 0;
|
||||
|
||||
/**
|
||||
* This helper class can bind a VertexArray temporarily, and
|
||||
* automatically un-bind when it's destroyed.
|
||||
*/
|
||||
class Bind
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Bind a VertexBuffer.
|
||||
*/
|
||||
Bind(VertexBuffer &buf)
|
||||
: buf(buf)
|
||||
{
|
||||
buf.bind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds a VertexBuffer.
|
||||
*/
|
||||
~Bind()
|
||||
{
|
||||
buf.unbind();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// VertexBuffer to work on.
|
||||
VertexBuffer &buf;
|
||||
};
|
||||
|
||||
class Mapper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Memory-maps a VertexBuffer.
|
||||
*/
|
||||
Mapper(VertexBuffer &buffer)
|
||||
: buf(buffer)
|
||||
{
|
||||
elems = buf.map();
|
||||
}
|
||||
|
||||
/**
|
||||
* unmaps the buffer
|
||||
*/
|
||||
~Mapper()
|
||||
{
|
||||
buf.unmap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pointer to memory mapped region
|
||||
*/
|
||||
void *get()
|
||||
{
|
||||
return elems;
|
||||
}
|
||||
|
||||
private:
|
||||
VertexBuffer &buf;
|
||||
void *elems;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// The size of the buffer, in bytes.
|
||||
size_t size;
|
||||
|
||||
// The target buffer object. (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
|
||||
GLenum target;
|
||||
|
||||
// Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW.
|
||||
GLenum usage;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of VertexBuffer which uses plain arrays to store the data.
|
||||
*
|
||||
* This implementation should be supported everywhere, and acts as a fallback
|
||||
* on systems which do not support VBOs.
|
||||
*/
|
||||
class VertexArray : public VertexBuffer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @copydoc VertexBuffer(int, GLenum, GLenum)
|
||||
*/
|
||||
VertexArray(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Frees the data we've allocated.
|
||||
*/
|
||||
virtual ~VertexArray();
|
||||
|
||||
// Implements VertexBuffer.
|
||||
virtual void *map();
|
||||
virtual void unmap();
|
||||
virtual void bind();
|
||||
virtual void unbind();
|
||||
virtual void fill(size_t offset, size_t size, const void *data);
|
||||
virtual const void *getPointer(size_t offset) const ;
|
||||
|
||||
private:
|
||||
// Holds the data.
|
||||
char *buf;
|
||||
};
|
||||
|
||||
/**
|
||||
* Vertex Buffer Object (VBO) implementation of VertexBuffer.
|
||||
*
|
||||
* This will be used on all systems that support it. It's in general
|
||||
* faster than vertex arrays, but especially in use-cases where there
|
||||
* is no need to update the data every frame.
|
||||
*/
|
||||
class VBO : public VertexBuffer, public Volatile
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @copydoc VertexBuffer(size_t, GLenum, GLenum)
|
||||
*/
|
||||
VBO(size_t size, GLenum target, GLenum usage);
|
||||
|
||||
/**
|
||||
* Deletes the VBOs from OpenGL.
|
||||
*/
|
||||
virtual ~VBO();
|
||||
|
||||
// Implements VertexBuffer.
|
||||
virtual void *map();
|
||||
virtual void unmap();
|
||||
virtual void bind();
|
||||
virtual void unbind();
|
||||
virtual void fill(size_t offset, size_t size, const void *data);
|
||||
virtual const void *getPointer(size_t offset) const ;
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Creates the VBO, and optionally restores data we saved earlier.
|
||||
*
|
||||
* @param restore True to restore data previously saved with 'unload'.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
bool load(bool restore);
|
||||
|
||||
/**
|
||||
* Optionally save the data in the VBO, then delete it.
|
||||
*
|
||||
* @param save True to save the data before deleting.
|
||||
*/
|
||||
void unload(bool save);
|
||||
|
||||
// The VBO identifier. Assigned by OpenGL.
|
||||
GLuint vbo;
|
||||
|
||||
// *May* contain data saved by 'unload'.
|
||||
char *buffer_copy;
|
||||
|
||||
// A pointer to mapped memory. Zero if memory is currently
|
||||
// not mapped.
|
||||
void *mapped;
|
||||
|
||||
// Usage hint for map()/unmap() pair. Same as `access' parameter in
|
||||
// glBufferData or 0 if not mapped.
|
||||
GLenum mapped_access;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
|
||||
@@ -1,205 +1,205 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Graphics.h"
|
||||
#include "wrap_Canvas.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Canvas *luax_checkcanvas(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Canvas>(L, idx, "Canvas", GRAPHICS_CANVAS_T);
|
||||
}
|
||||
|
||||
int w_Canvas_renderTo(lua_State *L)
|
||||
{
|
||||
// As startGrab() clears the framebuffer, better not allow
|
||||
// grabbing inside another grabbing
|
||||
if (Canvas::current != NULL)
|
||||
{
|
||||
Canvas::bindDefaultCanvas();
|
||||
return luaL_error(L, "Current render target not the default canvas!");
|
||||
}
|
||||
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
if (!lua_isfunction(L, 2))
|
||||
return luaL_error(L, "Need a function to render to canvas.");
|
||||
|
||||
canvas->startGrab();
|
||||
lua_settop(L, 2); // make sure the function is on top of the stack
|
||||
lua_call(L, 0, 0);
|
||||
canvas->stopGrab();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getImageData(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
|
||||
love::image::ImageData *img = canvas->getImageData(image);
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)img);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Canvas_setFilter(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_checkstring(L, 3);
|
||||
|
||||
Image::Filter f;
|
||||
if (!Image::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid min filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid max filter mode: %s", magstr);
|
||||
|
||||
canvas->setFilter(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getFilter(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Image::Filter f = canvas->getFilter();
|
||||
|
||||
const char *minstr;
|
||||
const char *magstr;
|
||||
Image::getConstant(f.min, minstr);
|
||||
Image::getConstant(f.mag, magstr);
|
||||
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Canvas_setWrap(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
const char *wrap_s = luaL_checkstring(L, 2);
|
||||
const char *wrap_t = luaL_checkstring(L, 3);
|
||||
|
||||
Image::Wrap w;
|
||||
if (!Image::getConstant(wrap_s, w.s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", wrap_s);
|
||||
if (!Image::getConstant(wrap_t, w.t))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", wrap_t);
|
||||
|
||||
canvas->setWrap(w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getWrap(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Image::Wrap w = canvas->getWrap();
|
||||
|
||||
const char *wrap_s;
|
||||
const char *wrap_t;
|
||||
Image::getConstant(w.s, wrap_s);
|
||||
Image::getConstant(w.t, wrap_t);
|
||||
|
||||
lua_pushstring(L, wrap_s);
|
||||
lua_pushstring(L, wrap_t);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Canvas_clear(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Color c;
|
||||
if (lua_isnoneornil(L, 2))
|
||||
{
|
||||
c.r = 0;
|
||||
c.g = 0;
|
||||
c.b = 0;
|
||||
c.a = 0;
|
||||
}
|
||||
else if (lua_istable(L, 2))
|
||||
{
|
||||
lua_pushinteger(L, 1);
|
||||
lua_gettable(L, 2);
|
||||
c.r = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 2);
|
||||
lua_gettable(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 3);
|
||||
lua_gettable(L, 2);
|
||||
c.b = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 4);
|
||||
lua_gettable(L, 2);
|
||||
c.g = (unsigned char)luaL_optint(L, -1, 255);
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.r = (unsigned char)luaL_checkint(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, 3);
|
||||
c.b = (unsigned char)luaL_checkint(L, 4);
|
||||
c.a = (unsigned char)luaL_optint(L, 5, 255);
|
||||
}
|
||||
canvas->clear(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getWidth(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
lua_pushnumber(L, canvas->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Canvas_getHeight(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
lua_pushnumber(L, canvas->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "renderTo", w_Canvas_renderTo },
|
||||
{ "getImageData", w_Canvas_getImageData },
|
||||
{ "setFilter", w_Canvas_setFilter },
|
||||
{ "getFilter", w_Canvas_getFilter },
|
||||
{ "setWrap", w_Canvas_setWrap },
|
||||
{ "getWrap", w_Canvas_getWrap },
|
||||
{ "clear", w_Canvas_clear },
|
||||
{ "getWidth", w_Canvas_getWidth },
|
||||
{ "getHeight", w_Canvas_getHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_canvas(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Canvas", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Graphics.h"
|
||||
#include "wrap_Canvas.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Canvas *luax_checkcanvas(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Canvas>(L, idx, "Canvas", GRAPHICS_CANVAS_T);
|
||||
}
|
||||
|
||||
int w_Canvas_renderTo(lua_State *L)
|
||||
{
|
||||
// As startGrab() clears the framebuffer, better not allow
|
||||
// grabbing inside another grabbing
|
||||
if (Canvas::current != NULL)
|
||||
{
|
||||
Canvas::bindDefaultCanvas();
|
||||
return luaL_error(L, "Current render target not the default canvas!");
|
||||
}
|
||||
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
if (!lua_isfunction(L, 2))
|
||||
return luaL_error(L, "Need a function to render to canvas.");
|
||||
|
||||
canvas->startGrab();
|
||||
lua_settop(L, 2); // make sure the function is on top of the stack
|
||||
lua_call(L, 0, 0);
|
||||
canvas->stopGrab();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getImageData(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
|
||||
love::image::ImageData *img = canvas->getImageData(image);
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)img);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Canvas_setFilter(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_checkstring(L, 3);
|
||||
|
||||
Image::Filter f;
|
||||
if (!Image::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid min filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid max filter mode: %s", magstr);
|
||||
|
||||
canvas->setFilter(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getFilter(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Image::Filter f = canvas->getFilter();
|
||||
|
||||
const char *minstr;
|
||||
const char *magstr;
|
||||
Image::getConstant(f.min, minstr);
|
||||
Image::getConstant(f.mag, magstr);
|
||||
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Canvas_setWrap(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
const char *wrap_s = luaL_checkstring(L, 2);
|
||||
const char *wrap_t = luaL_checkstring(L, 3);
|
||||
|
||||
Image::Wrap w;
|
||||
if (!Image::getConstant(wrap_s, w.s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", wrap_s);
|
||||
if (!Image::getConstant(wrap_t, w.t))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", wrap_t);
|
||||
|
||||
canvas->setWrap(w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getWrap(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Image::Wrap w = canvas->getWrap();
|
||||
|
||||
const char *wrap_s;
|
||||
const char *wrap_t;
|
||||
Image::getConstant(w.s, wrap_s);
|
||||
Image::getConstant(w.t, wrap_t);
|
||||
|
||||
lua_pushstring(L, wrap_s);
|
||||
lua_pushstring(L, wrap_t);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Canvas_clear(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Color c;
|
||||
if (lua_isnoneornil(L, 2))
|
||||
{
|
||||
c.r = 0;
|
||||
c.g = 0;
|
||||
c.b = 0;
|
||||
c.a = 0;
|
||||
}
|
||||
else if (lua_istable(L, 2))
|
||||
{
|
||||
lua_pushinteger(L, 1);
|
||||
lua_gettable(L, 2);
|
||||
c.r = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 2);
|
||||
lua_gettable(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 3);
|
||||
lua_gettable(L, 2);
|
||||
c.b = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 4);
|
||||
lua_gettable(L, 2);
|
||||
c.g = (unsigned char)luaL_optint(L, -1, 255);
|
||||
lua_pop(L, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.r = (unsigned char)luaL_checkint(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, 3);
|
||||
c.b = (unsigned char)luaL_checkint(L, 4);
|
||||
c.a = (unsigned char)luaL_optint(L, 5, 255);
|
||||
}
|
||||
canvas->clear(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Canvas_getWidth(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
lua_pushnumber(L, canvas->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Canvas_getHeight(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
lua_pushnumber(L, canvas->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "renderTo", w_Canvas_renderTo },
|
||||
{ "getImageData", w_Canvas_getImageData },
|
||||
{ "setFilter", w_Canvas_setFilter },
|
||||
{ "getFilter", w_Canvas_getFilter },
|
||||
{ "setWrap", w_Canvas_setWrap },
|
||||
{ "getWrap", w_Canvas_getWrap },
|
||||
{ "clear", w_Canvas_clear },
|
||||
{ "getWidth", w_Canvas_getWidth },
|
||||
{ "getHeight", w_Canvas_getHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_canvas(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Canvas", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_CANVAS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_CANVAS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Canvas.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
//see Canvas.h
|
||||
Canvas *luax_checkcanvas(lua_State *L, int idx);
|
||||
int w_Canvas_renderTo(lua_State *L);
|
||||
int w_Canvas_getImageData(lua_State *L);
|
||||
int w_Canvas_setFilter(lua_State *L);
|
||||
int w_Canvas_getFilter(lua_State *L);
|
||||
int w_Canvas_setWrap(lua_State *L);
|
||||
int w_Canvas_getWrap(lua_State *L);
|
||||
int w_Canvas_clear(lua_State *L);
|
||||
int w_Canvas_getWidth(lua_State *L);
|
||||
int w_Canvas_getHeight(lua_State *L);
|
||||
extern "C" int luaopen_canvas(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_CANVAS_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_CANVAS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_CANVAS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Canvas.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
//see Canvas.h
|
||||
Canvas *luax_checkcanvas(lua_State *L, int idx);
|
||||
int w_Canvas_renderTo(lua_State *L);
|
||||
int w_Canvas_getImageData(lua_State *L);
|
||||
int w_Canvas_setFilter(lua_State *L);
|
||||
int w_Canvas_getFilter(lua_State *L);
|
||||
int w_Canvas_setWrap(lua_State *L);
|
||||
int w_Canvas_getWrap(lua_State *L);
|
||||
int w_Canvas_clear(lua_State *L);
|
||||
int w_Canvas_getWidth(lua_State *L);
|
||||
int w_Canvas_getHeight(lua_State *L);
|
||||
extern "C" int luaopen_canvas(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_CANVAS_H
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font *luax_checkfont(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Font>(L, idx, "Font", GRAPHICS_FONT_T);
|
||||
}
|
||||
|
||||
int w_Font_getHeight(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Font_getWidth(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
const char *str = luaL_checkstring(L, 2);
|
||||
try
|
||||
{
|
||||
lua_pushinteger(L, t->getWidth(str));
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Font_getWrap(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
const char *str = luaL_checkstring(L, 2);
|
||||
float wrap = (float) luaL_checknumber(L, 3);
|
||||
int max_width = 0, numlines = 0;
|
||||
try
|
||||
{
|
||||
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
|
||||
numlines = lines.size();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
lua_pushinteger(L, max_width);
|
||||
lua_pushinteger(L, numlines);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Font_setLineHeight(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
t->setLineHeight(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Font_getLineHeight(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getLineHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getHeight", w_Font_getHeight },
|
||||
{ "getWidth", w_Font_getWidth },
|
||||
{ "getWrap", w_Font_getWrap },
|
||||
{ "setLineHeight", w_Font_setLineHeight },
|
||||
{ "getLineHeight", w_Font_getLineHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_font(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Font", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font *luax_checkfont(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Font>(L, idx, "Font", GRAPHICS_FONT_T);
|
||||
}
|
||||
|
||||
int w_Font_getHeight(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Font_getWidth(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
const char *str = luaL_checkstring(L, 2);
|
||||
try
|
||||
{
|
||||
lua_pushinteger(L, t->getWidth(str));
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Font_getWrap(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
const char *str = luaL_checkstring(L, 2);
|
||||
float wrap = (float) luaL_checknumber(L, 3);
|
||||
int max_width = 0, numlines = 0;
|
||||
try
|
||||
{
|
||||
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
|
||||
numlines = lines.size();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
lua_pushinteger(L, max_width);
|
||||
lua_pushinteger(L, numlines);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Font_setLineHeight(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
t->setLineHeight(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Font_getLineHeight(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getLineHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getHeight", w_Font_getHeight },
|
||||
{ "getWidth", w_Font_getWidth },
|
||||
{ "getWrap", w_Font_getWrap },
|
||||
{ "setLineHeight", w_Font_setLineHeight },
|
||||
{ "getLineHeight", w_Font_getLineHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_font(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Font", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font *luax_checkfont(lua_State *L, int idx);
|
||||
int w_Font_getHeight(lua_State *L);
|
||||
int w_Font_getWidth(lua_State *L);
|
||||
int w_Font_getWrap(lua_State *L);
|
||||
int w_Font_setLineHeight(lua_State *L);
|
||||
int w_Font_getLineHeight(lua_State *L);
|
||||
extern "C" int luaopen_font(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font *luax_checkfont(lua_State *L, int idx);
|
||||
int w_Font_getHeight(lua_State *L);
|
||||
int w_Font_getWidth(lua_State *L);
|
||||
int w_Font_getWrap(lua_State *L);
|
||||
int w_Font_setLineHeight(lua_State *L);
|
||||
int w_Font_getLineHeight(lua_State *L);
|
||||
extern "C" int luaopen_font(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,120 +1,120 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Quad.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
#include "wrap_ParticleSystem.h"
|
||||
#include "wrap_Canvas.h"
|
||||
#include "wrap_PixelEffect.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
int w_checkMode(lua_State *L);
|
||||
int w_setMode(lua_State *L);
|
||||
int w_getMode(lua_State *L);
|
||||
int w_toggleFullscreen(lua_State *L);
|
||||
int w_reset(lua_State *L);
|
||||
int w_clear(lua_State *L);
|
||||
int w_present(lua_State *L);
|
||||
int w_setIcon(lua_State *L);
|
||||
int w_setCaption(lua_State *L);
|
||||
int w_getCaption(lua_State *L);
|
||||
int w_getWidth(lua_State *L);
|
||||
int w_getHeight(lua_State *L);
|
||||
int w_isCreated(lua_State *L);
|
||||
int w_setScissor(lua_State *L);
|
||||
int w_getScissor(lua_State *L);
|
||||
int w_defineMask(lua_State *L);
|
||||
int w_setMask(lua_State *L);
|
||||
int w_newImage(lua_State *L);
|
||||
int w_newQuad(lua_State *L);
|
||||
int w_newFrame(lua_State *L);
|
||||
int w_newFont1(lua_State *L);
|
||||
int w_newImageFont(lua_State *L);
|
||||
int w_newSpriteBatch(lua_State *L);
|
||||
int w_newParticleSystem(lua_State *L);
|
||||
int w_newCanvas(lua_State *L); // comments in function
|
||||
int w_newPixelEffect(lua_State *L);
|
||||
int w_setColor(lua_State *L);
|
||||
int w_getColor(lua_State *L);
|
||||
int w_setBackgroundColor(lua_State *L);
|
||||
int w_getBackgroundColor(lua_State *L);
|
||||
int w_setFont(lua_State *L);
|
||||
int w_getFont(lua_State *L);
|
||||
int w_setBlendMode(lua_State *L);
|
||||
int w_setColorMode(lua_State *L);
|
||||
int w_setDefaultImageFilter(lua_State *L);
|
||||
int w_getBlendMode(lua_State *L);
|
||||
int w_getColorMode(lua_State *L);
|
||||
int w_getDefaultImageFilter(lua_State *L);
|
||||
int w_setLineWidth(lua_State *L);
|
||||
int w_setLineStyle(lua_State *L);
|
||||
int w_setLine(lua_State *L);
|
||||
int w_getLineWidth(lua_State *L);
|
||||
int w_getLineStyle(lua_State *L);
|
||||
int w_setPointSize(lua_State *L);
|
||||
int w_setPointStyle(lua_State *L);
|
||||
int w_setPoint(lua_State *L);
|
||||
int w_getPointSize(lua_State *L);
|
||||
int w_getPointStyle(lua_State *L);
|
||||
int w_getMaxPointSize(lua_State *L);
|
||||
int w_newScreenshot(lua_State *L);
|
||||
int w_setCanvas(lua_State *L);
|
||||
int w_getCanvas(lua_State *L);
|
||||
int w_setPixelEffect(lua_State *L);
|
||||
int w_isSupported(lua_State *L);
|
||||
int w_draw(lua_State *L);
|
||||
int w_drawq(lua_State *L);
|
||||
int w_drawTest(lua_State *L);
|
||||
int w_print1(lua_State *L);
|
||||
int w_printf1(lua_State *L);
|
||||
int w_point(lua_State *L);
|
||||
int w_line(lua_State *L);
|
||||
int w_triangle(lua_State *L);
|
||||
int w_rectangle(lua_State *L);
|
||||
int w_quad(lua_State *L);
|
||||
int w_circle(lua_State *L);
|
||||
int w_arc(lua_State *L);
|
||||
int w_push(lua_State *L);
|
||||
int w_pop(lua_State *L);
|
||||
int w_rotate(lua_State *L);
|
||||
int w_scale(lua_State *L);
|
||||
int w_translate(lua_State *L);
|
||||
int w_shear(lua_State *L);
|
||||
int w_hasFocus(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Quad.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
#include "wrap_ParticleSystem.h"
|
||||
#include "wrap_Canvas.h"
|
||||
#include "wrap_PixelEffect.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
int w_checkMode(lua_State *L);
|
||||
int w_setMode(lua_State *L);
|
||||
int w_getMode(lua_State *L);
|
||||
int w_toggleFullscreen(lua_State *L);
|
||||
int w_reset(lua_State *L);
|
||||
int w_clear(lua_State *L);
|
||||
int w_present(lua_State *L);
|
||||
int w_setIcon(lua_State *L);
|
||||
int w_setCaption(lua_State *L);
|
||||
int w_getCaption(lua_State *L);
|
||||
int w_getWidth(lua_State *L);
|
||||
int w_getHeight(lua_State *L);
|
||||
int w_isCreated(lua_State *L);
|
||||
int w_setScissor(lua_State *L);
|
||||
int w_getScissor(lua_State *L);
|
||||
int w_defineMask(lua_State *L);
|
||||
int w_setMask(lua_State *L);
|
||||
int w_newImage(lua_State *L);
|
||||
int w_newQuad(lua_State *L);
|
||||
int w_newFrame(lua_State *L);
|
||||
int w_newFont1(lua_State *L);
|
||||
int w_newImageFont(lua_State *L);
|
||||
int w_newSpriteBatch(lua_State *L);
|
||||
int w_newParticleSystem(lua_State *L);
|
||||
int w_newCanvas(lua_State *L); // comments in function
|
||||
int w_newPixelEffect(lua_State *L);
|
||||
int w_setColor(lua_State *L);
|
||||
int w_getColor(lua_State *L);
|
||||
int w_setBackgroundColor(lua_State *L);
|
||||
int w_getBackgroundColor(lua_State *L);
|
||||
int w_setFont(lua_State *L);
|
||||
int w_getFont(lua_State *L);
|
||||
int w_setBlendMode(lua_State *L);
|
||||
int w_setColorMode(lua_State *L);
|
||||
int w_setDefaultImageFilter(lua_State *L);
|
||||
int w_getBlendMode(lua_State *L);
|
||||
int w_getColorMode(lua_State *L);
|
||||
int w_getDefaultImageFilter(lua_State *L);
|
||||
int w_setLineWidth(lua_State *L);
|
||||
int w_setLineStyle(lua_State *L);
|
||||
int w_setLine(lua_State *L);
|
||||
int w_getLineWidth(lua_State *L);
|
||||
int w_getLineStyle(lua_State *L);
|
||||
int w_setPointSize(lua_State *L);
|
||||
int w_setPointStyle(lua_State *L);
|
||||
int w_setPoint(lua_State *L);
|
||||
int w_getPointSize(lua_State *L);
|
||||
int w_getPointStyle(lua_State *L);
|
||||
int w_getMaxPointSize(lua_State *L);
|
||||
int w_newScreenshot(lua_State *L);
|
||||
int w_setCanvas(lua_State *L);
|
||||
int w_getCanvas(lua_State *L);
|
||||
int w_setPixelEffect(lua_State *L);
|
||||
int w_isSupported(lua_State *L);
|
||||
int w_draw(lua_State *L);
|
||||
int w_drawq(lua_State *L);
|
||||
int w_drawTest(lua_State *L);
|
||||
int w_print1(lua_State *L);
|
||||
int w_printf1(lua_State *L);
|
||||
int w_point(lua_State *L);
|
||||
int w_line(lua_State *L);
|
||||
int w_triangle(lua_State *L);
|
||||
int w_rectangle(lua_State *L);
|
||||
int w_quad(lua_State *L);
|
||||
int w_circle(lua_State *L);
|
||||
int w_arc(lua_State *L);
|
||||
int w_push(lua_State *L);
|
||||
int w_pop(lua_State *L);
|
||||
int w_rotate(lua_State *L);
|
||||
int w_scale(lua_State *L);
|
||||
int w_translate(lua_State *L);
|
||||
int w_shear(lua_State *L);
|
||||
int w_hasFocus(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
|
||||
@@ -1,136 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image *luax_checkimage(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Image>(L, idx, "Image", GRAPHICS_IMAGE_T);
|
||||
}
|
||||
|
||||
int w_Image_getWidth(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Image_getHeight(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Image_setFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
Image::Filter f;
|
||||
Image::FilterMode min;
|
||||
Image::FilterMode mag;
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_checkstring(L, 3);
|
||||
if (!Image::getConstant(minstr, min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
t->setFilter(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Image_getFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
Image::Filter f = t->getFilter();
|
||||
Image::FilterMode min = f.min;
|
||||
Image::FilterMode mag = f.mag;
|
||||
const char *minstr;
|
||||
const char *magstr;
|
||||
Image::getConstant(min, minstr);
|
||||
Image::getConstant(mag, magstr);
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Image_setWrap(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
Image::Wrap w;
|
||||
Image::WrapMode s;
|
||||
Image::WrapMode t;
|
||||
const char *sstr = luaL_checkstring(L, 2);
|
||||
const char *tstr = luaL_checkstring(L, 3);
|
||||
if (!Image::getConstant(sstr, s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", sstr);
|
||||
if (!Image::getConstant(tstr, t))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||
|
||||
w.s = s;
|
||||
w.t = t;
|
||||
i->setWrap(w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Image_getWrap(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
Image::Wrap w = i->getWrap();
|
||||
Image::WrapMode s = w.s;
|
||||
Image::WrapMode t = w.t;
|
||||
const char *sstr;
|
||||
const char *tstr;
|
||||
Image::getConstant(s, sstr);
|
||||
Image::getConstant(t, tstr);
|
||||
lua_pushstring(L, sstr);
|
||||
lua_pushstring(L, tstr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getWidth", w_Image_getWidth },
|
||||
{ "getHeight", w_Image_getHeight },
|
||||
{ "setFilter", w_Image_setFilter },
|
||||
{ "getFilter", w_Image_getFilter },
|
||||
{ "setWrap", w_Image_setWrap },
|
||||
{ "getWrap", w_Image_getWrap },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_image(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Image", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image *luax_checkimage(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Image>(L, idx, "Image", GRAPHICS_IMAGE_T);
|
||||
}
|
||||
|
||||
int w_Image_getWidth(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Image_getHeight(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Image_setFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
Image::Filter f;
|
||||
Image::FilterMode min;
|
||||
Image::FilterMode mag;
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_checkstring(L, 3);
|
||||
if (!Image::getConstant(minstr, min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
t->setFilter(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Image_getFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
Image::Filter f = t->getFilter();
|
||||
Image::FilterMode min = f.min;
|
||||
Image::FilterMode mag = f.mag;
|
||||
const char *minstr;
|
||||
const char *magstr;
|
||||
Image::getConstant(min, minstr);
|
||||
Image::getConstant(mag, magstr);
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Image_setWrap(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
Image::Wrap w;
|
||||
Image::WrapMode s;
|
||||
Image::WrapMode t;
|
||||
const char *sstr = luaL_checkstring(L, 2);
|
||||
const char *tstr = luaL_checkstring(L, 3);
|
||||
if (!Image::getConstant(sstr, s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", sstr);
|
||||
if (!Image::getConstant(tstr, t))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||
|
||||
w.s = s;
|
||||
w.t = t;
|
||||
i->setWrap(w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Image_getWrap(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
Image::Wrap w = i->getWrap();
|
||||
Image::WrapMode s = w.s;
|
||||
Image::WrapMode t = w.t;
|
||||
const char *sstr;
|
||||
const char *tstr;
|
||||
Image::getConstant(s, sstr);
|
||||
Image::getConstant(t, tstr);
|
||||
lua_pushstring(L, sstr);
|
||||
lua_pushstring(L, tstr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getWidth", w_Image_getWidth },
|
||||
{ "getHeight", w_Image_getHeight },
|
||||
{ "setFilter", w_Image_setFilter },
|
||||
{ "getFilter", w_Image_getFilter },
|
||||
{ "setWrap", w_Image_setWrap },
|
||||
{ "getWrap", w_Image_getWrap },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_image(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Image", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image *luax_checkimage(lua_State *L, int idx);
|
||||
int w_Image_getWidth(lua_State *L);
|
||||
int w_Image_getHeight(lua_State *L);
|
||||
int w_Image_setFilter(lua_State *L);
|
||||
extern "C" int luaopen_image(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image *luax_checkimage(lua_State *L, int idx);
|
||||
int w_Image_getWidth(lua_State *L);
|
||||
int w_Image_getHeight(lua_State *L);
|
||||
int w_Image_setFilter(lua_State *L);
|
||||
extern "C" int luaopen_image(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
|
||||
@@ -1,416 +1,416 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_ParticleSystem.h"
|
||||
|
||||
#include "common/Vector.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T);
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSprite(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
Image *i = luax_checkimage(L, 2);
|
||||
t->setSprite(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setBufferSize(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setBufferSize((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setEmissionRate(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setEmissionRate((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setLifetime(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLifetime(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setParticleLife(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setParticleLife(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setPosition(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setPosition(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setDirection(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpread(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpread(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setRelativeDirection(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
bool arg1 = (bool)luax_toboolean(L, 2);
|
||||
t->setRelativeDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpeed(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setSpeed(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setGravity(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setRadialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRadialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setTangentialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setTangentialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSizes(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
size_t nSizes = lua_gettop(L) - 1;
|
||||
|
||||
if (nSizes > 8)
|
||||
return luaL_error(L, "At most eight (8) sizes may be used.");
|
||||
|
||||
if (nSizes <= 1)
|
||||
{
|
||||
float size = luax_checkfloat(L, 2);
|
||||
t->setSize(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<float> sizes(nSizes);
|
||||
for (size_t i = 0; i < nSizes; ++i)
|
||||
sizes[i] = luax_checkfloat(L, 1 + i + 1);
|
||||
|
||||
t->setSize(sizes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSizeVariation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSizeVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setRotation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRotation(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpin(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
float arg3 = (float)luaL_optnumber(L, 4, 0);
|
||||
t->setSpin(arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpinVariation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpinVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setColors(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
int cargs = lua_gettop(L) - 1;
|
||||
size_t nColors = (cargs + 3) / 4; // nColors = ceil(color_args / 4)
|
||||
if (cargs % 4 != 0 || cargs == 0)
|
||||
return luaL_error(L, "Expected red, green, blue, and alpha. Only got %d of 4 components.", cargs % 4);
|
||||
|
||||
if (nColors > 8)
|
||||
return luaL_error(L, "At most eight (8) colors may be used.");
|
||||
|
||||
if (nColors == 1)
|
||||
{
|
||||
int r = luaL_checkint(L, 2);
|
||||
int g = luaL_checkint(L, 3);
|
||||
int b = luaL_checkint(L, 4);
|
||||
int a = luaL_checkint(L, 5);
|
||||
t->setColor(Color(r,g,b,a));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<Color> colors(nColors);
|
||||
for (size_t i = 0; i < nColors; ++i)
|
||||
{
|
||||
int r = luaL_checkint(L, 1 + i*4 + 1);
|
||||
int g = luaL_checkint(L, 1 + i*4 + 2);
|
||||
int b = luaL_checkint(L, 1 + i*4 + 3);
|
||||
int a = luaL_checkint(L, 1 + i*4 + 4);
|
||||
colors[i] = Color(r,g,b,a);
|
||||
}
|
||||
t->setColor(colors);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setOffset(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setOffset(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getX(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getY(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getPosition(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
const love::Vector &p = t->getPosition();
|
||||
lua_pushnumber(L, p.x);
|
||||
lua_pushnumber(L, p.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getDirection(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getDirection());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getSpread(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getSpread());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getOffsetX(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getOffsetX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getOffsetY(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getOffsetY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_count(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->count());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_start(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_stop(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_pause(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->pause();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_reset(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_isActive(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isActive());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_isEmpty(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isEmpty());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_isFull(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isFull());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_update(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setSprite", w_ParticleSystem_setSprite },
|
||||
{ "setBufferSize", w_ParticleSystem_setBufferSize },
|
||||
{ "setEmissionRate", w_ParticleSystem_setEmissionRate },
|
||||
{ "setLifetime", w_ParticleSystem_setLifetime },
|
||||
{ "setParticleLife", w_ParticleSystem_setParticleLife },
|
||||
{ "setPosition", w_ParticleSystem_setPosition },
|
||||
{ "setDirection", w_ParticleSystem_setDirection },
|
||||
{ "setSpread", w_ParticleSystem_setSpread },
|
||||
{ "setRelativeDirection", w_ParticleSystem_setRelativeDirection },
|
||||
{ "setSpeed", w_ParticleSystem_setSpeed },
|
||||
{ "setGravity", w_ParticleSystem_setGravity },
|
||||
{ "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
|
||||
{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
|
||||
{ "setSizes", w_ParticleSystem_setSizes },
|
||||
{ "setSizeVariation", w_ParticleSystem_setSizeVariation },
|
||||
{ "setRotation", w_ParticleSystem_setRotation },
|
||||
{ "setSpin", w_ParticleSystem_setSpin },
|
||||
{ "setSpinVariation", w_ParticleSystem_setSpinVariation },
|
||||
{ "setColors", w_ParticleSystem_setColors },
|
||||
{ "setOffset", w_ParticleSystem_setOffset },
|
||||
{ "getX", w_ParticleSystem_getX },
|
||||
{ "getY", w_ParticleSystem_getY },
|
||||
{ "getPosition", w_ParticleSystem_getPosition },
|
||||
{ "getDirection", w_ParticleSystem_getDirection },
|
||||
{ "getSpread", w_ParticleSystem_getSpread },
|
||||
{ "getOffsetX", w_ParticleSystem_getOffsetX },
|
||||
{ "getOffsetY", w_ParticleSystem_getOffsetY },
|
||||
{ "count", w_ParticleSystem_count },
|
||||
{ "start", w_ParticleSystem_start },
|
||||
{ "stop", w_ParticleSystem_stop },
|
||||
{ "pause", w_ParticleSystem_pause },
|
||||
{ "reset", w_ParticleSystem_reset },
|
||||
{ "isActive", w_ParticleSystem_isActive },
|
||||
{ "isEmpty", w_ParticleSystem_isEmpty },
|
||||
{ "isFull", w_ParticleSystem_isFull },
|
||||
{ "update", w_ParticleSystem_update },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_particlesystem(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "ParticleSystem", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_ParticleSystem.h"
|
||||
|
||||
#include "common/Vector.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T);
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSprite(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
Image *i = luax_checkimage(L, 2);
|
||||
t->setSprite(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setBufferSize(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setBufferSize((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setEmissionRate(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setEmissionRate((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setLifetime(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLifetime(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setParticleLife(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setParticleLife(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setPosition(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setPosition(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setDirection(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpread(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpread(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setRelativeDirection(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
bool arg1 = (bool)luax_toboolean(L, 2);
|
||||
t->setRelativeDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpeed(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setSpeed(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setGravity(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setRadialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRadialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setTangentialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setTangentialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSizes(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
size_t nSizes = lua_gettop(L) - 1;
|
||||
|
||||
if (nSizes > 8)
|
||||
return luaL_error(L, "At most eight (8) sizes may be used.");
|
||||
|
||||
if (nSizes <= 1)
|
||||
{
|
||||
float size = luax_checkfloat(L, 2);
|
||||
t->setSize(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<float> sizes(nSizes);
|
||||
for (size_t i = 0; i < nSizes; ++i)
|
||||
sizes[i] = luax_checkfloat(L, 1 + i + 1);
|
||||
|
||||
t->setSize(sizes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSizeVariation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSizeVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setRotation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRotation(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpin(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
float arg3 = (float)luaL_optnumber(L, 4, 0);
|
||||
t->setSpin(arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setSpinVariation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpinVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setColors(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
int cargs = lua_gettop(L) - 1;
|
||||
size_t nColors = (cargs + 3) / 4; // nColors = ceil(color_args / 4)
|
||||
if (cargs % 4 != 0 || cargs == 0)
|
||||
return luaL_error(L, "Expected red, green, blue, and alpha. Only got %d of 4 components.", cargs % 4);
|
||||
|
||||
if (nColors > 8)
|
||||
return luaL_error(L, "At most eight (8) colors may be used.");
|
||||
|
||||
if (nColors == 1)
|
||||
{
|
||||
int r = luaL_checkint(L, 2);
|
||||
int g = luaL_checkint(L, 3);
|
||||
int b = luaL_checkint(L, 4);
|
||||
int a = luaL_checkint(L, 5);
|
||||
t->setColor(Color(r,g,b,a));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<Color> colors(nColors);
|
||||
for (size_t i = 0; i < nColors; ++i)
|
||||
{
|
||||
int r = luaL_checkint(L, 1 + i*4 + 1);
|
||||
int g = luaL_checkint(L, 1 + i*4 + 2);
|
||||
int b = luaL_checkint(L, 1 + i*4 + 3);
|
||||
int a = luaL_checkint(L, 1 + i*4 + 4);
|
||||
colors[i] = Color(r,g,b,a);
|
||||
}
|
||||
t->setColor(colors);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setOffset(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setOffset(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getX(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getY(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getPosition(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
const love::Vector &p = t->getPosition();
|
||||
lua_pushnumber(L, p.x);
|
||||
lua_pushnumber(L, p.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getDirection(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getDirection());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getSpread(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getSpread());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getOffsetX(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getOffsetX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getOffsetY(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getOffsetY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_count(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->count());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_start(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_stop(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_pause(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->pause();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_reset(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
t->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_isActive(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isActive());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_isEmpty(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isEmpty());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_isFull(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isFull());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_update(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setSprite", w_ParticleSystem_setSprite },
|
||||
{ "setBufferSize", w_ParticleSystem_setBufferSize },
|
||||
{ "setEmissionRate", w_ParticleSystem_setEmissionRate },
|
||||
{ "setLifetime", w_ParticleSystem_setLifetime },
|
||||
{ "setParticleLife", w_ParticleSystem_setParticleLife },
|
||||
{ "setPosition", w_ParticleSystem_setPosition },
|
||||
{ "setDirection", w_ParticleSystem_setDirection },
|
||||
{ "setSpread", w_ParticleSystem_setSpread },
|
||||
{ "setRelativeDirection", w_ParticleSystem_setRelativeDirection },
|
||||
{ "setSpeed", w_ParticleSystem_setSpeed },
|
||||
{ "setGravity", w_ParticleSystem_setGravity },
|
||||
{ "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
|
||||
{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
|
||||
{ "setSizes", w_ParticleSystem_setSizes },
|
||||
{ "setSizeVariation", w_ParticleSystem_setSizeVariation },
|
||||
{ "setRotation", w_ParticleSystem_setRotation },
|
||||
{ "setSpin", w_ParticleSystem_setSpin },
|
||||
{ "setSpinVariation", w_ParticleSystem_setSpinVariation },
|
||||
{ "setColors", w_ParticleSystem_setColors },
|
||||
{ "setOffset", w_ParticleSystem_setOffset },
|
||||
{ "getX", w_ParticleSystem_getX },
|
||||
{ "getY", w_ParticleSystem_getY },
|
||||
{ "getPosition", w_ParticleSystem_getPosition },
|
||||
{ "getDirection", w_ParticleSystem_getDirection },
|
||||
{ "getSpread", w_ParticleSystem_getSpread },
|
||||
{ "getOffsetX", w_ParticleSystem_getOffsetX },
|
||||
{ "getOffsetY", w_ParticleSystem_getOffsetY },
|
||||
{ "count", w_ParticleSystem_count },
|
||||
{ "start", w_ParticleSystem_start },
|
||||
{ "stop", w_ParticleSystem_stop },
|
||||
{ "pause", w_ParticleSystem_pause },
|
||||
{ "reset", w_ParticleSystem_reset },
|
||||
{ "isActive", w_ParticleSystem_isActive },
|
||||
{ "isEmpty", w_ParticleSystem_isEmpty },
|
||||
{ "isFull", w_ParticleSystem_isFull },
|
||||
{ "update", w_ParticleSystem_update },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_particlesystem(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "ParticleSystem", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,79 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "ParticleSystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx);
|
||||
int w_ParticleSystem_setSprite(lua_State *L);
|
||||
int w_ParticleSystem_setBufferSize(lua_State *L);
|
||||
int w_ParticleSystem_setEmissionRate(lua_State *L);
|
||||
int w_ParticleSystem_setLifetime(lua_State *L);
|
||||
int w_ParticleSystem_setParticleLife(lua_State *L);
|
||||
int w_ParticleSystem_setPosition(lua_State *L);
|
||||
int w_ParticleSystem_setDirection(lua_State *L);
|
||||
int w_ParticleSystem_setSpread(lua_State *L);
|
||||
int w_ParticleSystem_setRelativeDirection(lua_State *L);
|
||||
int w_ParticleSystem_setSpeed(lua_State *L);
|
||||
int w_ParticleSystem_setGravity(lua_State *L);
|
||||
int w_ParticleSystem_setRadialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setTangentialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setSizes(lua_State *L);
|
||||
int w_ParticleSystem_setSizeVariation(lua_State *L);
|
||||
int w_ParticleSystem_setRotation(lua_State *L);
|
||||
int w_ParticleSystem_setSpin(lua_State *L);
|
||||
int w_ParticleSystem_setSpinVariation(lua_State *L);
|
||||
int w_ParticleSystem_setColors(lua_State *L);
|
||||
int w_ParticleSystem_setOffset(lua_State *L);
|
||||
int w_ParticleSystem_getX(lua_State *L);
|
||||
int w_ParticleSystem_getY(lua_State *L);
|
||||
int w_ParticleSystem_getPosition(lua_State *L);
|
||||
int w_ParticleSystem_getDirection(lua_State *L);
|
||||
int w_ParticleSystem_getSpread(lua_State *L);
|
||||
int w_ParticleSystem_getOffsetX(lua_State *L);
|
||||
int w_ParticleSystem_getOffsetY(lua_State *L);
|
||||
int w_ParticleSystem_count(lua_State *L);
|
||||
int w_ParticleSystem_start(lua_State *L);
|
||||
int w_ParticleSystem_stop(lua_State *L);
|
||||
int w_ParticleSystem_pause(lua_State *L);
|
||||
int w_ParticleSystem_reset(lua_State *L);
|
||||
int w_ParticleSystem_isActive(lua_State *L);
|
||||
int w_ParticleSystem_isEmpty(lua_State *L);
|
||||
int w_ParticleSystem_isFull(lua_State *L);
|
||||
int w_ParticleSystem_update(lua_State *L);
|
||||
extern "C" int luaopen_particlesystem(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "ParticleSystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx);
|
||||
int w_ParticleSystem_setSprite(lua_State *L);
|
||||
int w_ParticleSystem_setBufferSize(lua_State *L);
|
||||
int w_ParticleSystem_setEmissionRate(lua_State *L);
|
||||
int w_ParticleSystem_setLifetime(lua_State *L);
|
||||
int w_ParticleSystem_setParticleLife(lua_State *L);
|
||||
int w_ParticleSystem_setPosition(lua_State *L);
|
||||
int w_ParticleSystem_setDirection(lua_State *L);
|
||||
int w_ParticleSystem_setSpread(lua_State *L);
|
||||
int w_ParticleSystem_setRelativeDirection(lua_State *L);
|
||||
int w_ParticleSystem_setSpeed(lua_State *L);
|
||||
int w_ParticleSystem_setGravity(lua_State *L);
|
||||
int w_ParticleSystem_setRadialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setTangentialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setSizes(lua_State *L);
|
||||
int w_ParticleSystem_setSizeVariation(lua_State *L);
|
||||
int w_ParticleSystem_setRotation(lua_State *L);
|
||||
int w_ParticleSystem_setSpin(lua_State *L);
|
||||
int w_ParticleSystem_setSpinVariation(lua_State *L);
|
||||
int w_ParticleSystem_setColors(lua_State *L);
|
||||
int w_ParticleSystem_setOffset(lua_State *L);
|
||||
int w_ParticleSystem_getX(lua_State *L);
|
||||
int w_ParticleSystem_getY(lua_State *L);
|
||||
int w_ParticleSystem_getPosition(lua_State *L);
|
||||
int w_ParticleSystem_getDirection(lua_State *L);
|
||||
int w_ParticleSystem_getSpread(lua_State *L);
|
||||
int w_ParticleSystem_getOffsetX(lua_State *L);
|
||||
int w_ParticleSystem_getOffsetY(lua_State *L);
|
||||
int w_ParticleSystem_count(lua_State *L);
|
||||
int w_ParticleSystem_start(lua_State *L);
|
||||
int w_ParticleSystem_stop(lua_State *L);
|
||||
int w_ParticleSystem_pause(lua_State *L);
|
||||
int w_ParticleSystem_reset(lua_State *L);
|
||||
int w_ParticleSystem_isActive(lua_State *L);
|
||||
int w_ParticleSystem_isEmpty(lua_State *L);
|
||||
int w_ParticleSystem_isFull(lua_State *L);
|
||||
int w_ParticleSystem_update(lua_State *L);
|
||||
extern "C" int luaopen_particlesystem(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
|
||||
@@ -1,244 +1,244 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PixelEffect.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Canvas.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
PixelEffect *luax_checkpixeleffect(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<PixelEffect>(L, idx, "PixelEffect", GRAPHICS_PIXELEFFECT_T);
|
||||
}
|
||||
|
||||
int w_PixelEffect_getWarnings(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
lua_pushstring(L, effect->getWarnings().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _sendScalars(lua_State *L, PixelEffect *effect, const char *name, int count)
|
||||
{
|
||||
float *values = new float[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (!lua_isnumber(L, 3 + i))
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_typerror(L, 3 + i, "number");
|
||||
}
|
||||
values[i] = (float)lua_tonumber(L, 3 + i);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendFloat(name, 1, values, count);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _sendVectors(lua_State *L, PixelEffect *effect, const char *name, int count)
|
||||
{
|
||||
size_t dimension = lua_objlen(L, 3);
|
||||
float *values = new float[count * dimension];
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (!lua_istable(L, 3 + i))
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_typerror(L, 3 + i, "table");
|
||||
}
|
||||
if (lua_objlen(L, 3 + i) != dimension)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, "Error in argument %d: Expected table size %d, got %d.",
|
||||
3+i, dimension, lua_objlen(L, 3+i));
|
||||
}
|
||||
|
||||
for (size_t k = 1; k <= dimension; ++k)
|
||||
{
|
||||
lua_rawgeti(L, 3 + i, k);
|
||||
values[i * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
||||
}
|
||||
lua_pop(L, int(dimension));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendFloat(name, dimension, values, count);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendFloat(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
int count = lua_gettop(L) - 2;
|
||||
|
||||
if (count < 1)
|
||||
return luaL_error(L, "No variable to send.");
|
||||
|
||||
if (lua_isnumber(L, 3))
|
||||
return _sendScalars(L, effect, name, count);
|
||||
else if (lua_istable(L, 3))
|
||||
return _sendVectors(L, effect, name, count);
|
||||
|
||||
return luaL_typerror(L, 3, "number or table");
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendMatrix(lua_State *L)
|
||||
{
|
||||
int count = lua_gettop(L) - 2;
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
|
||||
if (!lua_istable(L, 3))
|
||||
return luaL_typerror(L, 3, "matrix table");
|
||||
|
||||
lua_getfield(L, 3, "dimension");
|
||||
int dimension = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (dimension < 2 || dimension > 4)
|
||||
return luaL_error(L, "Invalid matrix size: %dx%d (only 2x2, 3x3 and 4x4 matrices are supported).",
|
||||
count, count);
|
||||
|
||||
float *values = new float[dimension * dimension * count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
lua_getfield(L, 3+i, "dimension");
|
||||
if (lua_tointeger(L, -1) != dimension)
|
||||
{
|
||||
// You unlock this door with the key of imagination. Beyond it is
|
||||
// another dimension: a dimension of sound, a dimension of sight,
|
||||
// a dimension of mind. You're moving into a land of both shadow
|
||||
// and substance, of things and ideas. You've just crossed over
|
||||
// into... the Twilight Zone.
|
||||
int other_dimension = lua_tointeger(L, -1);
|
||||
delete[] values;
|
||||
return luaL_error(L, "Invalid matrix size at argument %d: Expected size %dx%d, got %dx%d.",
|
||||
3+i, dimension, dimension, other_dimension, other_dimension);
|
||||
}
|
||||
|
||||
for (int k = 1; k <= dimension*dimension; ++k)
|
||||
{
|
||||
lua_rawgeti(L, 3+i, k);
|
||||
values[i * dimension * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
||||
}
|
||||
|
||||
lua_pop(L, 1 + dimension);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendMatrix(name, dimension, values, count);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendImage(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
Image *img = luax_checkimage(L, 3);
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendImage(name, *img);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendCanvas(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
Canvas *canvas = luax_checkcanvas(L, 3);
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendCanvas(name, *canvas);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getWarnings", w_PixelEffect_getWarnings },
|
||||
{ "sendFloat", w_PixelEffect_sendFloat },
|
||||
{ "sendMatrix", w_PixelEffect_sendMatrix },
|
||||
{ "sendImage", w_PixelEffect_sendImage },
|
||||
{ "sendCanvas", w_PixelEffect_sendCanvas },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_pixeleffect(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PixelEffect", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PixelEffect.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Canvas.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
PixelEffect *luax_checkpixeleffect(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<PixelEffect>(L, idx, "PixelEffect", GRAPHICS_PIXELEFFECT_T);
|
||||
}
|
||||
|
||||
int w_PixelEffect_getWarnings(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
lua_pushstring(L, effect->getWarnings().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _sendScalars(lua_State *L, PixelEffect *effect, const char *name, int count)
|
||||
{
|
||||
float *values = new float[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (!lua_isnumber(L, 3 + i))
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_typerror(L, 3 + i, "number");
|
||||
}
|
||||
values[i] = (float)lua_tonumber(L, 3 + i);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendFloat(name, 1, values, count);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _sendVectors(lua_State *L, PixelEffect *effect, const char *name, int count)
|
||||
{
|
||||
size_t dimension = lua_objlen(L, 3);
|
||||
float *values = new float[count * dimension];
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (!lua_istable(L, 3 + i))
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_typerror(L, 3 + i, "table");
|
||||
}
|
||||
if (lua_objlen(L, 3 + i) != dimension)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, "Error in argument %d: Expected table size %d, got %d.",
|
||||
3+i, dimension, lua_objlen(L, 3+i));
|
||||
}
|
||||
|
||||
for (size_t k = 1; k <= dimension; ++k)
|
||||
{
|
||||
lua_rawgeti(L, 3 + i, k);
|
||||
values[i * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
||||
}
|
||||
lua_pop(L, int(dimension));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendFloat(name, dimension, values, count);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendFloat(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
int count = lua_gettop(L) - 2;
|
||||
|
||||
if (count < 1)
|
||||
return luaL_error(L, "No variable to send.");
|
||||
|
||||
if (lua_isnumber(L, 3))
|
||||
return _sendScalars(L, effect, name, count);
|
||||
else if (lua_istable(L, 3))
|
||||
return _sendVectors(L, effect, name, count);
|
||||
|
||||
return luaL_typerror(L, 3, "number or table");
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendMatrix(lua_State *L)
|
||||
{
|
||||
int count = lua_gettop(L) - 2;
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
|
||||
if (!lua_istable(L, 3))
|
||||
return luaL_typerror(L, 3, "matrix table");
|
||||
|
||||
lua_getfield(L, 3, "dimension");
|
||||
int dimension = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (dimension < 2 || dimension > 4)
|
||||
return luaL_error(L, "Invalid matrix size: %dx%d (only 2x2, 3x3 and 4x4 matrices are supported).",
|
||||
count, count);
|
||||
|
||||
float *values = new float[dimension * dimension * count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
lua_getfield(L, 3+i, "dimension");
|
||||
if (lua_tointeger(L, -1) != dimension)
|
||||
{
|
||||
// You unlock this door with the key of imagination. Beyond it is
|
||||
// another dimension: a dimension of sound, a dimension of sight,
|
||||
// a dimension of mind. You're moving into a land of both shadow
|
||||
// and substance, of things and ideas. You've just crossed over
|
||||
// into... the Twilight Zone.
|
||||
int other_dimension = lua_tointeger(L, -1);
|
||||
delete[] values;
|
||||
return luaL_error(L, "Invalid matrix size at argument %d: Expected size %dx%d, got %dx%d.",
|
||||
3+i, dimension, dimension, other_dimension, other_dimension);
|
||||
}
|
||||
|
||||
for (int k = 1; k <= dimension*dimension; ++k)
|
||||
{
|
||||
lua_rawgeti(L, 3+i, k);
|
||||
values[i * dimension * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
||||
}
|
||||
|
||||
lua_pop(L, 1 + dimension);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendMatrix(name, dimension, values, count);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
delete[] values;
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendImage(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
Image *img = luax_checkimage(L, 3);
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendImage(name, *img);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PixelEffect_sendCanvas(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
Canvas *canvas = luax_checkcanvas(L, 3);
|
||||
|
||||
try
|
||||
{
|
||||
effect->sendCanvas(name, *canvas);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getWarnings", w_PixelEffect_getWarnings },
|
||||
{ "sendFloat", w_PixelEffect_sendFloat },
|
||||
{ "sendMatrix", w_PixelEffect_sendMatrix },
|
||||
{ "sendImage", w_PixelEffect_sendImage },
|
||||
{ "sendCanvas", w_PixelEffect_sendCanvas },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_pixeleffect(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PixelEffect", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_PROGRAM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_PROGRAM_H
|
||||
|
||||
#include "common/runtime.h"
|
||||
#include "PixelEffect.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
PixelEffect *luax_checkpixeleffect(lua_State *L, int idx);
|
||||
int w_PixelEffect_getWarnings(lua_State *L);
|
||||
int w_PixelEffect_sendFloat(lua_State *L);
|
||||
int w_PixelEffect_sendMatrix(lua_State *L);
|
||||
int w_PixelEffect_sendImage(lua_State *L);
|
||||
extern "C" int luaopen_pixeleffect(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_PROGRAM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_PROGRAM_H
|
||||
|
||||
#include "common/runtime.h"
|
||||
#include "PixelEffect.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
PixelEffect *luax_checkpixeleffect(lua_State *L, int idx);
|
||||
int w_PixelEffect_getWarnings(lua_State *L);
|
||||
int w_PixelEffect_sendFloat(lua_State *L);
|
||||
int w_PixelEffect_sendMatrix(lua_State *L);
|
||||
int w_PixelEffect_sendImage(lua_State *L);
|
||||
extern "C" int luaopen_pixeleffect(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Quad *luax_checkframe(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Quad>(L, idx, "Quad", GRAPHICS_QUAD_T);
|
||||
}
|
||||
|
||||
int w_Quad_flip(lua_State *L)
|
||||
{
|
||||
Quad *quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
|
||||
quad->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Quad_setViewport(lua_State *L)
|
||||
{
|
||||
Quad *quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
|
||||
Quad::Viewport v;
|
||||
v.x = (float) luaL_checknumber(L, 2);
|
||||
v.y = (float) luaL_checknumber(L, 3);
|
||||
v.w = (float) luaL_checknumber(L, 4);
|
||||
v.h = (float) luaL_checknumber(L, 5);
|
||||
quad->setViewport(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Quad_getViewport(lua_State *L)
|
||||
{
|
||||
Quad *quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
|
||||
Quad::Viewport v = quad->getViewport();
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
lua_pushnumber(L, v.w);
|
||||
lua_pushnumber(L, v.h);
|
||||
return 4;
|
||||
}
|
||||
|
||||
static const luaL_Reg w_Quad_functions[] =
|
||||
{
|
||||
{ "flip", w_Quad_flip },
|
||||
{ "setViewport", w_Quad_setViewport },
|
||||
{ "getViewport", w_Quad_getViewport },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_frame(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Quad", w_Quad_functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Quad *luax_checkframe(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Quad>(L, idx, "Quad", GRAPHICS_QUAD_T);
|
||||
}
|
||||
|
||||
int w_Quad_flip(lua_State *L)
|
||||
{
|
||||
Quad *quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
|
||||
quad->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Quad_setViewport(lua_State *L)
|
||||
{
|
||||
Quad *quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
|
||||
Quad::Viewport v;
|
||||
v.x = (float) luaL_checknumber(L, 2);
|
||||
v.y = (float) luaL_checknumber(L, 3);
|
||||
v.w = (float) luaL_checknumber(L, 4);
|
||||
v.h = (float) luaL_checknumber(L, 5);
|
||||
quad->setViewport(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Quad_getViewport(lua_State *L)
|
||||
{
|
||||
Quad *quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
|
||||
Quad::Viewport v = quad->getViewport();
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
lua_pushnumber(L, v.w);
|
||||
lua_pushnumber(L, v.h);
|
||||
return 4;
|
||||
}
|
||||
|
||||
static const luaL_Reg w_Quad_functions[] =
|
||||
{
|
||||
{ "flip", w_Quad_flip },
|
||||
{ "setViewport", w_Quad_setViewport },
|
||||
{ "getViewport", w_Quad_getViewport },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_frame(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Quad", w_Quad_functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Quad *luax_checkframe(lua_State *L, int idx);
|
||||
int w_Quad_flip(lua_State *L);
|
||||
int w_Quad_setViewport(lua_State *L);
|
||||
int w_Quad_getViewport(lua_State *L);
|
||||
extern "C" int luaopen_frame(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Quad.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Quad *luax_checkframe(lua_State *L, int idx);
|
||||
int w_Quad_flip(lua_State *L);
|
||||
int w_Quad_setViewport(lua_State *L);
|
||||
int w_Quad_getViewport(lua_State *L);
|
||||
extern "C" int luaopen_frame(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
|
||||
|
||||
@@ -1,184 +1,184 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T);
|
||||
}
|
||||
|
||||
int w_SpriteBatch_add(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
float kx = (float)luaL_optnumber(L, 9, 0);
|
||||
float ky = (float)luaL_optnumber(L, 10, 0);
|
||||
lua_pushnumber(L, t->add(x, y, angle, sx, sy, ox, oy, kx, ky));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_addq(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Quad *q = luax_checktype<Quad>(L, 2, "Quad", GRAPHICS_QUAD_T);
|
||||
float x = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 6, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 7, sx);
|
||||
float ox = (float)luaL_optnumber(L, 8, 0);
|
||||
float oy = (float)luaL_optnumber(L, 9, 0);
|
||||
float kx = (float)luaL_optnumber(L, 10, 0);
|
||||
float ky = (float)luaL_optnumber(L, 11, 0);
|
||||
lua_pushnumber(L, t->addq(q, x, y, angle, sx, sy, ox, oy, kx, ky));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_set(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
int index = luaL_checkinteger(L, 2);
|
||||
float x = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 6, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 7, sx);
|
||||
float ox = (float)luaL_optnumber(L, 8, 0);
|
||||
float oy = (float)luaL_optnumber(L, 9, 0);
|
||||
float kx = (float)luaL_optnumber(L, 10, 0);
|
||||
float ky = (float)luaL_optnumber(L, 11, 0);
|
||||
t->add(x, y, angle, sx, sy, ox, oy, kx, ky, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_setq(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
int index = luaL_checkinteger(L, 2);
|
||||
Quad *q = luax_checktype<Quad>(L, 3, "Quad", GRAPHICS_QUAD_T);
|
||||
float x = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 6, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 7, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 8, sx);
|
||||
float ox = (float)luaL_optnumber(L, 9, 0);
|
||||
float oy = (float)luaL_optnumber(L, 10, 0);
|
||||
float kx = (float)luaL_optnumber(L, 11, 0);
|
||||
float ky = (float)luaL_optnumber(L, 12, 0);
|
||||
t->addq(q, x, y, angle, sx, sy, ox, oy, kx, ky, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int w_SpriteBatch_clear(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
t->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_bind(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
t->lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_unbind(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
t->unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_setImage(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Image *image = luax_checktype<Image>(L, 2, "Image", GRAPHICS_IMAGE_T);
|
||||
t->setImage(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_getImage(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Image *image = t->getImage();
|
||||
image->retain();
|
||||
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *)image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_setColor(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
|
||||
if (lua_gettop(L) <= 1)
|
||||
t->setColor();
|
||||
else
|
||||
{
|
||||
Color c;
|
||||
c.r = (unsigned char)luaL_checkint(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, 3);
|
||||
c.b = (unsigned char)luaL_checkint(L, 4);
|
||||
c.a = (unsigned char)luaL_optint(L, 5, 255);
|
||||
t->setColor(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "add", w_SpriteBatch_add },
|
||||
{ "addq", w_SpriteBatch_addq },
|
||||
{ "set", w_SpriteBatch_set },
|
||||
{ "setq", w_SpriteBatch_setq },
|
||||
{ "clear", w_SpriteBatch_clear },
|
||||
{ "bind", w_SpriteBatch_bind },
|
||||
{ "unbind", w_SpriteBatch_unbind },
|
||||
{ "setImage", w_SpriteBatch_setImage },
|
||||
{ "getImage", w_SpriteBatch_getImage },
|
||||
{ "setColor", w_SpriteBatch_setColor },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_spritebatch(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "SpriteBatch", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T);
|
||||
}
|
||||
|
||||
int w_SpriteBatch_add(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
float kx = (float)luaL_optnumber(L, 9, 0);
|
||||
float ky = (float)luaL_optnumber(L, 10, 0);
|
||||
lua_pushnumber(L, t->add(x, y, angle, sx, sy, ox, oy, kx, ky));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_addq(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Quad *q = luax_checktype<Quad>(L, 2, "Quad", GRAPHICS_QUAD_T);
|
||||
float x = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 6, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 7, sx);
|
||||
float ox = (float)luaL_optnumber(L, 8, 0);
|
||||
float oy = (float)luaL_optnumber(L, 9, 0);
|
||||
float kx = (float)luaL_optnumber(L, 10, 0);
|
||||
float ky = (float)luaL_optnumber(L, 11, 0);
|
||||
lua_pushnumber(L, t->addq(q, x, y, angle, sx, sy, ox, oy, kx, ky));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_set(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
int index = luaL_checkinteger(L, 2);
|
||||
float x = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 6, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 7, sx);
|
||||
float ox = (float)luaL_optnumber(L, 8, 0);
|
||||
float oy = (float)luaL_optnumber(L, 9, 0);
|
||||
float kx = (float)luaL_optnumber(L, 10, 0);
|
||||
float ky = (float)luaL_optnumber(L, 11, 0);
|
||||
t->add(x, y, angle, sx, sy, ox, oy, kx, ky, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_setq(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
int index = luaL_checkinteger(L, 2);
|
||||
Quad *q = luax_checktype<Quad>(L, 3, "Quad", GRAPHICS_QUAD_T);
|
||||
float x = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 6, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 7, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 8, sx);
|
||||
float ox = (float)luaL_optnumber(L, 9, 0);
|
||||
float oy = (float)luaL_optnumber(L, 10, 0);
|
||||
float kx = (float)luaL_optnumber(L, 11, 0);
|
||||
float ky = (float)luaL_optnumber(L, 12, 0);
|
||||
t->addq(q, x, y, angle, sx, sy, ox, oy, kx, ky, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int w_SpriteBatch_clear(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
t->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_bind(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
t->lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_unbind(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
t->unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_setImage(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Image *image = luax_checktype<Image>(L, 2, "Image", GRAPHICS_IMAGE_T);
|
||||
t->setImage(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_getImage(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Image *image = t->getImage();
|
||||
image->retain();
|
||||
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *)image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_SpriteBatch_setColor(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
|
||||
if (lua_gettop(L) <= 1)
|
||||
t->setColor();
|
||||
else
|
||||
{
|
||||
Color c;
|
||||
c.r = (unsigned char)luaL_checkint(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, 3);
|
||||
c.b = (unsigned char)luaL_checkint(L, 4);
|
||||
c.a = (unsigned char)luaL_optint(L, 5, 255);
|
||||
t->setColor(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "add", w_SpriteBatch_add },
|
||||
{ "addq", w_SpriteBatch_addq },
|
||||
{ "set", w_SpriteBatch_set },
|
||||
{ "setq", w_SpriteBatch_setq },
|
||||
{ "clear", w_SpriteBatch_clear },
|
||||
{ "bind", w_SpriteBatch_bind },
|
||||
{ "unbind", w_SpriteBatch_unbind },
|
||||
{ "setImage", w_SpriteBatch_setImage },
|
||||
{ "getImage", w_SpriteBatch_getImage },
|
||||
{ "setColor", w_SpriteBatch_setColor },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_spritebatch(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "SpriteBatch", functions);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
|
||||
#include "common/runtime.h"
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx);
|
||||
int w_SpriteBatch_add(lua_State *L);
|
||||
int w_SpriteBatch_addq(lua_State *L);
|
||||
int w_SpriteBatch_set(lua_State *L);
|
||||
int w_SpriteBatch_setq(lua_State *L);
|
||||
int w_SpriteBatch_clear(lua_State *L);
|
||||
int w_SpriteBatch_lock(lua_State *L);
|
||||
int w_SpriteBatch_unlock(lua_State *L);
|
||||
int w_SpriteBatch_setImage(lua_State *L);
|
||||
int w_SpriteBatch_getImage(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_spritebatch(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
|
||||
#include "common/runtime.h"
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx);
|
||||
int w_SpriteBatch_add(lua_State *L);
|
||||
int w_SpriteBatch_addq(lua_State *L);
|
||||
int w_SpriteBatch_set(lua_State *L);
|
||||
int w_SpriteBatch_setq(lua_State *L);
|
||||
int w_SpriteBatch_clear(lua_State *L);
|
||||
int w_SpriteBatch_lock(lua_State *L);
|
||||
int w_SpriteBatch_unlock(lua_State *L);
|
||||
int w_SpriteBatch_setImage(lua_State *L);
|
||||
int w_SpriteBatch_getImage(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_spritebatch(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
|
||||
Reference in New Issue
Block a user