mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-23 03:23:54 +00:00
More direct pixel functions.
This commit is contained in:
parent
593ac7b240
commit
a05046026e
3 changed files with 53 additions and 1 deletions
|
@ -7,7 +7,34 @@
|
|||
|
||||
using namespace Mangle::Rend2D;
|
||||
|
||||
// This is a really crappy and slow implementation
|
||||
const SpriteData *SDL_Sprite::lock()
|
||||
{
|
||||
// Make sure we aren't already locked
|
||||
assert(!data.pixels);
|
||||
|
||||
// Lock the surface and set up the data structure
|
||||
SDL_LockSurface(surface);
|
||||
|
||||
data.pixels = surface->pixels;
|
||||
data.w = surface->w;
|
||||
data.h = surface->h;
|
||||
data.pitch = surface->pitch;
|
||||
data.bypp = surface->format->BytesPerPixel;
|
||||
|
||||
return &data;
|
||||
}
|
||||
|
||||
void SDL_Sprite::unlock()
|
||||
{
|
||||
if(data.pixels)
|
||||
{
|
||||
SDL_UnlockSurface(surface);
|
||||
data.pixels = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// This is a really crappy and slow implementation, only intended for
|
||||
// testing purposes. Use lock/unlock for faster pixel drawing.
|
||||
void SDL_Sprite::pixel(int x, int y, int color)
|
||||
{
|
||||
SDL_LockSurface(surface);
|
||||
|
@ -83,6 +110,7 @@ SDL_Sprite::SDL_Sprite(SDL_Surface *s, bool autoDelete)
|
|||
: surface(s), autoDel(autoDelete)
|
||||
{
|
||||
assert(surface != NULL);
|
||||
data.pixels = NULL;
|
||||
}
|
||||
|
||||
SDL_Sprite::~SDL_Sprite()
|
||||
|
|
|
@ -37,10 +37,16 @@ namespace Mangle
|
|||
// Set one pixel
|
||||
void pixel(int x, int y, int value);
|
||||
|
||||
const SpriteData *lock();
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
// The SDL surface
|
||||
SDL_Surface* surface;
|
||||
|
||||
// Used for locking
|
||||
SpriteData data;
|
||||
|
||||
// If true, delete this surface when the canvas is destructed
|
||||
bool autoDel;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,17 @@ namespace Mangle
|
|||
{
|
||||
namespace Rend2D
|
||||
{
|
||||
/**
|
||||
A pointer to sprite data for direct drawing. Only to be used
|
||||
while the corresponding sprite is locked.
|
||||
*/
|
||||
struct SpriteData
|
||||
{
|
||||
void *pixels; // Pixel data
|
||||
int w, h; // Width and height
|
||||
int pitch, bypp; // Pitch (bytes) and bytes per pixel
|
||||
};
|
||||
|
||||
/**
|
||||
A Sprite is either a bitmap to be drawn or an output of area
|
||||
for blitting other bitmaps, or both. They are created by the
|
||||
|
@ -33,6 +44,13 @@ namespace Mangle
|
|||
/// format. This is not expected to be fast, and in some
|
||||
/// implementations may not work at all.
|
||||
virtual void pixel(int x, int y, int value) {}
|
||||
|
||||
/// Lock sprite for direct drawing, and return a struct
|
||||
/// containing the necessary pointer. When finished, unlock the
|
||||
/// sprite with unlock(). May return NULL, if so then direct
|
||||
/// drawing is not possible.
|
||||
virtual const SpriteData *lock() { return NULL; }
|
||||
virtual void unlock() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue