Commit 41d6633d authored by hybrid's avatar hybrid

Fix eol-style for all code files to CRLF for simpler file handling.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2528 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 3f924718
// Copyright (C) 2002-2009 Nikolaus Gebhardt / Thomas Alten // Copyright (C) 2002-2009 Nikolaus Gebhardt / Thomas Alten
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_BLIT_H_INCLUDED_ #ifndef _C_BLIT_H_INCLUDED_
#define _C_BLIT_H_INCLUDED_ #define _C_BLIT_H_INCLUDED_
#include "SoftwareDriver2_helper.h" #include "SoftwareDriver2_helper.h"
namespace irr namespace irr
{ {
struct SBlitJob struct SBlitJob
{ {
AbsRectangle Dest; AbsRectangle Dest;
AbsRectangle Source; AbsRectangle Source;
u32 argb; u32 argb;
void * src; void * src;
void * dst; void * dst;
s32 width; s32 width;
s32 height; s32 height;
u32 srcPitch; u32 srcPitch;
u32 dstPitch; u32 dstPitch;
u32 srcPixelMul; u32 srcPixelMul;
u32 dstPixelMul; u32 dstPixelMul;
}; };
// Bitfields Cohen Sutherland // Bitfields Cohen Sutherland
enum eClipCode enum eClipCode
{ {
CLIPCODE_EMPTY = 0, CLIPCODE_EMPTY = 0,
CLIPCODE_BOTTOM = 1, CLIPCODE_BOTTOM = 1,
CLIPCODE_TOP = 2, CLIPCODE_TOP = 2,
CLIPCODE_LEFT = 4, CLIPCODE_LEFT = 4,
CLIPCODE_RIGHT = 8 CLIPCODE_RIGHT = 8
}; };
inline u32 GetClipCode( const AbsRectangle &r, const core::position2d<s32> &p ) inline u32 GetClipCode( const AbsRectangle &r, const core::position2d<s32> &p )
{ {
u32 code = CLIPCODE_EMPTY; u32 code = CLIPCODE_EMPTY;
if ( p.X < r.x0 ) if ( p.X < r.x0 )
code = CLIPCODE_LEFT; code = CLIPCODE_LEFT;
else else
if ( p.X > r.x1 ) if ( p.X > r.x1 )
code = CLIPCODE_RIGHT; code = CLIPCODE_RIGHT;
if ( p.Y < r.y0 ) if ( p.Y < r.y0 )
code |= CLIPCODE_TOP; code |= CLIPCODE_TOP;
else else
if ( p.Y > r.y1 ) if ( p.Y > r.y1 )
code |= CLIPCODE_BOTTOM; code |= CLIPCODE_BOTTOM;
return code; return code;
} }
/*! /*!
Cohen Sutherland clipping Cohen Sutherland clipping
@return: 1 if valid @return: 1 if valid
*/ */
static int ClipLine(const AbsRectangle &clipping, static int ClipLine(const AbsRectangle &clipping,
core::position2d<s32> &p0, core::position2d<s32> &p0,
core::position2d<s32> &p1, core::position2d<s32> &p1,
const core::position2d<s32>& p0_in, const core::position2d<s32>& p0_in,
const core::position2d<s32>& p1_in) const core::position2d<s32>& p1_in)
{ {
u32 code0; u32 code0;
u32 code1; u32 code1;
u32 code; u32 code;
p0 = p0_in; p0 = p0_in;
p1 = p1_in; p1 = p1_in;
code0 = GetClipCode( clipping, p0 ); code0 = GetClipCode( clipping, p0 );
code1 = GetClipCode( clipping, p1 ); code1 = GetClipCode( clipping, p1 );
// trivial accepted // trivial accepted
while ( code0 | code1 ) while ( code0 | code1 )
{ {
s32 x=0; s32 x=0;
s32 y=0; s32 y=0;
// trivial reject // trivial reject
if ( code0 & code1 ) if ( code0 & code1 )
return 0; return 0;
if ( code0 ) if ( code0 )
{ {
// clip first point // clip first point
code = code0; code = code0;
} }
else else
{ {
// clip last point // clip last point
code = code1; code = code1;
} }
if ( (code & CLIPCODE_BOTTOM) == CLIPCODE_BOTTOM ) if ( (code & CLIPCODE_BOTTOM) == CLIPCODE_BOTTOM )
{ {
// clip bottom viewport // clip bottom viewport
y = clipping.y1; y = clipping.y1;
x = p0.X + ( p1.X - p0.X ) * ( y - p0.Y ) / ( p1.Y - p0.Y ); x = p0.X + ( p1.X - p0.X ) * ( y - p0.Y ) / ( p1.Y - p0.Y );
} }
else else
if ( (code & CLIPCODE_TOP) == CLIPCODE_TOP ) if ( (code & CLIPCODE_TOP) == CLIPCODE_TOP )
{ {
// clip to viewport // clip to viewport
y = clipping.y0; y = clipping.y0;
x = p0.X + ( p1.X - p0.X ) * ( y - p0.Y ) / ( p1.Y - p0.Y ); x = p0.X + ( p1.X - p0.X ) * ( y - p0.Y ) / ( p1.Y - p0.Y );
} }
else else
if ( (code & CLIPCODE_RIGHT) == CLIPCODE_RIGHT ) if ( (code & CLIPCODE_RIGHT) == CLIPCODE_RIGHT )
{ {
// clip right viewport // clip right viewport
x = clipping.x1; x = clipping.x1;
y = p0.Y + ( p1.Y - p0.Y ) * ( x - p0.X ) / ( p1.X - p0.X ); y = p0.Y + ( p1.Y - p0.Y ) * ( x - p0.X ) / ( p1.X - p0.X );
} }
else else
if ( (code & CLIPCODE_LEFT) == CLIPCODE_LEFT ) if ( (code & CLIPCODE_LEFT) == CLIPCODE_LEFT )
{ {
// clip left viewport // clip left viewport
x = clipping.x0; x = clipping.x0;
y = p0.Y + ( p1.Y - p0.Y ) * ( x - p0.X ) / ( p1.X - p0.X ); y = p0.Y + ( p1.Y - p0.Y ) * ( x - p0.X ) / ( p1.X - p0.X );
} }
if ( code == code0 ) if ( code == code0 )
{ {
// modify first point // modify first point
p0.X = x; p0.X = x;
p0.Y = y; p0.Y = y;
code0 = GetClipCode( clipping, p0 ); code0 = GetClipCode( clipping, p0 );
} }
else else
{ {
// modify second point // modify second point
p1.X = x; p1.X = x;
p1.Y = y; p1.Y = y;
code1 = GetClipCode( clipping, p1 ); code1 = GetClipCode( clipping, p1 );
} }
} }
return 1; return 1;
} }
/* /*
*/ */
inline void GetClip(AbsRectangle &clipping, video::IImage * t) inline void GetClip(AbsRectangle &clipping, video::IImage * t)
{ {
clipping.x0 = 0; clipping.x0 = 0;
clipping.y0 = 0; clipping.y0 = 0;
clipping.x1 = t->getDimension().Width - 1; clipping.x1 = t->getDimension().Width - 1;
clipping.y1 = t->getDimension().Height - 1; clipping.y1 = t->getDimension().Height - 1;
} }
/* /*
return alpha in [0;256] Granularity from 32-Bit ARGB return alpha in [0;256] Granularity from 32-Bit ARGB
add highbit alpha ( alpha > 127 ? + 1 ) add highbit alpha ( alpha > 127 ? + 1 )
*/ */
static inline u32 extractAlpha ( const u32 c ) static inline u32 extractAlpha ( const u32 c )
{ {
return ( c >> 24 ) + ( c >> 31 ); return ( c >> 24 ) + ( c >> 31 );
} }
/* /*
return alpha in [0;255] Granularity and 32-Bit ARGB return alpha in [0;255] Granularity and 32-Bit ARGB
add highbit alpha ( alpha > 127 ? + 1 ) add highbit alpha ( alpha > 127 ? + 1 )
*/ */
static inline u32 packAlpha ( const u32 c ) static inline u32 packAlpha ( const u32 c )
{ {
return (c > 127 ? c - 1 : c) << 24; return (c > 127 ? c - 1 : c) << 24;
} }
/*! /*!
Scale Color by (1/value) Scale Color by (1/value)
value 0 - 256 ( alpha ) value 0 - 256 ( alpha )
*/ */
inline u32 PixelLerp32 ( const u32 source, const u32 value ) inline u32 PixelLerp32 ( const u32 source, const u32 value )
{ {
u32 srcRB = source & 0x00FF00FF; u32 srcRB = source & 0x00FF00FF;
u32 srcXG = (source & 0xFF00FF00) >> 8; u32 srcXG = (source & 0xFF00FF00) >> 8;
srcRB *= value; srcRB *= value;
srcXG *= value; srcXG *= value;
srcRB >>= 8; srcRB >>= 8;
//srcXG >>= 8; //srcXG >>= 8;
srcXG &= 0xFF00FF00; srcXG &= 0xFF00FF00;
srcRB &= 0x00FF00FF; srcRB &= 0x00FF00FF;
return srcRB | srcXG; return srcRB | srcXG;
} }
/* /*
*/ */
static void RenderLine32_Decal(video::IImage *t, static void RenderLine32_Decal(video::IImage *t,
const core::position2d<s32> &p0, const core::position2d<s32> &p0,
const core::position2d<s32> &p1, const core::position2d<s32> &p1,
u32 argb ) u32 argb )
{ {
s32 dx = p1.X - p0.X; s32 dx = p1.X - p0.X;
s32 dy = p1.Y - p0.Y; s32 dy = p1.Y - p0.Y;
s32 c; s32 c;
s32 m; s32 m;
s32 d = 0; s32 d = 0;
s32 run; s32 run;
s32 xInc = 4; s32 xInc = 4;
s32 yInc = (s32) t->getPitch(); s32 yInc = (s32) t->getPitch();
if ( dx < 0 ) if ( dx < 0 )
{ {
xInc = -xInc; xInc = -xInc;
dx = -dx; dx = -dx;
} }
if ( dy < 0 ) if ( dy < 0 )
{ {
yInc = -yInc; yInc = -yInc;
dy = -dy; dy = -dy;
} }
u32 *dst; u32 *dst;
dst = (u32*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 2 ) ); dst = (u32*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 2 ) );
if ( dy > dx ) if ( dy > dx )
{ {
s32 tmp; s32 tmp;
tmp = dx; tmp = dx;
dx = dy; dx = dy;
dy = tmp; dy = tmp;
tmp = xInc; tmp = xInc;
xInc = yInc; xInc = yInc;
yInc = tmp; yInc = tmp;
} }
c = dx << 1; c = dx << 1;
m = dy << 1; m = dy << 1;
run = dx; run = dx;
while ( run ) while ( run )
{ {
*dst = argb; *dst = argb;
dst = (u32*) ( (u8*) dst + xInc ); // x += xInc dst = (u32*) ( (u8*) dst + xInc ); // x += xInc
d += m; d += m;
if ( d > dx ) if ( d > dx )
{ {
dst = (u32*) ( (u8*) dst + yInc ); // y += yInc dst = (u32*) ( (u8*) dst + yInc ); // y += yInc
d -= c; d -= c;
} }
run -= 1; run -= 1;
} }
t->unlock(); t->unlock();
} }
/* /*
*/ */
static void RenderLine32_Blend(video::IImage *t, static void RenderLine32_Blend(video::IImage *t,
const core::position2d<s32> &p0, const core::position2d<s32> &p0,
const core::position2d<s32> &p1, const core::position2d<s32> &p1,
u32 argb, u32 alpha) u32 argb, u32 alpha)
{ {
s32 dx = p1.X - p0.X; s32 dx = p1.X - p0.X;
s32 dy = p1.Y - p0.Y; s32 dy = p1.Y - p0.Y;
s32 c; s32 c;
s32 m; s32 m;
s32 d = 0; s32 d = 0;
s32 run; s32 run;
s32 xInc = 4; s32 xInc = 4;
s32 yInc = (s32) t->getPitch(); s32 yInc = (s32) t->getPitch();
if ( dx < 0 ) if ( dx < 0 )
{ {
xInc = -xInc; xInc = -xInc;
dx = -dx; dx = -dx;
} }
if ( dy < 0 ) if ( dy < 0 )
{ {
yInc = -yInc; yInc = -yInc;
dy = -dy; dy = -dy;
} }
u32 *dst; u32 *dst;
dst = (u32*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 2 ) ); dst = (u32*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 2 ) );
if ( dy > dx ) if ( dy > dx )
{ {
s32 tmp; s32 tmp;
tmp = dx; tmp = dx;
dx = dy; dx = dy;
dy = tmp; dy = tmp;
tmp = xInc; tmp = xInc;
xInc = yInc; xInc = yInc;
yInc = tmp; yInc = tmp;
} }
c = dx << 1; c = dx << 1;
m = dy << 1; m = dy << 1;
run = dx; run = dx;
const u32 packA = packAlpha ( alpha ); const u32 packA = packAlpha ( alpha );
while ( run ) while ( run )
{ {
*dst = packA | PixelBlend32( *dst, argb, alpha ); *dst = packA | PixelBlend32( *dst, argb, alpha );
dst = (u32*) ( (u8*) dst + xInc ); // x += xInc dst = (u32*) ( (u8*) dst + xInc ); // x += xInc
d += m; d += m;
if ( d > dx ) if ( d > dx )
{ {
dst = (u32*) ( (u8*) dst + yInc ); // y += yInc dst = (u32*) ( (u8*) dst + yInc ); // y += yInc
d -= c; d -= c;
} }
run -= 1; run -= 1;
} }
t->unlock(); t->unlock();
} }
/* /*
*/ */
static void RenderLine16_Decal(video::IImage *t, static void RenderLine16_Decal(video::IImage *t,
const core::position2d<s32> &p0, const core::position2d<s32> &p0,
const core::position2d<s32> &p1, const core::position2d<s32> &p1,
u32 argb ) u32 argb )
{ {
s32 dx = p1.X - p0.X; s32 dx = p1.X - p0.X;
s32 dy = p1.Y - p0.Y; s32 dy = p1.Y - p0.Y;
s32 c; s32 c;
s32 m; s32 m;
s32 d = 0; s32 d = 0;
s32 run; s32 run;
s32 xInc = 2; s32 xInc = 2;
s32 yInc = (s32) t->getPitch(); s32 yInc = (s32) t->getPitch();
if ( dx < 0 ) if ( dx < 0 )
{ {
xInc = -xInc; xInc = -xInc;
dx = -dx; dx = -dx;
} }
if ( dy < 0 ) if ( dy < 0 )
{ {
yInc = -yInc; yInc = -yInc;
dy = -dy; dy = -dy;
} }
u16 *dst; u16 *dst;
dst = (u16*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 1 ) ); dst = (u16*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 1 ) );
if ( dy > dx ) if ( dy > dx )
{ {
s32 tmp; s32 tmp;
tmp = dx; tmp = dx;
dx = dy; dx = dy;
dy = tmp; dy = tmp;
tmp = xInc; tmp = xInc;
xInc = yInc; xInc = yInc;
yInc = tmp; yInc = tmp;
} }
c = dx << 1; c = dx << 1;
m = dy << 1; m = dy << 1;
run = dx; run = dx;
while ( run ) while ( run )
{ {
*dst = (u16)argb; *dst = (u16)argb;
dst = (u16*) ( (u8*) dst + xInc ); // x += xInc dst = (u16*) ( (u8*) dst + xInc ); // x += xInc
d += m; d += m;
if ( d > dx ) if ( d > dx )
{ {
dst = (u16*) ( (u8*) dst + yInc ); // y += yInc dst = (u16*) ( (u8*) dst + yInc ); // y += yInc
d -= c; d -= c;
} }
run -= 1; run -= 1;
} }
t->unlock(); t->unlock();
} }
/* /*
*/ */
static void RenderLine16_Blend(video::IImage *t, static void RenderLine16_Blend(video::IImage *t,
const core::position2d<s32> &p0, const core::position2d<s32> &p0,
const core::position2d<s32> &p1, const core::position2d<s32> &p1,
u16 argb, u16 argb,
u16 alpha) u16 alpha)
{ {
s32 dx = p1.X - p0.X; s32 dx = p1.X - p0.X;
s32 dy = p1.Y - p0.Y; s32 dy = p1.Y - p0.Y;
s32 c; s32 c;
s32 m; s32 m;
s32 d = 0; s32 d = 0;
s32 run; s32 run;
s32 xInc = 2; s32 xInc = 2;
s32 yInc = (s32) t->getPitch(); s32 yInc = (s32) t->getPitch();
if ( dx < 0 ) if ( dx < 0 )
{ {
xInc = -xInc; xInc = -xInc;
dx = -dx; dx = -dx;
} }
if ( dy < 0 ) if ( dy < 0 )
{ {
yInc = -yInc; yInc = -yInc;
dy = -dy; dy = -dy;
} }
u16 *dst; u16 *dst;
dst = (u16*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 1 ) ); dst = (u16*) ( (u8*) t->lock() + ( p0.Y * t->getPitch() ) + ( p0.X << 1 ) );
if ( dy > dx ) if ( dy > dx )
{ {
s32 tmp; s32 tmp;
tmp = dx; tmp = dx;
dx = dy; dx = dy;
dy = tmp; dy = tmp;
tmp = xInc; tmp = xInc;
xInc = yInc; xInc = yInc;
yInc = tmp; yInc = tmp;
} }
c = dx << 1; c = dx << 1;
m = dy << 1; m = dy << 1;
run = dx; run = dx;
const u16 packA = alpha ? 0x8000 : 0; const u16 packA = alpha ? 0x8000 : 0;
while ( run ) while ( run )
{ {
*dst = packA | PixelBlend16( *dst, argb, alpha ); *dst = packA | PixelBlend16( *dst, argb, alpha );
dst = (u16*) ( (u8*) dst + xInc ); // x += xInc dst = (u16*) ( (u8*) dst + xInc ); // x += xInc
d += m; d += m;
if ( d > dx ) if ( d > dx )
{ {
dst = (u16*) ( (u8*) dst + yInc ); // y += yInc dst = (u16*) ( (u8*) dst + yInc ); // y += yInc
d -= c; d -= c;
} }
run -= 1; run -= 1;
} }
t->unlock(); t->unlock();
} }
/*! /*!
*/ */
static void executeBlit_TextureCopy_x_to_x( const SBlitJob * job ) static void executeBlit_TextureCopy_x_to_x( const SBlitJob * job )
{ {
const void *src = (void*) job->src; const void *src = (void*) job->src;
void *dst = (void*) job->dst; void *dst = (void*) job->dst;
const u32 widthPitch = job->width * job->dstPixelMul; const u32 widthPitch = job->width * job->dstPixelMul;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
memcpy( dst, src, widthPitch ); memcpy( dst, src, widthPitch );
src = (void*) ( (u8*) (src) + job->srcPitch ); src = (void*) ( (u8*) (src) + job->srcPitch );
dst = (void*) ( (u8*) (dst) + job->dstPitch ); dst = (void*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureCopy_32_to_16( const SBlitJob * job ) static void executeBlit_TextureCopy_32_to_16( const SBlitJob * job )
{ {
const u32 *src = static_cast<const u32*>(job->src); const u32 *src = static_cast<const u32*>(job->src);
u16 *dst = static_cast<u16*>(job->dst); u16 *dst = static_cast<u16*>(job->dst);
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
//16 bit Blitter depends on pre-multiplied color //16 bit Blitter depends on pre-multiplied color
const u32 s = PixelLerp32( src[dx] | 0xFF000000, extractAlpha( src[dx] ) ); const u32 s = PixelLerp32( src[dx] | 0xFF000000, extractAlpha( src[dx] ) );
dst[dx] = video::A8R8G8B8toA1R5G5B5( s ); dst[dx] = video::A8R8G8B8toA1R5G5B5( s );
} }
src = (u32*) ( (u8*) (src) + job->srcPitch ); src = (u32*) ( (u8*) (src) + job->srcPitch );
dst = (u16*) ( (u8*) (dst) + job->dstPitch ); dst = (u16*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureCopy_24_to_16( const SBlitJob * job ) static void executeBlit_TextureCopy_24_to_16( const SBlitJob * job )
{ {
const void *src = (void*) job->src; const void *src = (void*) job->src;
u16 *dst = (u16*) job->dst; u16 *dst = (u16*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
u8 * s = (u8*) src; u8 * s = (u8*) src;
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = video::RGBA16(s[0], s[1], s[2]); dst[dx] = video::RGBA16(s[0], s[1], s[2]);
s += 3; s += 3;
} }
src = (void*) ( (u8*) (src) + job->srcPitch ); src = (void*) ( (u8*) (src) + job->srcPitch );
dst = (u16*) ( (u8*) (dst) + job->dstPitch ); dst = (u16*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureCopy_16_to_32( const SBlitJob * job ) static void executeBlit_TextureCopy_16_to_32( const SBlitJob * job )
{ {
const u16 *src = (u16*) job->src; const u16 *src = (u16*) job->src;
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = video::A1R5G5B5toA8R8G8B8( src[dx] ); dst[dx] = video::A1R5G5B5toA8R8G8B8( src[dx] );
} }
src = (u16*) ( (u8*) (src) + job->srcPitch ); src = (u16*) ( (u8*) (src) + job->srcPitch );
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
static void executeBlit_TextureCopy_16_to_24( const SBlitJob * job ) static void executeBlit_TextureCopy_16_to_24( const SBlitJob * job )
{ {
const u16 *src = (u16*) job->src; const u16 *src = (u16*) job->src;
u8 *dst = (u8*) job->dst; u8 *dst = (u8*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
u32 colour = video::A1R5G5B5toA8R8G8B8( src[dx] ); u32 colour = video::A1R5G5B5toA8R8G8B8( src[dx] );
u8 * writeTo = &dst[dx * 3]; u8 * writeTo = &dst[dx * 3];
*writeTo++ = (colour >> 16)& 0xFF; *writeTo++ = (colour >> 16)& 0xFF;
*writeTo++ = (colour >> 8) & 0xFF; *writeTo++ = (colour >> 8) & 0xFF;
*writeTo++ = colour & 0xFF; *writeTo++ = colour & 0xFF;
} }
src = (u16*) ( (u8*) (src) + job->srcPitch ); src = (u16*) ( (u8*) (src) + job->srcPitch );
dst += job->dstPitch; dst += job->dstPitch;
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureCopy_24_to_32( const SBlitJob * job ) static void executeBlit_TextureCopy_24_to_32( const SBlitJob * job )
{ {
void *src = (void*) job->src; void *src = (void*) job->src;
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
u8 * s = (u8*) src; u8 * s = (u8*) src;
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = 0xFF000000 | s[0] << 16 | s[1] << 8 | s[2]; dst[dx] = 0xFF000000 | s[0] << 16 | s[1] << 8 | s[2];
s += 3; s += 3;
} }
src = (void*) ( (u8*) (src) + job->srcPitch ); src = (void*) ( (u8*) (src) + job->srcPitch );
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
static void executeBlit_TextureCopy_32_to_24( const SBlitJob * job ) static void executeBlit_TextureCopy_32_to_24( const SBlitJob * job )
{ {
const u32 * src = (u32*) job->src; const u32 * src = (u32*) job->src;
u8 * dst = (u8*) job->dst; u8 * dst = (u8*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
u8 * writeTo = &dst[dx * 3]; u8 * writeTo = &dst[dx * 3];
*writeTo++ = (src[dx] >> 16)& 0xFF; *writeTo++ = (src[dx] >> 16)& 0xFF;
*writeTo++ = (src[dx] >> 8) & 0xFF; *writeTo++ = (src[dx] >> 8) & 0xFF;
*writeTo++ = src[dx] & 0xFF; *writeTo++ = src[dx] & 0xFF;
} }
src = (u32*) ( (u8*) (src) + job->srcPitch ); src = (u32*) ( (u8*) (src) + job->srcPitch );
dst += job->dstPitch ; dst += job->dstPitch ;
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureBlend_16_to_16( const SBlitJob * job ) static void executeBlit_TextureBlend_16_to_16( const SBlitJob * job )
{ {
u32 dx; u32 dx;
s32 dy; s32 dy;
u32 *src = (u32*) job->src; u32 *src = (u32*) job->src;
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
const u32 rdx = job->width >> 1; const u32 rdx = job->width >> 1;
const u32 off = core::if_c_a_else_b( job->width & 1 ,job->width - 1, 0 ); const u32 off = core::if_c_a_else_b( job->width & 1 ,job->width - 1, 0 );
for ( dy = 0; dy != job->height; ++dy ) for ( dy = 0; dy != job->height; ++dy )
{ {
for ( dx = 0; dx != rdx; ++dx ) for ( dx = 0; dx != rdx; ++dx )
{ {
dst[dx] = PixelBlend16_simd( dst[dx], src[dx] ); dst[dx] = PixelBlend16_simd( dst[dx], src[dx] );
} }
if ( off ) if ( off )
{ {
((u16*) dst)[off] = PixelBlend16( ((u16*) dst)[off], ((u16*) src)[off] ); ((u16*) dst)[off] = PixelBlend16( ((u16*) dst)[off], ((u16*) src)[off] );
} }
src = (u32*) ( (u8*) (src) + job->srcPitch ); src = (u32*) ( (u8*) (src) + job->srcPitch );
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureBlend_32_to_32( const SBlitJob * job ) static void executeBlit_TextureBlend_32_to_32( const SBlitJob * job )
{ {
u32 *src = (u32*) job->src; u32 *src = (u32*) job->src;
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = PixelBlend32( dst[dx], src[dx] ); dst[dx] = PixelBlend32( dst[dx], src[dx] );
} }
src = (u32*) ( (u8*) (src) + job->srcPitch ); src = (u32*) ( (u8*) (src) + job->srcPitch );
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureBlendColor_16_to_16( const SBlitJob * job ) static void executeBlit_TextureBlendColor_16_to_16( const SBlitJob * job )
{ {
u16 *src = (u16*) job->src; u16 *src = (u16*) job->src;
u16 *dst = (u16*) job->dst; u16 *dst = (u16*) job->dst;
u16 blend = video::A8R8G8B8toA1R5G5B5 ( job->argb ); u16 blend = video::A8R8G8B8toA1R5G5B5 ( job->argb );
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
if ( 0 == (src[dx] & 0x8000) ) if ( 0 == (src[dx] & 0x8000) )
continue; continue;
dst[dx] = PixelMul16_2( src[dx], blend ); dst[dx] = PixelMul16_2( src[dx], blend );
} }
src = (u16*) ( (u8*) (src) + job->srcPitch ); src = (u16*) ( (u8*) (src) + job->srcPitch );
dst = (u16*) ( (u8*) (dst) + job->dstPitch ); dst = (u16*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_TextureBlendColor_32_to_32( const SBlitJob * job ) static void executeBlit_TextureBlendColor_32_to_32( const SBlitJob * job )
{ {
u32 *src = (u32*) job->src; u32 *src = (u32*) job->src;
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = PixelBlend32( dst[dx], PixelMul32_2( src[dx], job->argb ) ); dst[dx] = PixelBlend32( dst[dx], PixelMul32_2( src[dx], job->argb ) );
} }
src = (u32*) ( (u8*) (src) + job->srcPitch ); src = (u32*) ( (u8*) (src) + job->srcPitch );
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_Color_16_to_16( const SBlitJob * job ) static void executeBlit_Color_16_to_16( const SBlitJob * job )
{ {
u16 *dst = (u16*) job->dst; u16 *dst = (u16*) job->dst;
u16 c0 = video::A8R8G8B8toA1R5G5B5( job->argb ); u16 c0 = video::A8R8G8B8toA1R5G5B5( job->argb );
u32 c = c0 | c0 << 16; u32 c = c0 | c0 << 16;
if ( 0 == (job->srcPitch & 3 ) ) if ( 0 == (job->srcPitch & 3 ) )
{ {
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
memset32( dst, c, job->srcPitch ); memset32( dst, c, job->srcPitch );
dst = (u16*) ( (u8*) (dst) + job->dstPitch ); dst = (u16*) ( (u8*) (dst) + job->dstPitch );
} }
} }
else else
{ {
s32 dx = job->width - 1; s32 dx = job->width - 1;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
memset32( dst, c, job->srcPitch ); memset32( dst, c, job->srcPitch );
dst[dx] = c0; dst[dx] = c0;
dst = (u16*) ( (u8*) (dst) + job->dstPitch ); dst = (u16*) ( (u8*) (dst) + job->dstPitch );
} }
} }
} }
/*! /*!
*/ */
static void executeBlit_Color_32_to_32( const SBlitJob * job ) static void executeBlit_Color_32_to_32( const SBlitJob * job )
{ {
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
memset32( dst, job->argb, job->srcPitch ); memset32( dst, job->argb, job->srcPitch );
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_ColorAlpha_16_to_16( const SBlitJob * job ) static void executeBlit_ColorAlpha_16_to_16( const SBlitJob * job )
{ {
u16 *dst = (u16*) job->dst; u16 *dst = (u16*) job->dst;
const u16 alpha = extractAlpha( job->argb ) >> 3; const u16 alpha = extractAlpha( job->argb ) >> 3;
if ( 0 == alpha ) if ( 0 == alpha )
return; return;
const u32 src = video::A8R8G8B8toA1R5G5B5( job->argb ); const u32 src = video::A8R8G8B8toA1R5G5B5( job->argb );
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = 0x8000 | PixelBlend16( dst[dx], src, alpha ); dst[dx] = 0x8000 | PixelBlend16( dst[dx], src, alpha );
} }
dst = (u16*) ( (u8*) (dst) + job->dstPitch ); dst = (u16*) ( (u8*) (dst) + job->dstPitch );
} }
} }
/*! /*!
*/ */
static void executeBlit_ColorAlpha_32_to_32( const SBlitJob * job ) static void executeBlit_ColorAlpha_32_to_32( const SBlitJob * job )
{ {
u32 *dst = (u32*) job->dst; u32 *dst = (u32*) job->dst;
const u32 alpha = extractAlpha( job->argb ); const u32 alpha = extractAlpha( job->argb );
const u32 src = job->argb; const u32 src = job->argb;
for ( s32 dy = 0; dy != job->height; ++dy ) for ( s32 dy = 0; dy != job->height; ++dy )
{ {
for ( s32 dx = 0; dx != job->width; ++dx ) for ( s32 dx = 0; dx != job->width; ++dx )
{ {
dst[dx] = (job->argb & 0xFF000000 ) | PixelBlend32( dst[dx], src, alpha ); dst[dx] = (job->argb & 0xFF000000 ) | PixelBlend32( dst[dx], src, alpha );
} }
dst = (u32*) ( (u8*) (dst) + job->dstPitch ); dst = (u32*) ( (u8*) (dst) + job->dstPitch );
} }
} }
// Blitter Operation // Blitter Operation
enum eBlitter enum eBlitter
{ {
BLITTER_INVALID = 0, BLITTER_INVALID = 0,
BLITTER_COLOR, BLITTER_COLOR,
BLITTER_COLOR_ALPHA, BLITTER_COLOR_ALPHA,
BLITTER_TEXTURE, BLITTER_TEXTURE,
BLITTER_TEXTURE_ALPHA_BLEND, BLITTER_TEXTURE_ALPHA_BLEND,
BLITTER_TEXTURE_ALPHA_COLOR_BLEND BLITTER_TEXTURE_ALPHA_COLOR_BLEND
}; };
typedef void (*tExecuteBlit) ( const SBlitJob * job ); typedef void (*tExecuteBlit) ( const SBlitJob * job );
/*! /*!
*/ */
struct blitterTable struct blitterTable
{ {
eBlitter operation; eBlitter operation;
s32 destFormat; s32 destFormat;
s32 sourceFormat; s32 sourceFormat;
tExecuteBlit func; tExecuteBlit func;
}; };
static const blitterTable blitTable[] = static const blitterTable blitTable[] =
{ {
{ BLITTER_TEXTURE, -2, -2, executeBlit_TextureCopy_x_to_x }, { BLITTER_TEXTURE, -2, -2, executeBlit_TextureCopy_x_to_x },
{ BLITTER_TEXTURE, video::ECF_A1R5G5B5, video::ECF_A8R8G8B8, executeBlit_TextureCopy_32_to_16 }, { BLITTER_TEXTURE, video::ECF_A1R5G5B5, video::ECF_A8R8G8B8, executeBlit_TextureCopy_32_to_16 },
{ BLITTER_TEXTURE, video::ECF_A1R5G5B5, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_16 }, { BLITTER_TEXTURE, video::ECF_A1R5G5B5, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_16 },
{ BLITTER_TEXTURE, video::ECF_A8R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCopy_16_to_32 }, { BLITTER_TEXTURE, video::ECF_A8R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCopy_16_to_32 },
{ BLITTER_TEXTURE, video::ECF_A8R8G8B8, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_32 }, { BLITTER_TEXTURE, video::ECF_A8R8G8B8, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_32 },
{ BLITTER_TEXTURE, video::ECF_R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCopy_16_to_24 }, { BLITTER_TEXTURE, video::ECF_R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCopy_16_to_24 },
{ BLITTER_TEXTURE, video::ECF_R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureCopy_32_to_24 }, { BLITTER_TEXTURE, video::ECF_R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureCopy_32_to_24 },
{ BLITTER_TEXTURE_ALPHA_BLEND, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureBlend_16_to_16 }, { BLITTER_TEXTURE_ALPHA_BLEND, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureBlend_16_to_16 },
{ BLITTER_TEXTURE_ALPHA_BLEND, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureBlend_32_to_32 }, { BLITTER_TEXTURE_ALPHA_BLEND, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureBlend_32_to_32 },
{ BLITTER_TEXTURE_ALPHA_COLOR_BLEND, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureBlendColor_16_to_16 }, { BLITTER_TEXTURE_ALPHA_COLOR_BLEND, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureBlendColor_16_to_16 },
{ BLITTER_TEXTURE_ALPHA_COLOR_BLEND, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureBlendColor_32_to_32 }, { BLITTER_TEXTURE_ALPHA_COLOR_BLEND, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureBlendColor_32_to_32 },
{ BLITTER_COLOR, video::ECF_A1R5G5B5, -1, executeBlit_Color_16_to_16 }, { BLITTER_COLOR, video::ECF_A1R5G5B5, -1, executeBlit_Color_16_to_16 },
{ BLITTER_COLOR, video::ECF_A8R8G8B8, -1, executeBlit_Color_32_to_32 }, { BLITTER_COLOR, video::ECF_A8R8G8B8, -1, executeBlit_Color_32_to_32 },
{ BLITTER_COLOR_ALPHA, video::ECF_A1R5G5B5, -1, executeBlit_ColorAlpha_16_to_16 }, { BLITTER_COLOR_ALPHA, video::ECF_A1R5G5B5, -1, executeBlit_ColorAlpha_16_to_16 },
{ BLITTER_COLOR_ALPHA, video::ECF_A8R8G8B8, -1, executeBlit_ColorAlpha_32_to_32 }, { BLITTER_COLOR_ALPHA, video::ECF_A8R8G8B8, -1, executeBlit_ColorAlpha_32_to_32 },
{ BLITTER_INVALID, -1, -1, 0 } { BLITTER_INVALID, -1, -1, 0 }
}; };
static inline tExecuteBlit getBlitter2( eBlitter operation,const video::IImage * dest,const video::IImage * source ) static inline tExecuteBlit getBlitter2( eBlitter operation,const video::IImage * dest,const video::IImage * source )
{ {
video::ECOLOR_FORMAT sourceFormat = (video::ECOLOR_FORMAT) ( source ? source->getColorFormat() : -1 ); video::ECOLOR_FORMAT sourceFormat = (video::ECOLOR_FORMAT) ( source ? source->getColorFormat() : -1 );
video::ECOLOR_FORMAT destFormat = (video::ECOLOR_FORMAT) ( dest ? dest->getColorFormat() : -1 ); video::ECOLOR_FORMAT destFormat = (video::ECOLOR_FORMAT) ( dest ? dest->getColorFormat() : -1 );
const blitterTable * b = blitTable; const blitterTable * b = blitTable;
while ( b->operation != BLITTER_INVALID ) while ( b->operation != BLITTER_INVALID )
{ {
if ( b->operation == operation ) if ( b->operation == operation )
{ {
if (( b->destFormat == -1 || b->destFormat == destFormat ) && if (( b->destFormat == -1 || b->destFormat == destFormat ) &&
( b->sourceFormat == -1 || b->sourceFormat == sourceFormat ) ) ( b->sourceFormat == -1 || b->sourceFormat == sourceFormat ) )
return b->func; return b->func;
else else
if ( b->destFormat == -2 && ( sourceFormat == destFormat ) ) if ( b->destFormat == -2 && ( sourceFormat == destFormat ) )
return b->func; return b->func;
} }
b += 1; b += 1;
} }
return 0; return 0;
} }
// bounce clipping to texture // bounce clipping to texture
inline void setClip ( AbsRectangle &out, const core::rect<s32> *clip, inline void setClip ( AbsRectangle &out, const core::rect<s32> *clip,
const video::IImage * tex, s32 passnative ) const video::IImage * tex, s32 passnative )
{ {
if ( clip && 0 == tex && passnative ) if ( clip && 0 == tex && passnative )
{ {
out.x0 = clip->UpperLeftCorner.X; out.x0 = clip->UpperLeftCorner.X;
out.x1 = clip->LowerRightCorner.X; out.x1 = clip->LowerRightCorner.X;
out.y0 = clip->UpperLeftCorner.Y; out.y0 = clip->UpperLeftCorner.Y;
out.y1 = clip->LowerRightCorner.Y; out.y1 = clip->LowerRightCorner.Y;
return; return;
} }
const s32 w = tex ? tex->getDimension().Width : 0; const s32 w = tex ? tex->getDimension().Width : 0;
const s32 h = tex ? tex->getDimension().Height : 0; const s32 h = tex ? tex->getDimension().Height : 0;
if ( clip ) if ( clip )
{ {
out.x0 = core::s32_clamp ( clip->UpperLeftCorner.X, 0, w ); out.x0 = core::s32_clamp ( clip->UpperLeftCorner.X, 0, w );
out.x1 = core::s32_clamp ( clip->LowerRightCorner.X, out.x0, w ); out.x1 = core::s32_clamp ( clip->LowerRightCorner.X, out.x0, w );
out.y0 = core::s32_clamp ( clip->UpperLeftCorner.Y, 0, h ); out.y0 = core::s32_clamp ( clip->UpperLeftCorner.Y, 0, h );
out.y1 = core::s32_clamp ( clip->LowerRightCorner.Y, out.y0, h ); out.y1 = core::s32_clamp ( clip->LowerRightCorner.Y, out.y0, h );
} }
else else
{ {
out.x0 = 0; out.x0 = 0;
out.y0 = 0; out.y0 = 0;
out.x1 = w; out.x1 = w;
out.y1 = h; out.y1 = h;
} }
} }
/*! /*!
a generic 2D Blitter a generic 2D Blitter
*/ */
static s32 Blit(eBlitter operation, static s32 Blit(eBlitter operation,
video::IImage * dest, video::IImage * dest,
const core::rect<s32> *destClipping, const core::rect<s32> *destClipping,
const core::position2d<s32> *destPos, const core::position2d<s32> *destPos,
video::IImage * const source, video::IImage * const source,
const core::rect<s32> *sourceClipping, const core::rect<s32> *sourceClipping,
u32 argb) u32 argb)
{ {
tExecuteBlit blitter = getBlitter2( operation, dest, source ); tExecuteBlit blitter = getBlitter2( operation, dest, source );
if ( 0 == blitter ) if ( 0 == blitter )
{ {
return 0; return 0;
} }
// Clipping // Clipping
AbsRectangle sourceClip; AbsRectangle sourceClip;
AbsRectangle destClip; AbsRectangle destClip;
AbsRectangle v; AbsRectangle v;
SBlitJob job; SBlitJob job;
setClip ( sourceClip, sourceClipping, source, 1 ); setClip ( sourceClip, sourceClipping, source, 1 );
setClip ( destClip, destClipping, dest, 0 ); setClip ( destClip, destClipping, dest, 0 );
v.x0 = destPos ? destPos->X : 0; v.x0 = destPos ? destPos->X : 0;
v.y0 = destPos ? destPos->Y : 0; v.y0 = destPos ? destPos->Y : 0;
v.x1 = v.x0 + ( sourceClip.x1 - sourceClip.x0 ); v.x1 = v.x0 + ( sourceClip.x1 - sourceClip.x0 );
v.y1 = v.y0 + ( sourceClip.y1 - sourceClip.y0 ); v.y1 = v.y0 + ( sourceClip.y1 - sourceClip.y0 );
if ( !intersect( job.Dest, destClip, v ) ) if ( !intersect( job.Dest, destClip, v ) )
return 0; return 0;
job.width = job.Dest.x1 - job.Dest.x0; job.width = job.Dest.x1 - job.Dest.x0;
job.height = job.Dest.y1 - job.Dest.y0; job.height = job.Dest.y1 - job.Dest.y0;
job.Source.x0 = sourceClip.x0 + ( job.Dest.x0 - v.x0 ); job.Source.x0 = sourceClip.x0 + ( job.Dest.x0 - v.x0 );
job.Source.x1 = job.Source.x0 + job.width; job.Source.x1 = job.Source.x0 + job.width;
job.Source.y0 = sourceClip.y0 + ( job.Dest.y0 - v.y0 ); job.Source.y0 = sourceClip.y0 + ( job.Dest.y0 - v.y0 );
job.Source.y1 = job.Source.y0 + job.height; job.Source.y1 = job.Source.y0 + job.height;
job.argb = argb; job.argb = argb;
if ( source ) if ( source )
{ {
job.srcPitch = source->getPitch(); job.srcPitch = source->getPitch();
job.srcPixelMul = source->getBytesPerPixel(); job.srcPixelMul = source->getBytesPerPixel();
job.src = (void*) ( (u8*) source->lock() + ( job.Source.y0 * job.srcPitch ) + ( job.Source.x0 * job.srcPixelMul ) ); job.src = (void*) ( (u8*) source->lock() + ( job.Source.y0 * job.srcPitch ) + ( job.Source.x0 * job.srcPixelMul ) );
} }
else else
{ {
// use srcPitch for color operation on dest // use srcPitch for color operation on dest
job.srcPitch = job.width * dest->getBytesPerPixel(); job.srcPitch = job.width * dest->getBytesPerPixel();
} }
job.dstPitch = dest->getPitch(); job.dstPitch = dest->getPitch();
job.dstPixelMul = dest->getBytesPerPixel(); job.dstPixelMul = dest->getBytesPerPixel();
job.dst = (void*) ( (u8*) dest->lock() + ( job.Dest.y0 * job.dstPitch ) + ( job.Dest.x0 * job.dstPixelMul ) ); job.dst = (void*) ( (u8*) dest->lock() + ( job.Dest.y0 * job.dstPitch ) + ( job.Dest.x0 * job.dstPixelMul ) );
blitter( &job ); blitter( &job );
if ( source ) if ( source )
source->unlock(); source->unlock();
if ( dest ) if ( dest )
dest->unlock(); dest->unlock();
return 1; return 1;
} }
} }
#endif #endif
...@@ -71,8 +71,8 @@ public: ...@@ -71,8 +71,8 @@ public:
virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type); virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type);
//! Creates the image list from the given texture. //! Creates the image list from the given texture.
virtual IGUIImageList* createImageList( video::ITexture* texture, virtual IGUIImageList* createImageList( video::ITexture* texture,
core::dimension2d<s32> imageSize, bool useAlphaChannel ); core::dimension2d<s32> imageSize, bool useAlphaChannel );
//! returns the font //! returns the font
virtual IGUIFont* getFont(const core::string<c16>& filename); virtual IGUIFont* getFont(const core::string<c16>& filename);
......
...@@ -46,11 +46,10 @@ CGUIImageList::~CGUIImageList() ...@@ -46,11 +46,10 @@ CGUIImageList::~CGUIImageList()
} }
//! Creates the image list from texture. //! Creates the image list from texture.
bool CGUIImageList::createImageList( video::ITexture* texture, bool CGUIImageList::createImageList(video::ITexture* texture,
core::dimension2d<s32> imageSize, core::dimension2d<s32> imageSize,
bool useAlphaChannel bool useAlphaChannel)
)
{ {
if( !texture ) if( !texture )
{ {
......
...@@ -79,12 +79,12 @@ namespace irr ...@@ -79,12 +79,12 @@ namespace irr
virtual void setResizable(bool resize=false); virtual void setResizable(bool resize=false);
//! Minimizes the window. //! Minimizes the window.
virtual void minimizeWindow(); virtual void minimizeWindow();
//! Get the device type //! Get the device type
virtual E_DEVICE_TYPE getType() const virtual E_DEVICE_TYPE getType() const
{ {
return EIDT_CONSOLE; return EIDT_CONSOLE;
} }
void addPostPresentText(s16 X, s16 Y, const wchar_t *text); void addPostPresentText(s16 X, s16 Y, const wchar_t *text);
......
...@@ -102,12 +102,12 @@ namespace irr ...@@ -102,12 +102,12 @@ namespace irr
//! copies text to the clipboard //! copies text to the clipboard
//! This sets the clipboard selection and _not_ the primary selection which you have on X on the middle mouse button. //! This sets the clipboard selection and _not_ the primary selection which you have on X on the middle mouse button.
virtual void copyToClipboard(const c8* text) const; virtual void copyToClipboard(const c8* text) const;
//! Get the device type //! Get the device type
virtual E_DEVICE_TYPE getType() const virtual E_DEVICE_TYPE getType() const
{ {
return EIDT_X11; return EIDT_X11;
} }
private: private:
......
...@@ -79,12 +79,12 @@ namespace irr ...@@ -79,12 +79,12 @@ namespace irr
virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ); virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast );
//! Get the current Gamma Value for the Display //! Get the current Gamma Value for the Display
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ); virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast );
//! Get the device type //! Get the device type
virtual E_DEVICE_TYPE getType() const virtual E_DEVICE_TYPE getType() const
{ {
return EIDT_WIN32; return EIDT_WIN32;
} }
//! Compares to the last call of this function to return double and triple clicks. //! Compares to the last call of this function to return double and triple clicks.
......
...@@ -70,12 +70,12 @@ namespace irr ...@@ -70,12 +70,12 @@ namespace irr
virtual void setResizable(bool resize=false); virtual void setResizable(bool resize=false);
//! Minimizes the window. //! Minimizes the window.
virtual void minimizeWindow(); virtual void minimizeWindow();
//! Get the device type //! Get the device type
virtual E_DEVICE_TYPE getType() const virtual E_DEVICE_TYPE getType() const
{ {
return EIDT_WINCE; return EIDT_WINCE;
} }
//! Implementation of the win32 cursor control //! Implementation of the win32 cursor control
...@@ -265,5 +265,5 @@ namespace irr ...@@ -265,5 +265,5 @@ namespace irr
} // end namespace irr } // end namespace irr
#endif // _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ #endif // _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
#endif // __C_IRR_DEVICE_WINCE_H_INCLUDED__ #endif // __C_IRR_DEVICE_WINCE_H_INCLUDED__
...@@ -454,9 +454,9 @@ COpenGLDriver::~COpenGLDriver() ...@@ -454,9 +454,9 @@ COpenGLDriver::~COpenGLDriver()
deleteAllTextures(); deleteAllTextures();
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
if (DeviceType == EIDT_WIN32) if (DeviceType == EIDT_WIN32)
{ {
if (HRc) if (HRc)
{ {
...@@ -468,7 +468,7 @@ COpenGLDriver::~COpenGLDriver() ...@@ -468,7 +468,7 @@ COpenGLDriver::~COpenGLDriver()
} }
if (HDc) if (HDc)
ReleaseDC(Window, HDc); ReleaseDC(Window, HDc);
} }
#endif #endif
} }
...@@ -625,36 +625,36 @@ bool COpenGLDriver::endScene() ...@@ -625,36 +625,36 @@ bool COpenGLDriver::endScene()
glFlush(); glFlush();
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
if (DeviceType == EIDT_WIN32) if (DeviceType == EIDT_WIN32)
return SwapBuffers(HDc) == TRUE; return SwapBuffers(HDc) == TRUE;
#endif #endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
if (DeviceType == EIDT_X11) if (DeviceType == EIDT_X11)
{ {
glXSwapBuffers((Display*)ExposedData.OpenGLLinux.X11Display, Drawable); glXSwapBuffers((Display*)ExposedData.OpenGLLinux.X11Display, Drawable);
return true; return true;
} }
#endif #endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
if (DeviceType == EIDT_OSX) if (DeviceType == EIDT_OSX)
{ {
_device->flush(); _device->flush();
return true; return true;
} }
#endif #endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
if (DeviceType == EIDT_SDL) if (DeviceType == EIDT_SDL)
{ {
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
return true; return true;
} }
#endif #endif
// todo: console device present // todo: console device present
return false; return false;
} }
...@@ -693,12 +693,12 @@ bool COpenGLDriver::beginScene(bool backBuffer, bool zBuffer, SColor color, ...@@ -693,12 +693,12 @@ bool COpenGLDriver::beginScene(bool backBuffer, bool zBuffer, SColor color,
{ {
CNullDriver::beginScene(backBuffer, zBuffer, color, windowId, sourceRect); CNullDriver::beginScene(backBuffer, zBuffer, color, windowId, sourceRect);
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
if (DeviceType == EIDT_SDL) if (DeviceType == EIDT_SDL)
{ {
// todo: SDL sets glFrontFace(GL_CCW) after driver creation, // todo: SDL sets glFrontFace(GL_CCW) after driver creation,
// it would be better if this was fixed elsewhere. // it would be better if this was fixed elsewhere.
glFrontFace(GL_CW); glFrontFace(GL_CW);
} }
#endif #endif
...@@ -3343,22 +3343,22 @@ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, ...@@ -3343,22 +3343,22 @@ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
return 0; return 0;
#endif // _IRR_COMPILE_WITH_OPENGL_ #endif // _IRR_COMPILE_WITH_OPENGL_
} }
#endif // _IRR_COMPILE_WITH_X11_DEVICE_ #endif // _IRR_COMPILE_WITH_X11_DEVICE_
// ----------------------------------- // -----------------------------------
// SDL VERSION // SDL VERSION
// ----------------------------------- // -----------------------------------
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceSDL* device) io::IFileSystem* io, CIrrDeviceSDL* device)
{ {
#ifdef _IRR_COMPILE_WITH_OPENGL_ #ifdef _IRR_COMPILE_WITH_OPENGL_
return new COpenGLDriver(params, io, device); return new COpenGLDriver(params, io, device);
#else #else
return 0; return 0;
#endif // _IRR_COMPILE_WITH_OPENGL_ #endif // _IRR_COMPILE_WITH_OPENGL_
} }
#endif // _IRR_COMPILE_WITH_SDL_DEVICE_ #endif // _IRR_COMPILE_WITH_SDL_DEVICE_
} // end namespace } // end namespace
......
...@@ -37,14 +37,14 @@ namespace video ...@@ -37,14 +37,14 @@ namespace video
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device); COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device);
#endif #endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device); COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device);
#endif #endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device); COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device);
#endif #endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
...@@ -408,15 +408,15 @@ namespace video ...@@ -408,15 +408,15 @@ namespace video
#ifdef _IRR_WINDOWS_API_ #ifdef _IRR_WINDOWS_API_
HDC HDc; // Private GDI Device Context HDC HDc; // Private GDI Device Context
HWND Window; HWND Window;
HGLRC HRc; // Permanent Rendering Context HGLRC HRc; // Permanent Rendering Context
#endif #endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
GLXDrawable Drawable; GLXDrawable Drawable;
#endif #endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
CIrrDeviceMacOSX *_device; CIrrDeviceMacOSX *_device;
#endif #endif
E_DEVICE_TYPE DeviceType; E_DEVICE_TYPE DeviceType;
}; };
......
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
#include "glext.h" #include "glext.h"
#endif #endif
#include "wglext.h" #include "wglext.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma comment(lib, "OpenGL32.lib") #pragma comment(lib, "OpenGL32.lib")
#endif #endif
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
#include "CIrrDeviceMacOSX.h" #include "CIrrDeviceMacOSX.h"
......
...@@ -13,33 +13,30 @@ static const char* const copyright = "Irrlicht Engine (c) 2002-2009 Nikolaus Geb ...@@ -13,33 +13,30 @@ static const char* const copyright = "Irrlicht Engine (c) 2002-2009 Nikolaus Geb
#endif // _DEBUG #endif // _DEBUG
#endif #endif
#include "irrlicht.h" #include "irrlicht.h"
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
#include "CIrrDeviceWin32.h" #include "CIrrDeviceWin32.h"
#endif #endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
#include "MacOSX/CIrrDeviceMacOSX.h" #include "MacOSX/CIrrDeviceMacOSX.h"
#endif #endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ #include "CIrrDeviceWinCE.h"
#include "CIrrDeviceWinCE.h" #endif
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
#include "CIrrDeviceLinux.h"
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #endif
#include "CIrrDeviceLinux.h"
#endif #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
#include "CIrrDeviceSDL.h"
#endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
#include "CIrrDeviceSDL.h" #ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#include "CIrrDeviceConsole.h" #include "CIrrDeviceConsole.h"
#endif #endif
namespace irr namespace irr
{ {
...@@ -60,52 +57,52 @@ namespace irr ...@@ -60,52 +57,52 @@ namespace irr
return createDeviceEx(p); return createDeviceEx(p);
} }
extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& params) extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& params)
{ {
IrrlichtDevice* dev = 0; IrrlichtDevice* dev = 0;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
if (params.DeviceType == EIDT_WIN32 || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_WIN32 || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWin32(params); dev = new CIrrDeviceWin32(params);
#endif #endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceMacOSX(params); dev = new CIrrDeviceMacOSX(params);
#endif #endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
if (params.DeviceType == EIDT_WINCE || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_WINCE || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWinCE(params); dev = new CIrrDeviceWinCE(params);
#endif #endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceLinux(params); dev = new CIrrDeviceLinux(params);
#endif #endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
if (params.DeviceType == EIDT_SDL || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_SDL || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceSDL(params); dev = new CIrrDeviceSDL(params);
#endif #endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ #ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
if (params.DeviceType == EIDT_CONSOLE || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_CONSOLE || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceConsole(params); dev = new CIrrDeviceConsole(params);
#endif #endif
if (dev && !dev->getVideoDriver() && params.DriverType != video::EDT_NULL) if (dev && !dev->getVideoDriver() && params.DriverType != video::EDT_NULL)
{ {
dev->closeDevice(); // destroy window dev->closeDevice(); // destroy window
dev->run(); // consume quit message dev->run(); // consume quit message
dev->drop(); dev->drop();
dev = 0; dev = 0;
} }
return dev; return dev;
} }
namespace core namespace core
{ {
......
// Copyright (C) 2005-2009 Etienne Petitjean // Copyright (C) 2005-2009 Etienne Petitjean
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h // For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h" #include "IrrCompileConfig.h"
#ifdef _IRR_USE_OSX_DEVICE_ #ifdef _IRR_USE_OSX_DEVICE_
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "CIrrDeviceMacOSX.h" #import "CIrrDeviceMacOSX.h"
@interface AppDelegate : NSObject @interface AppDelegate : NSObject
{ {
BOOL _quit; BOOL _quit;
irr::CIrrDeviceMacOSX *_device; irr::CIrrDeviceMacOSX *_device;
} }
- (id)initWithDevice:(irr::CIrrDeviceMacOSX *)device; - (id)initWithDevice:(irr::CIrrDeviceMacOSX *)device;
- (BOOL)isQuit; - (BOOL)isQuit;
@end @end
#endif // _IRR_USE_OSX_DEVICE_ #endif // _IRR_USE_OSX_DEVICE_
// Copyright (C) 2005-2009 Etienne Petitjean // Copyright (C) 2005-2009 Etienne Petitjean
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h // For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #ifndef __C_IRR_DEVICE_MACOSX_H_INCLUDED__
#define __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #define __C_IRR_DEVICE_MACOSX_H_INCLUDED__
#include "IrrCompileConfig.h" #include "IrrCompileConfig.h"
#ifdef _IRR_USE_OSX_DEVICE_ #ifdef _IRR_USE_OSX_DEVICE_
#include "CIrrDeviceStub.h" #include "CIrrDeviceStub.h"
#include "IrrlichtDevice.h" #include "IrrlichtDevice.h"
#include "IImagePresenter.h" #include "IImagePresenter.h"
#include "IGUIEnvironment.h" #include "IGUIEnvironment.h"
#include "ICursorControl.h" #include "ICursorControl.h"
#include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
#include <map> #include <map>
class NSWindow; class NSWindow;
class NSOpenGLContext; class NSOpenGLContext;
class NSBitmapImageRep; class NSBitmapImageRep;
namespace irr namespace irr
{ {
class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter
{ {
public: public:
//! constructor //! constructor
CIrrDeviceMacOSX(const SIrrlichtCreationParameters& params); CIrrDeviceMacOSX(const SIrrlichtCreationParameters& params);
//! destructor //! destructor
virtual ~CIrrDeviceMacOSX(); virtual ~CIrrDeviceMacOSX();
//! runs the device. Returns false if device wants to be deleted //! runs the device. Returns false if device wants to be deleted
virtual bool run(); virtual bool run();
//! Cause the device to temporarily pause execution and let other processes to run //! Cause the device to temporarily pause execution and let other processes to run
// This should bring down processor usage without major performance loss for Irrlicht // This should bring down processor usage without major performance loss for Irrlicht
virtual void yield(); virtual void yield();
//! Pause execution and let other processes to run for a specified amount of time. //! Pause execution and let other processes to run for a specified amount of time.
virtual void sleep(u32 timeMs, bool pauseTimer); virtual void sleep(u32 timeMs, bool pauseTimer);
//! sets the caption of the window //! sets the caption of the window
virtual void setWindowCaption(const wchar_t* text); virtual void setWindowCaption(const wchar_t* text);
//! returns if window is active. if not, nothing need to be drawn //! returns if window is active. if not, nothing need to be drawn
virtual bool isWindowActive() const; virtual bool isWindowActive() const;
//! Checks if the Irrlicht window has focus //! Checks if the Irrlicht window has focus
virtual bool isWindowFocused() const; virtual bool isWindowFocused() const;
//! Checks if the Irrlicht window is minimized //! Checks if the Irrlicht window is minimized
virtual bool isWindowMinimized() const; virtual bool isWindowMinimized() const;
//! presents a surface in the client area //! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0 ); virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0 );
//! notifies the device that it should close itself //! notifies the device that it should close itself
virtual void closeDevice(); virtual void closeDevice();
//! Sets if the window should be resizable in windowed mode. //! Sets if the window should be resizable in windowed mode.
virtual void setResizable(bool resize); virtual void setResizable(bool resize);
//! Returns true if the window is resizable, false if not //! Returns true if the window is resizable, false if not
virtual bool isResizable() const; virtual bool isResizable() const;
//! Minimizes the window if possible //! Minimizes the window if possible
virtual void minimizeWindow(); virtual void minimizeWindow();
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
//! \return Returns a pointer to a list with all video modes //! \return Returns a pointer to a list with all video modes
//! supported by the gfx adapter. //! supported by the gfx adapter.
virtual video::IVideoModeList* getVideoModeList(); virtual video::IVideoModeList* getVideoModeList();
//! Get the device type //! Get the device type
virtual E_DEVICE_TYPE getType() const virtual E_DEVICE_TYPE getType() const
{ {
return EIDT_OSX; return EIDT_OSX;
} }
void flush(); void flush();
void setMouseLocation(int x, int y); void setMouseLocation(int x, int y);
void setResize(int width, int height); void setResize(int width, int height);
void setCursorVisible(bool visible); void setCursorVisible(bool visible);
private: private:
//! create the driver //! create the driver
void createDriver(); void createDriver();
//! Implementation of the macos x cursor control //! Implementation of the macos x cursor control
class CCursorControl : public gui::ICursorControl class CCursorControl : public gui::ICursorControl
{ {
public: public:
CCursorControl(const core::dimension2d<u32>& wsize, CIrrDeviceMacOSX *device) CCursorControl(const core::dimension2d<u32>& wsize, CIrrDeviceMacOSX *device)
: WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), Device(device), UseReferenceRect(false) : WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), Device(device), UseReferenceRect(false)
{ {
CursorPos.X = CursorPos.Y = 0; CursorPos.X = CursorPos.Y = 0;
if (WindowSize.Width!=0) if (WindowSize.Width!=0)
InvWindowSize.Width = 1.0f / WindowSize.Width; InvWindowSize.Width = 1.0f / WindowSize.Width;
if (WindowSize.Height!=0) if (WindowSize.Height!=0)
InvWindowSize.Height = 1.0f / WindowSize.Height; InvWindowSize.Height = 1.0f / WindowSize.Height;
} }
//! Changes the visible state of the mouse cursor. //! Changes the visible state of the mouse cursor.
virtual void setVisible(bool visible) virtual void setVisible(bool visible)
{ {
IsVisible = visible; IsVisible = visible;
Device->setCursorVisible(visible); Device->setCursorVisible(visible);
} }
//! Returns if the cursor is currently visible. //! Returns if the cursor is currently visible.
virtual bool isVisible() const virtual bool isVisible() const
{ {
return IsVisible; return IsVisible;
} }
//! Sets the new position of the cursor. //! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<f32> &pos) virtual void setPosition(const core::position2d<f32> &pos)
{ {
setPosition(pos.X, pos.Y); setPosition(pos.X, pos.Y);
} }
//! Sets the new position of the cursor. //! Sets the new position of the cursor.
virtual void setPosition(f32 x, f32 y) virtual void setPosition(f32 x, f32 y)
{ {
setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height)); setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height));
} }
//! Sets the new position of the cursor. //! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<s32> &pos) virtual void setPosition(const core::position2d<s32> &pos)
{ {
if (CursorPos.X != pos.X || CursorPos.Y != pos.Y) if (CursorPos.X != pos.X || CursorPos.Y != pos.Y)
setPosition(pos.X, pos.Y); setPosition(pos.X, pos.Y);
} }
//! Sets the new position of the cursor. //! Sets the new position of the cursor.
virtual void setPosition(s32 x, s32 y) virtual void setPosition(s32 x, s32 y)
{ {
if (UseReferenceRect) if (UseReferenceRect)
{ {
Device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y); Device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y);
} }
else else
{ {
Device->setMouseLocation(x,y); Device->setMouseLocation(x,y);
} }
} }
//! Returns the current position of the mouse cursor. //! Returns the current position of the mouse cursor.
virtual core::position2d<s32> getPosition() virtual core::position2d<s32> getPosition()
{ {
return CursorPos; return CursorPos;
} }
//! Returns the current position of the mouse cursor. //! Returns the current position of the mouse cursor.
virtual core::position2d<f32> getRelativePosition() virtual core::position2d<f32> getRelativePosition()
{ {
if (!UseReferenceRect) if (!UseReferenceRect)
{ {
return core::position2d<f32>(CursorPos.X * InvWindowSize.Width, return core::position2d<f32>(CursorPos.X * InvWindowSize.Width,
CursorPos.Y * InvWindowSize.Height); CursorPos.Y * InvWindowSize.Height);
} }
return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(), return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
CursorPos.Y / (f32)ReferenceRect.getHeight()); CursorPos.Y / (f32)ReferenceRect.getHeight());
} }
//! Sets an absolute reference rect for calculating the cursor position. //! Sets an absolute reference rect for calculating the cursor position.
virtual void setReferenceRect(core::rect<s32>* rect=0) virtual void setReferenceRect(core::rect<s32>* rect=0)
{ {
if (rect) if (rect)
{ {
ReferenceRect = *rect; ReferenceRect = *rect;
UseReferenceRect = true; UseReferenceRect = true;
// prevent division through zero and uneven sizes // prevent division through zero and uneven sizes
if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2) if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2)
ReferenceRect.LowerRightCorner.Y += 1; ReferenceRect.LowerRightCorner.Y += 1;
if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2) if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2)
ReferenceRect.LowerRightCorner.X += 1; ReferenceRect.LowerRightCorner.X += 1;
} }
else else
UseReferenceRect = false; UseReferenceRect = false;
} }
//! Updates the internal cursor position //! Updates the internal cursor position
void updateInternalCursorPosition(int x,int y) void updateInternalCursorPosition(int x,int y)
{ {
CursorPos.X = x; CursorPos.X = x;
CursorPos.Y = y; CursorPos.Y = y;
} }
private: private:
core::position2d<s32> CursorPos; core::position2d<s32> CursorPos;
core::dimension2d<s32> WindowSize; core::dimension2d<s32> WindowSize;
core::dimension2d<float> InvWindowSize; core::dimension2d<float> InvWindowSize;
core::rect<s32> ReferenceRect; core::rect<s32> ReferenceRect;
CIrrDeviceMacOSX *Device; CIrrDeviceMacOSX *Device;
bool IsVisible; bool IsVisible;
bool UseReferenceRect; bool UseReferenceRect;
}; };
bool createWindow(); bool createWindow();
void initKeycodes(); void initKeycodes();
void storeMouseLocation(); void storeMouseLocation();
void postMouseEvent(void *event, irr::SEvent &ievent); void postMouseEvent(void *event, irr::SEvent &ievent);
void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed); void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed);
void pollJoysticks(); void pollJoysticks();
NSWindow *Window; NSWindow *Window;
CGLContextObj CGLContext; CGLContextObj CGLContext;
NSOpenGLContext *OGLContext; NSOpenGLContext *OGLContext;
int DeviceWidth, int DeviceWidth,
DeviceHeight; DeviceHeight;
std::map<int,int> KeyCodes; std::map<int,int> KeyCodes;
int ScreenWidth, int ScreenWidth,
ScreenHeight; ScreenHeight;
bool IsActive; bool IsActive;
NSBitmapImageRep *SoftwareDriverTarget; NSBitmapImageRep *SoftwareDriverTarget;
bool IsSoftwareRenderer, bool IsSoftwareRenderer,
IsShiftDown, IsShiftDown,
IsControlDown, IsControlDown,
IsResizable; IsResizable;
u32 MouseButtonStates; u32 MouseButtonStates;
}; };
} // end namespace irr } // end namespace irr
#endif // _IRR_USE_OSX_DEVICE_ #endif // _IRR_USE_OSX_DEVICE_
#endif // __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #endif // __C_IRR_DEVICE_MACOSX_H_INCLUDED__
// Copyright (C) 2005-2009 Etienne Petitjean // Copyright (C) 2005-2009 Etienne Petitjean
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h // For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "OSXClipboard.h" #include "OSXClipboard.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
void OSXCopyToClipboard(const char *text) void OSXCopyToClipboard(const char *text)
{ {
NSString *str; NSString *str;
NSPasteboard *board; NSPasteboard *board;
if (text != NULL && strlen(text) > 0) if (text != NULL && strlen(text) > 0)
{ {
str = [NSString stringWithCString:text encoding:NSWindowsCP1252StringEncoding]; str = [NSString stringWithCString:text encoding:NSWindowsCP1252StringEncoding];
board = [NSPasteboard generalPasteboard]; board = [NSPasteboard generalPasteboard];
[board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp]; [board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp];
[board setString:str forType:NSStringPboardType]; [board setString:str forType:NSStringPboardType];
} }
} }
char* OSXCopyFromClipboard() char* OSXCopyFromClipboard()
{ {
NSString *str; NSString *str;
NSPasteboard *board; NSPasteboard *board;
char *result; char *result;
result = NULL; result = NULL;
board = [NSPasteboard generalPasteboard]; board = [NSPasteboard generalPasteboard];
str = [board stringForType:NSStringPboardType]; str = [board stringForType:NSStringPboardType];
if (str != nil) result = (char*)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding]; if (str != nil) result = (char*)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
return (result); return (result);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment