diff --git a/src/base.hpp b/src/base.hpp index 4df2f48b9..78a63cd4e 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -165,6 +165,10 @@ #endif #endif +#if ( defined( EE_GLES2 ) || defined( EE_GLES1 ) ) && !defined( EE_GLES ) + #define EE_GLES +#endif + /// Activate at least one backend for the compilation #if !defined( EE_BACKEND_SDL_ACTIVE ) && !defined( EE_BACKEND_ALLEGRO_ACTIVE ) #define EE_BACKEND_SDL_ACTIVE diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp index fc567b4de..347ff308c 100644 --- a/src/gaming/cmap.cpp +++ b/src/gaming/cmap.cpp @@ -30,7 +30,9 @@ cMap::cMap() : mTileOverColor( 255, 0, 0, 200 ), mBackColor( 0, 0, 0, 50 ), mBackAlpha( 255 ), - mMouseOver( false ) + mMouseOver( false ), + mScale( 1 ), + mOffscale( 1, 1 ) { ViewSize( mViewSize ); } @@ -195,31 +197,6 @@ void cMap::Draw() { mWindow->ClipEnable( mScreenPos.x, mScreenPos.y, mViewSize.x, mViewSize.y ); } - GridDraw(); - - for ( Uint32 i = 0; i < mLayerCount; i++ ) { - if ( mLayers[i]->Visible() ) - mLayers[i]->Draw( mOffsetFixed ); - } - - MouseOverDraw(); - - if ( mDrawCb.IsSet() ) - mDrawCb(); - - if ( ClipedArea() ) { - mWindow->ClipDisable(); - } -} - -void cMap::MouseOverDraw() { - if ( !DrawTileOver() || NULL == mTileTex ) - return; - - mTileTex->Draw( mOffsetFixed.x + mMouseOverTileFinal.x * mTileSize.x, mOffsetFixed.y + mMouseOverTileFinal.y * mTileSize.y, 0, 1, mTileOverColor ); -} - -void cMap::GridDraw() { if ( DrawBackground() ) { cPrimitives P; @@ -230,6 +207,40 @@ void cMap::GridDraw() { P.SetColor( eeColorA( 255, 255, 255, 255 ) ); } + GLi->LoadIdentity(); + GLi->PushMatrix(); + GLi->Translatef( (eeFloat)static_cast( mScreenPos.x + mFixedOffset.x ), (eeFloat)static_cast( mScreenPos.y + mFixedOffset.y ), 0 ); + GLi->Scalef( mScale, mScale, 0 ); + + GridDraw(); + + for ( Uint32 i = 0; i < mLayerCount; i++ ) { + if ( mLayers[i]->Visible() ) + mLayers[i]->Draw(); + } + + MouseOverDraw(); + + if ( mDrawCb.IsSet() ) + mDrawCb(); + + cGlobalBatchRenderer::instance()->Draw(); + + GLi->PopMatrix(); + + if ( ClipedArea() ) { + mWindow->ClipDisable(); + } +} + +void cMap::MouseOverDraw() { + if ( !DrawTileOver() || NULL == mTileTex ) + return; + + mTileTex->Draw( mMouseOverTileFinal.x * mTileSize.x, mMouseOverTileFinal.y * mTileSize.y, 0, 1, mTileOverColor ); +} + +void cMap::GridDraw() { if ( !DrawGrid() ) return; @@ -238,10 +249,6 @@ void cMap::GridDraw() { cGlobalBatchRenderer::instance()->Draw(); - GLi->LoadIdentity(); - GLi->PushMatrix(); - GLi->Translatef( mOffsetFixed.x, mOffsetFixed.y, 0.0f ); - eeVector2i start = StartTile(); eeVector2i end = EndTile(); @@ -259,8 +266,6 @@ void cMap::GridDraw() { } cGlobalBatchRenderer::instance()->Draw(); - - GLi->PopMatrix(); } const bool& cMap::IsMouseOver() const { @@ -270,7 +275,7 @@ const bool& cMap::IsMouseOver() const { void cMap::GetMouseOverTile() { eeVector2i mouse = mWindow->GetInput()->GetMousePos(); - eeVector2i MapPos( mouse.x - mScreenPos.x - mOffset.x, mouse.y - mScreenPos.y - mOffset.y ); + eeVector2i MapPos( static_cast( mouse.x - mScreenPos.x - mFixedOffset.x ) / mScale, static_cast( mouse.y - mScreenPos.y - mFixedOffset.y ) / mScale ); mMouseOver = !( MapPos.x < 0 || MapPos.y < 0 || MapPos.x > mPixelSize.x || MapPos.y > mPixelSize.y ); @@ -291,6 +296,98 @@ void cMap::GetMouseOverTile() { mMouseMapPos = MapPos; } +void cMap::CalcTilesClip() { + if ( mTileSize.x > 0 && mTileSize.y > 0 ) { + eeVector2f ffoff( mFixedOffset ); + eeVector2i foff( (Int32)ffoff.x, (Int32)ffoff.y ); + + mStartTile.x = -foff.x / ( mTileSize.x * mScale ) - mExtraTiles.x; + mStartTile.y = -foff.y / ( mTileSize.y * mScale ) - mExtraTiles.y; + mEndTile.x = mStartTile.x + eeRound( (eeFloat)mViewSize.x / ( (eeFloat)mTileSize.x * mScale ) ) + 1 + mExtraTiles.x; + mEndTile.y = mStartTile.y + eeRound( (eeFloat)mViewSize.y / ( (eeFloat)mTileSize.y * mScale ) ) + 1 + mExtraTiles.y; + + if ( mStartTile.x < 0 ) + mStartTile.x = 0; + + if ( mStartTile.y < 0 ) + mStartTile.y = 0; + + if ( mEndTile.x > mSize.x ) + mEndTile.x = mSize.x; + + if ( mEndTile.y > mSize.y ) + mEndTile.y = mSize.y; + } +} + +void cMap::Clamp() { + if ( !ClampBorders() ) + return; + + if ( mOffset.x > 0 ) + mOffset.x = 0; + + if ( mOffset.y > 0 ) + mOffset.y = 0; + + eeSize totSize( mTileSize * mSize ); + + if ( -mOffset.x + mViewSize.x > totSize.x ) + mOffset.x = -( totSize.x - mViewSize.x ); + + if ( -mOffset.y + mViewSize.y > totSize.y ) + mOffset.y = -( totSize.y - mViewSize.y ); + + if ( totSize.x < mViewSize.x ) + mOffset.x = 0; + + if ( totSize.y < mViewSize.y ) + mOffset.y = 0; + + totSize.x = (Int32)( (eeFloat)( mTileSize.x * mSize.x ) * mScale ); + totSize.y = (Int32)( (eeFloat)( mTileSize.y * mSize.y ) * mScale ); + + if ( -mFixedOffset.x + mViewSize.x > totSize.x ) + mFixedOffset.x = -( totSize.x - mViewSize.x ); + + if ( -mFixedOffset.y + mViewSize.y > totSize.y ) + mFixedOffset.y = -( totSize.y - mViewSize.y ); + + if ( totSize.x < mViewSize.x ) + mFixedOffset.x = 0; + + if ( totSize.y < mViewSize.y ) + mFixedOffset.y = 0; +} + +void cMap::Offset( const eeVector2f& offset ) { + mOffset = offset; + mFixedOffset = mOffset * mOffscale; + + Clamp(); + + CalcTilesClip(); +} + +void cMap::UpdateOffscale() { + eeVector2f totSizeT( mTileSize.x * mSize.x - mViewSize.x , mTileSize.y * mSize.y - mViewSize.y ); + eeVector2f totSizeS( mTileSize.x * mSize.x * mScale - mViewSize.x , mTileSize.y * mSize.y * mScale - mViewSize.y ); + + mOffscale = eeVector2f( totSizeS.x / totSizeT.x, totSizeS.y / totSizeT.y ); +} + +const eeFloat& cMap::Scale() const { + return mScale; +} + +void cMap::Scale( const eeFloat& scale ) { + mScale = scale; + + UpdateOffscale(); + + Offset( mOffset ); +} + void cMap::UpdateScreenAABB() { mScreenAABB = eeAABB( -mOffset.x, -mOffset.y, -mOffset.x + mViewSize.Width(), -mOffset.y + mViewSize.Height() ); } @@ -299,10 +396,6 @@ const eeAABB& cMap::GetViewAreaAABB() const { return mScreenAABB; } -void cMap::FixedOffset() { - mOffsetFixed = eeVector2f( (eeFloat)mScreenPos.x, (eeFloat)mScreenPos.y ) + FixOffset(); -} - void cMap::Update() { GetMouseOverTile(); @@ -341,6 +434,8 @@ eeVector2f cMap::GetMouseMapPosf() const { void cMap::ViewSize( const eeSize& viewSize ) { mViewSize = viewSize; + UpdateOffscale(); + Clamp(); CalcTilesClip(); @@ -352,17 +447,12 @@ const eeVector2i& cMap::Position() const { void cMap::Position( const eeVector2i& position ) { mScreenPos = position; - FixedOffset(); } const eeVector2f& cMap::Offset() const { return mOffset; } -const eeVector2f& cMap::OffsetFixed() const { - return mOffsetFixed; -} - const eeVector2i& cMap::StartTile() const { return mStartTile; } @@ -379,65 +469,6 @@ const eeVector2i& cMap::ExtraTiles() const { return mExtraTiles; } -void cMap::Offset( const eeVector2f& offset ) { - mOffset = offset; - - Clamp(); - - CalcTilesClip(); - - FixedOffset(); -} - -void cMap::CalcTilesClip() { - if ( mTileSize.x > 0 && mTileSize.y > 0 ) { - eeVector2f ffoff( FixOffset() ); - eeVector2i foff( (Int32)ffoff.x, (Int32)ffoff.y ); - - mStartTile.x = -foff.x / mTileSize.x - mExtraTiles.x; - mStartTile.y = -foff.y / mTileSize.y - mExtraTiles.y; - mEndTile.x = mStartTile.x + eeRound( (eeFloat)mViewSize.x / (eeFloat)mTileSize.x ) + 1 + mExtraTiles.x; - mEndTile.y = mStartTile.y + eeRound( (eeFloat)mViewSize.y / (eeFloat)mTileSize.y ) + 1 + mExtraTiles.y; - - if ( mStartTile.x < 0 ) - mStartTile.x = 0; - - if ( mStartTile.y < 0 ) - mStartTile.y = 0; - - if ( mEndTile.x > mSize.x ) - mEndTile.x = mSize.x; - - if ( mEndTile.y > mSize.y ) - mEndTile.y = mSize.y; - } -} - -void cMap::Clamp() { - if ( !ClampBorders() ) - return; - - if ( mOffset.x > 0 ) - mOffset.x = 0; - - if ( mOffset.y > 0 ) - mOffset.y = 0; - - eeSize totSize( mTileSize * mSize ); - - if ( -mOffset.x + mViewSize.x > totSize.x ) - mOffset.x = -( totSize.x - mViewSize.x ); - - if ( -mOffset.y + mViewSize.y > totSize.y ) - mOffset.y = -( totSize.y - mViewSize.y ); - - if ( totSize.x < mViewSize.x ) - mOffset.x = 0; - - if ( totSize.y < mViewSize.y ) - mOffset.y = 0; -} - void cMap::BaseColor( const eeColorA& color ) { mBaseColor = color; } @@ -474,10 +505,18 @@ Uint32 cMap::ClipedArea() const { return mFlags & MAP_FLAG_CLIP_AREA; } +void cMap::ClipedArea( const bool& clip ) { + SetFlagValue( &mFlags, MAP_FLAG_CLIP_AREA, clip ? 1 : 0 ); +} + Uint32 cMap::ClampBorders() const { return mFlags & MAP_FLAG_CLAMP_BORDERS; } +void cMap::ClampBorders( const bool& clamp ) { + SetFlagValue( &mFlags, MAP_FLAG_CLAMP_BORDERS, clamp ? 1 : 0 ); +} + Uint32 cMap::DrawTileOver() const { return mFlags & MAP_FLAG_DRAW_TILE_OVER; } @@ -494,10 +533,6 @@ void cMap::LightsEnabled( const bool& enabled ) { SetFlagValue( &mFlags, MAP_FLAG_LIGHTS_ENABLED, enabled ? 1 : 0 ); } -eeVector2f cMap::FixOffset() { - return eeVector2f( (eeFloat)static_cast( mOffset.x ), (eeFloat)static_cast( mOffset.y ) ); -} - void cMap::Move( const eeVector2f& offset ) { Move( offset.x, offset.y ); } diff --git a/src/gaming/cmap.hpp b/src/gaming/cmap.hpp index 3329456d6..c948d0846 100644 --- a/src/gaming/cmap.hpp +++ b/src/gaming/cmap.hpp @@ -91,8 +91,12 @@ class EE_API cMap { Uint32 ClampBorders() const; + void ClampBorders( const bool& clamp ); + Uint32 ClipedArea() const; + void ClipedArea( const bool& clip ); + void DrawGrid( const bool& draw ); Uint32 DrawGrid() const; @@ -189,6 +193,10 @@ class EE_API cMap { const eeColorA& BackColor() const; void BackColor( const eeColorA& col ); + + const eeFloat& Scale() const; + + void Scale( const eeFloat& scale ); protected: Window::cWindow * mWindow; cLayer** mLayers; @@ -200,6 +208,7 @@ class EE_API cMap { eeSize mTileSize; eeSize mViewSize; eeVector2f mOffset; + eeVector2f mFixedOffset; eeVector2i mScreenPos; eeVector2i mStartTile; eeVector2i mEndTile; @@ -207,7 +216,6 @@ class EE_API cMap { eeVector2i mMouseOverTile; eeVector2i mMouseOverTileFinal; eeVector2i mMouseMapPos; - eeVector2f mOffsetFixed; eeColorA mBaseColor; PropertiesMap mProperties; GOTypesList mObjTypes; @@ -221,15 +229,13 @@ class EE_API cMap { eeColorA mTileOverColor; eeColorA mBackColor; Uint8 mBackAlpha; - std::string mPath; bool mMouseOver; + std::string mPath; + eeFloat mScale; + eeVector2f mOffscale; virtual cGameObject * CreateGameObject( const Uint32& Type, const Uint32& Flags, cLayer * Layer, const Uint32& DataId = 0 ); - eeVector2f FixOffset(); - - void FixedOffset(); - void CalcTilesClip(); void Clamp(); @@ -251,6 +257,8 @@ class EE_API cMap { void CreateLightManager(); virtual void OnMapLoaded(); + + void UpdateOffscale(); }; }} diff --git a/src/gaming/cobjectlayer.cpp b/src/gaming/cobjectlayer.cpp index 3f56a596e..233b3bbdb 100644 --- a/src/gaming/cobjectlayer.cpp +++ b/src/gaming/cobjectlayer.cpp @@ -31,9 +31,8 @@ void cObjectLayer::Draw( const eeVector2f &Offset ) { ObjList::iterator it; - GLi->LoadIdentity(); GLi->PushMatrix(); - GLi->Translatef( mOffset.x + Offset.x, mOffset.y + Offset.y, 0.0f ); + GLi->Translatef( mOffset.x, mOffset.y, 0.0f ); for ( it = mObjects.begin(); it != mObjects.end(); it++ ) { (*it)->Draw(); diff --git a/src/gaming/ctilelayer.cpp b/src/gaming/ctilelayer.cpp index 65c4128d5..ba1e61f6b 100644 --- a/src/gaming/ctilelayer.cpp +++ b/src/gaming/ctilelayer.cpp @@ -21,9 +21,8 @@ cTileLayer::~cTileLayer() { void cTileLayer::cTileLayer::Draw( const eeVector2f &Offset ) { cGlobalBatchRenderer::instance()->Draw(); - GLi->LoadIdentity(); GLi->PushMatrix(); - GLi->Translatef( mOffset.x + Offset.x, mOffset.y + Offset.y, 0.0f ); + GLi->Translatef( mOffset.x, mOffset.y, 0.0f ); eeVector2i start = mMap->StartTile(); eeVector2i end = mMap->EndTile(); diff --git a/src/gaming/mapeditor/cuimap.cpp b/src/gaming/mapeditor/cuimap.cpp index 8ae6b9292..5e512a9a6 100644 --- a/src/gaming/mapeditor/cuimap.cpp +++ b/src/gaming/mapeditor/cuimap.cpp @@ -162,7 +162,7 @@ void cUIMap::MapDraw() { cPrimitives P; P.SetColor( eeColorA( 255, 0, 0, (Uint8)mAlpha ) ); - eeVector2f Pos( mSelLight->GetAABB().Left + mMap->OffsetFixed().x, mSelLight->GetAABB().Top + mMap->OffsetFixed().y ); + eeVector2f Pos( mSelLight->GetAABB().Left, mSelLight->GetAABB().Top ); eeAABB AB( mSelLight->GetAABB() ); eeSizef Size( AB.Size() ); diff --git a/src/graphics/base.hpp b/src/graphics/base.hpp index 14e87aef8..be7af3dcf 100644 --- a/src/graphics/base.hpp +++ b/src/graphics/base.hpp @@ -9,10 +9,6 @@ #define GL_FP GL_FLOAT #endif -#if ( defined( EE_GLES2 ) || defined( EE_GLES1 ) ) && !defined( EE_GLES ) - #define EE_GLES -#endif - #if ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) ) && !defined( EE_GLES ) #define EE_GLEW_AVAILABLE #endif @@ -45,7 +41,7 @@ //! GLES2 ( programmable pipeline ) #ifdef EE_GLES2 - #if EE_PLATFORM_IOS + #if EE_PLATFORM == EE_PLATFORM_IOS #include #include #else @@ -55,19 +51,29 @@ //! GLES1 ( fixed pipeline ) #elif defined( EE_GLES1 ) - #if EE_PLATFORM_IOS + #if EE_PLATFORM == EE_PLATFORM_IOS #include #include #else #include + #define GL_GLEXT_PROTOTYPES #include #endif #endif #endif #ifdef EE_GLES -typedef GLfloat GLdouble; -typedef char GLchar; + typedef GLfloat GLdouble; + typedef char GLchar; + + #define glDeleteBuffersARB glDeleteBuffers + #define glGenBuffersARB glGenBuffers + #define glBindBufferARB glBindBuffer + #define glBufferDataARB glBufferData + #define glBufferSubDataARB glBufferSubData +#endif + +#ifdef EE_GLES2 #define glCheckFramebufferStatusEXT glCheckFramebufferStatus #define glDeleteFramebuffersEXT glDeleteFramebuffers @@ -78,16 +84,15 @@ typedef char GLchar; #define glBindRenderbufferEXT glBindRenderbuffer #define glFramebufferRenderbufferEXT glFramebufferRenderbuffer #define glFramebufferTexture2DEXT glFramebufferTexture2D -#define glDeleteBuffersARB glDeleteBuffers -#define glGenBuffersARB glGenBuffers -#define glBindBufferARB glBindBuffer -#define glBufferDataARB glBufferData -#define glBufferSubDataARB glBufferSubData + #define glVertexAttribPointerARB glVertexAttribPointer #define GL_MODELVIEW 0x1700 #define GL_PROJECTION 0x1701 #define GL_TEXTURE 0x1702 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_TEXTURE_MATRIX 0x0BA8 #define GL_VERTEX_ARRAY 0x8074 #define GL_NORMAL_ARRAY 0x8075 #define GL_COLOR_ARRAY 0x8076 @@ -106,6 +111,84 @@ typedef char GLchar; #define GL_CLIP_PLANE5 0x3005 #define GL_POINT_SPRITE 0x8861 #define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 + +#elif defined( EE_GLES1 ) + +#define glOrtho glOrthof +#define glClipPlane glClipPlanef +#define glFrustum glFrustumf + +#define glCheckFramebufferStatusEXT glCheckFramebufferStatusOES +#define glDeleteFramebuffersEXT glDeleteFramebuffersOES +#define glGenFramebuffersEXT glGenFramebuffersOES +#define glGenRenderbuffersEXT glGenRenderbuffersOES +#define glBindFramebufferEXT glBindFramebufferOES +#define glRenderbufferStorageEXT glRenderbufferStorageOES +#define glBindRenderbufferEXT glBindRenderbufferOES +#define glFramebufferRenderbufferEXT glFramebufferRenderbufferOES +#define glFramebufferTexture2DEXT glFramebufferTexture2DOES + +#define GL_POINT_SPRITE GL_POINT_SPRITE_OES +#define GL_COORD_REPLACE GL_COORD_REPLACE_OES +#define GL_COMBINE_ARB GL_COMBINE + +#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACEGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES +#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES +#define GL_FRAMEBUFFER_UNSUPPORTED GL_FRAMEBUFFER_UNSUPPORTED_OES +#define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES + +#define GL_RENDERBUFFER GL_RENDERBUFFER_OES +#define GL_RENDERBUFFER_WIDTH GL_RENDERBUFFER_WIDTH_OES +#define GL_RENDERBUFFER_HEIGHT GL_RENDERBUFFER_HEIGHT_OES +#define GL_RENDERBUFFER_INTERNAL_FORMAT GL_RENDERBUFFER_INTERNAL_FORMAT_OES +#define GL_RENDERBUFFER_RED_SIZE GL_RENDERBUFFER_RED_SIZE_OES +#define GL_RENDERBUFFER_GREEN_SIZE GL_RENDERBUFFER_GREEN_SIZE_OES +#define GL_RENDERBUFFER_BLUE_SIZE GL_RENDERBUFFER_BLUE_SIZE_OES +#define GL_RENDERBUFFER_ALPHA_SIZE GL_RENDERBUFFER_ALPHA_SIZE_OES +#define GL_RENDERBUFFER_DEPTH_SIZE GL_RENDERBUFFER_DEPTH_SIZE_OES +#define GL_RENDERBUFFER_STENCIL_SIZE GL_RENDERBUFFER_STENCIL_SIZE_OES +#define GL_RENDERBUFFER_BINDING GL_RENDERBUFFER_BINDING_OES + +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 + +#define GL_UNSIGNED_INT GL_UNSIGNED_INT_24_8_OES + +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 + +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA + +#define GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT32_OES +#define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES +#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES + +#define GL_SUBTRACT_ARB GL_SUBTRACT +#define GL_ADD_SIGNED_ARB GL_ADD_SIGNED +#define GL_INTERPOLATE_ARB GL_INTERPOLATE +#define GL_DOT3_RGB_ARB GL_DOT3_RGB +#define GL_DOT3_RGBA_ARB GL_DOT3_RGBA + +#define GL_CONSTANT_ARB GL_CONSTANT +#define GL_PRIMARY_COLOR_ARB GL_PRIMARY_COLOR +#define GL_PREVIOUS_ARB GL_PREVIOUS + #endif #ifdef EE_GLES diff --git a/src/graphics/cframebuffer.cpp b/src/graphics/cframebuffer.cpp index 707cc067e..32b983855 100644 --- a/src/graphics/cframebuffer.cpp +++ b/src/graphics/cframebuffer.cpp @@ -64,9 +64,9 @@ void cFrameBuffer::SetBufferView() { mPrevView = mWindow->GetView(); + GLi->Viewport( 0, 0, mWidth, mHeight ); GLi->MatrixMode( GL_PROJECTION ); GLi->LoadIdentity(); - GLi->Viewport( 0, 0, mWidth, mHeight ); GLi->Ortho( 0.0f, mWidth, 0.f, mHeight, -1000.0f, 1000.0f ); GLi->MatrixMode( GL_MODELVIEW ); GLi->LoadIdentity(); diff --git a/src/graphics/cshader.cpp b/src/graphics/cshader.cpp index 177d7567e..1d460835d 100644 --- a/src/graphics/cshader.cpp +++ b/src/graphics/cshader.cpp @@ -68,15 +68,20 @@ cShader::cShader( const Uint32& Type, const char ** Data, const Uint32& NumLines } cShader::~cShader() { - if ( 0 != mGLId ) + if ( 0 != mGLId ) { + #ifndef EE_GLES1 glDeleteShader( mGLId ); + #endif + } } void cShader::Init( const Uint32& Type ) { mType = Type; mValid = false; mCompiled = false; + #ifndef EE_GLES1 mGLId = glCreateShader( mType ); + #endif } void cShader::Reload() { @@ -121,9 +126,11 @@ void cShader::SetSource( const std::string& Source ) { EnsureVersion(); + #ifndef EE_GLES1 const char * src = reinterpret_cast ( &mSource[0] ); glShaderSource( mGLId, 1, &src, NULL ); + #endif } void cShader::SetSource( const char** Data, const Uint32& NumLines ) { @@ -158,6 +165,8 @@ bool cShader::Compile() { return false; } + #ifndef EE_GLES1 + glCompileShader( GetId() ); mCompiled = true; @@ -186,6 +195,8 @@ bool cShader::Compile() { cLog::instance()->Write( "Shader Loaded Succesfully" ); } + #endif + return mValid; } diff --git a/src/graphics/cshaderprogram.cpp b/src/graphics/cshaderprogram.cpp index 77fca4090..b11c99b8b 100644 --- a/src/graphics/cshaderprogram.cpp +++ b/src/graphics/cshaderprogram.cpp @@ -116,8 +116,11 @@ cShaderProgram::cShaderProgram( const char ** VertexShaderData, const Uint32& Nu } cShaderProgram::~cShaderProgram() { - if ( Handler() > 0 ) + if ( Handler() > 0 ) { + #ifndef EE_GLES1 glDeleteProgram( Handler() ); + #endif + } mUniformLocations.clear(); mAttributeLocations.clear(); @@ -138,7 +141,9 @@ void cShaderProgram::RemoveFromManager() { void cShaderProgram::Init() { if ( GLi->ShadersSupported() && 0 == Handler() ) { + #ifndef EE_GLES1 mHandler = glCreateProgram(); + #endif mValid = false; mUniformLocations.clear(); mAttributeLocations.clear(); @@ -173,7 +178,9 @@ void cShaderProgram::AddShader( cShader* Shader ) { } if ( 0 != Handler() ) { + #ifndef EE_GLES1 glAttachShader( Handler(), Shader->GetId() ); + #endif mShaders.push_back( Shader ); } @@ -185,8 +192,10 @@ void cShaderProgram::AddShaders( const std::vector& Shaders ) { } bool cShaderProgram::Link() { + #ifndef EE_GLES1 glLinkProgram( Handler() ); + Int32 linked; glGetProgramiv( Handler(), GL_LINK_STATUS, &linked ); mValid = 0 != linked; @@ -197,6 +206,8 @@ bool cShaderProgram::Link() { glGetProgramInfoLog( Handler(), logarraysize, &logsize, reinterpret_cast( &mLinkLog[0] ) ); + #endif + if ( !mValid ) { cLog::instance()->Write( "cShaderProgram::Link(): Couldn't link program. Log follows:" + mLinkLog ); #ifdef EE_DEBUG @@ -228,8 +239,10 @@ Int32 cShaderProgram::UniformLocation( const std::string& Name ) { std::map::iterator it = mUniformLocations.find( Name ); if ( it == mUniformLocations.end() ) { + #ifndef EE_GLES1 Int32 Location = glGetUniformLocation( Handler(), Name.c_str() ); mUniformLocations[Name] = Location; + #endif } return mUniformLocations[Name]; } @@ -240,8 +253,10 @@ Int32 cShaderProgram::AttributeLocation( const std::string& Name ) { std::map::iterator it = mAttributeLocations.find( Name ); if ( it == mAttributeLocations.end() ) { + #ifndef EE_GLES1 Int32 Location = glGetAttribLocation( Handler(), Name.c_str() ); mAttributeLocations[Name] = Location; + #endif } return mAttributeLocations[Name]; } @@ -254,8 +269,11 @@ void cShaderProgram::InvalidateLocations() { bool cShaderProgram::SetUniform( const std::string& Name, float Value ) { Int32 Location = UniformLocation( Name ); - if ( Location >= 0 ) + if ( Location >= 0 ) { + #ifndef EE_GLES1 glUniform1f( Location, Value ); + #endif + } return ( Location >= 0 ); } @@ -263,8 +281,11 @@ bool cShaderProgram::SetUniform( const std::string& Name, float Value ) { bool cShaderProgram::SetUniform( const std::string& Name, eeVector2ff Value ) { Int32 Location = UniformLocation( Name ); - if ( Location >= 0 ) + if ( Location >= 0 ) { + #ifndef EE_GLES1 glUniform2fv( Location, 1, reinterpret_cast( &Value ) ); + #endif + } return ( Location >= 0 ); } @@ -272,8 +293,11 @@ bool cShaderProgram::SetUniform( const std::string& Name, eeVector2ff Value ) { bool cShaderProgram::SetUniform( const std::string& Name, eeVector3ff Value ) { Int32 Location = UniformLocation( Name ); - if ( Location >= 0 ) + if ( Location >= 0 ) { + #ifndef EE_GLES1 glUniform3fv( Location, 1, reinterpret_cast( &Value ) ); + #endif + } return ( Location >= 0 ); } @@ -281,8 +305,11 @@ bool cShaderProgram::SetUniform( const std::string& Name, eeVector3ff Value ) { bool cShaderProgram::SetUniform( const std::string& Name, float x, float y, float z, float w ) { Int32 Location = UniformLocation( Name ); - if ( Location >= 0 ) + if ( Location >= 0 ) { + #ifndef EE_GLES1 glUniform4f( Location, x, y, z, w ); + #endif + } return ( Location >= 0 ); } @@ -290,15 +317,20 @@ bool cShaderProgram::SetUniform( const std::string& Name, float x, float y, floa bool cShaderProgram::SetUniform( const std::string& Name, Int32 Value ) { Int32 Location = UniformLocation( Name ); - if ( Location >= 0 ) + if ( Location >= 0 ) { + #ifndef EE_GLES1 glUniform1i( Location, Value ); + #endif + } return ( Location >= 0 ); } bool cShaderProgram::SetUniform( const Int32& Location, Int32 Value ) { if ( -1 != Location ) { + #ifndef EE_GLES1 glUniform1i( Location, Value ); + #endif return true; } @@ -308,7 +340,10 @@ bool cShaderProgram::SetUniform( const Int32& Location, Int32 Value ) { bool cShaderProgram::SetUniform( const Int32& Location, float Value ) { if ( -1 != Location ) { + #ifndef EE_GLES1 glUniform1f( Location, Value ); + #endif + return true; } @@ -317,7 +352,10 @@ bool cShaderProgram::SetUniform( const Int32& Location, float Value ) { bool cShaderProgram::SetUniform( const Int32& Location, eeVector2ff Value ) { if ( -1 != Location ) { + #ifndef EE_GLES1 glUniform2fv( Location, 1, reinterpret_cast( &Value ) ); + #endif + return true; } @@ -326,7 +364,10 @@ bool cShaderProgram::SetUniform( const Int32& Location, eeVector2ff Value ) { bool cShaderProgram::SetUniform( const Int32& Location, eeVector3ff Value ) { if ( -1 != Location ) { + #ifndef EE_GLES1 glUniform3fv( Location, 1, reinterpret_cast( &Value ) ); + #endif + return true; } @@ -335,7 +376,10 @@ bool cShaderProgram::SetUniform( const Int32& Location, eeVector3ff Value ) { bool cShaderProgram::SetUniform( const Int32& Location, float x, float y, float z, float w ) { if ( -1 != Location ) { + #ifndef EE_GLES1 glUniform4f( Location, x, y, z, w ); + #endif + return true; } @@ -344,7 +388,9 @@ bool cShaderProgram::SetUniform( const Int32& Location, float x, float y, float bool cShaderProgram::SetUniformMatrix( const Int32& Location, const float * Value ) { if ( -1 != Location ) { + #ifndef EE_GLES1 glUniformMatrix4fv( Location, 1, false, Value ); + #endif return true; } @@ -355,8 +401,11 @@ bool cShaderProgram::SetUniformMatrix( const Int32& Location, const float * Valu bool cShaderProgram::SetUniformMatrix( const std::string Name, const float * Value ) { Int32 Location = UniformLocation( Name ); - if ( Location >= 0 ) + if ( Location >= 0 ) { + #ifndef EE_GLES1 glUniformMatrix4fv( Location, 1, false, Value ); + #endif + } return ( Location >= 0 ); } diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp index 11336df3f..58a3ed856 100755 --- a/src/graphics/ctexture.cpp +++ b/src/graphics/ctexture.cpp @@ -602,6 +602,10 @@ void cTexture::DrawEx( const eeFloat &x, const eeFloat &y, const eeFloat &width, BR->DrawOpt(); } +void cTexture::DrawEx2( const eeFloat &x, const eeFloat &y, const eeFloat &width, const eeFloat &height, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color, const EE_PRE_BLEND_FUNC &blend, const EE_RENDERTYPE &Effect, const bool &ScaleCentered, const eeRecti& texSector ) { + DrawEx( x, y, width, height, Angle, Scale, Color, Color, Color, Color, blend, Effect, ScaleCentered, texSector ); +} + void cTexture::DrawQuad( const eeQuad2f& Q, const eeFloat &offsetx, const eeFloat &offsety, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color, const EE_PRE_BLEND_FUNC &blend, const eeRecti& texSector) { DrawQuadEx( Q, offsetx, offsety, Angle, Scale, Color, Color, Color, Color, blend, texSector); } diff --git a/src/graphics/ctexture.hpp b/src/graphics/ctexture.hpp index f8aaed95e..a9ae671e1 100755 --- a/src/graphics/ctexture.hpp +++ b/src/graphics/ctexture.hpp @@ -171,6 +171,21 @@ class EE_API cTexture : public cImage { */ void DrawEx( const eeFloat &x, const eeFloat &y, const eeFloat &width = 0.0f, const eeFloat &height = 0.0f, const eeFloat &Angle = 0, const eeFloat &Scale = 1.0f, const eeColorA& Color0 = eeColorA(255,255,255,255), const eeColorA& Color1 = eeColorA(255,255,255,255), const eeColorA& Color2 = eeColorA(255,255,255,255), const eeColorA& Color3 = eeColorA(255,255,255,255), const EE_PRE_BLEND_FUNC &blend = ALPHA_NORMAL, const EE_RENDERTYPE &Effect = RN_NORMAL, const bool &ScaleCentered = true, const eeRecti& texSector = eeRecti(0,0,0,0) ); + /** Render the texture on screen + * @param x The x position on screen + * @param y The y position on screen + * @param width The width of the texture rendered ( when Scale = 1, otherwise this width will be scaled like width * Scale ) + * @param height The height of the texture rendered ( when Scale = 1, otherwise this height will be scaled like height * Scale ) + * @param Angle The Angle of the texture rendered + * @param Scale The Scale factor of the rendered texture + * @param Color The texture color + * @param blend Set the Blend Mode ( default ALPHA_NORMAL ) + * @param Effect Set the Render Effect ( default RN_NORMAL, no effect ) + * @param ScaleCentered If true the texture will be scaled centered, otherwise will be scale from the Top - Left Corner + * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture ) + */ + void DrawEx2( const eeFloat &x, const eeFloat &y, const eeFloat &width = 0.0f, const eeFloat &height = 0.0f, const eeFloat &Angle = 0, const eeFloat &Scale = 1.0f, const eeColorA& Color = eeColorA(255,255,255,255), const EE_PRE_BLEND_FUNC &blend = ALPHA_NORMAL, const EE_RENDERTYPE &Effect = RN_NORMAL, const bool &ScaleCentered = true, const eeRecti& texSector = eeRecti(0,0,0,0) ); + /** Render a GL_QUAD on Screen * @param Q The eeQuad2f * @param offsetx The Offset X applyed to all the coordinates on eeQuad2f diff --git a/src/graphics/cvertexbuffervbo.cpp b/src/graphics/cvertexbuffervbo.cpp index 3036baa3b..5f2b5bb13 100644 --- a/src/graphics/cvertexbuffervbo.cpp +++ b/src/graphics/cvertexbuffervbo.cpp @@ -25,7 +25,7 @@ cVertexBufferVBO::~cVertexBufferVBO() { glDeleteBuffersARB( 1, (GLuint *)&mElementHandle ); } - #if !defined( EE_GLES2 ) && EE_PLATFORM != EE_PLATFORM_HAIKU + #if !defined( EE_GLES ) && EE_PLATFORM != EE_PLATFORM_HAIKU if ( GLv_3 == GLi->Version() ) { glDeleteVertexArrays( 1, &mVAO ); } @@ -47,7 +47,7 @@ bool cVertexBufferVBO::Compile() { if( mCompiled ) return false; - #if !defined( EE_GLES2 ) && EE_PLATFORM != EE_PLATFORM_HAIKU + #if !defined( EE_GLES ) && EE_PLATFORM != EE_PLATFORM_HAIKU if ( GLv_3 == GLi->Version() ) { glGenVertexArrays( 1, &mVAO ); glBindVertexArray( mVAO ); @@ -100,7 +100,7 @@ void cVertexBufferVBO::Draw() { return; if ( GLv_3 == GLi->Version() || GLv_ES2 == GLi->Version() ) { - #if !defined( EE_GLES2 ) && EE_PLATFORM != EE_PLATFORM_HAIKU + #if !defined( EE_GLES ) && EE_PLATFORM != EE_PLATFORM_HAIKU glBindVertexArray( mVAO ); #endif @@ -132,9 +132,11 @@ void cVertexBufferVBO::Draw() { } void cVertexBufferVBO::SetVertexStates() { + #ifdef EE_GL3_ENABLED GLint index; + #endif - #if !defined( EE_GLES2 ) && EE_PLATFORM != EE_PLATFORM_HAIKU + #if !defined( EE_GLES ) && EE_PLATFORM != EE_PLATFORM_HAIKU if ( GLv_3 == GLi->Version() ) { if ( mBuffersSet ) { return; diff --git a/src/graphics/renderer/cgl.cpp b/src/graphics/renderer/cgl.cpp index 86ad46bb4..b123c492d 100644 --- a/src/graphics/renderer/cgl.cpp +++ b/src/graphics/renderer/cgl.cpp @@ -159,7 +159,7 @@ bool cGL::ShadersSupported() { } Uint32 cGL::GetTextureParamEnum( const EE_TEXTURE_PARAM& Type ) { - #ifndef EE_GLES2 + #ifndef EE_GLES switch( Type ) { case TEX_PARAM_COLOR_FUNC: return GL_COMBINE_RGB_ARB; case TEX_PARAM_ALPHA_FUNC: return GL_COMBINE_ALPHA_ARB; @@ -258,7 +258,7 @@ void cGL::Scissor ( GLint x, GLint y, GLsizei width, GLsizei height ) { } void cGL::PolygonMode( GLenum face, GLenum mode ) { - #ifndef EE_GLES2 + #ifndef EE_GLES glPolygonMode( face, mode ); #endif } @@ -284,11 +284,13 @@ void cGL::BlendFunc ( GLenum sfactor, GLenum dfactor ) { } void cGL::SetShader( cShaderProgram * Shader ) { + #ifndef EE_GLES1 if ( NULL != Shader ) { glUseProgram( Shader->Handler() ); } else { glUseProgram( 0 ); } + #endif } bool cGL::IsLineSmooth() { @@ -349,4 +351,42 @@ std::string cGL::GetShadingLanguageVersion() { return std::string( "Shaders not supported" ); } +void cGL::GetViewport( GLint * viewport ) { + glGetIntegerv( GL_VIEWPORT, viewport ); +} + +eeVector3f cGL::ProjectCurrent( const eeVector3f& point ) { + GLfloat projMat[16]; + GetCurrentMatrix( GL_PROJECTION_MATRIX, projMat ); + + GLfloat modelMat[16]; + GetCurrentMatrix( GL_MODELVIEW_MATRIX, modelMat ); + + GLint viewPort[4]; + GetViewport( viewPort ); + + eeVector3f tv3; + + Project( point.x, point.y, point.z, projMat, modelMat, viewPort, &tv3.x, &tv3.y, &tv3.z ); + + return tv3; +} + +eeVector3f cGL::UnProjectCurrent( const eeVector3f& point ) { + GLfloat projMat[16]; + GetCurrentMatrix( GL_PROJECTION_MATRIX, projMat ); + + GLfloat modelMat[16]; + GetCurrentMatrix( GL_MODELVIEW_MATRIX, modelMat ); + + GLint viewPort[4]; + GetViewport( viewPort ); + + eeVector3f tv3; + + UnProject( point.x, point.y, point.z, projMat, modelMat, viewPort, &tv3.x, &tv3.y, &tv3.z ); + + return tv3; +} + }} diff --git a/src/graphics/renderer/cgl.hpp b/src/graphics/renderer/cgl.hpp index 76014a874..2b7ccdd7b 100644 --- a/src/graphics/renderer/cgl.hpp +++ b/src/graphics/renderer/cgl.hpp @@ -185,6 +185,16 @@ class EE_API cGL { virtual void GetCurrentMatrix( GLenum mode, GLfloat * m ) = 0; virtual GLenum GetCurrentMatrixMode() = 0; + + void GetViewport( GLint * viewport ); + + virtual GLint Project( GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *winx, GLfloat *winy, GLfloat *winz ) = 0; + + virtual GLint UnProject( GLfloat winx, GLfloat winy, GLfloat winz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *objx, GLfloat *objy, GLfloat *objz ) = 0; + + eeVector3f ProjectCurrent( const eeVector3f& point ); + + eeVector3f UnProjectCurrent( const eeVector3f& point ); protected: enum GLStateFlags { GLSF_LINE_SMOOTH = 0, diff --git a/src/graphics/renderer/crenderergl.cpp b/src/graphics/renderer/crenderergl.cpp index 72d681877..d03b90116 100644 --- a/src/graphics/renderer/crenderergl.cpp +++ b/src/graphics/renderer/crenderergl.cpp @@ -1,5 +1,37 @@ #include "crenderergl.hpp" +/* + * Some of this code is based on the implementation of the functions from + * the Mesa3D project ( http://mesa3d.org/ ), which is licensed + * under the MIT license, which allows use, modification, and + * redistribution + * + * Out of respect for the original authors, this is licensed under + * the Mesa (MIT) license. Original license follows: + * + * ----------------------------------------------------------------------- + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + namespace EE { namespace Graphics { #ifndef EE_GLES2 @@ -58,37 +90,6 @@ void cRendererGL::Ortho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat to glOrtho( left, right, bottom, top, zNear, zFar ); } -/* - * This is a modified version of the function of the same name from - * the Mesa3D project ( http://mesa3d.org/ ), which is licensed - * under the MIT license, which allows use, modification, and - * redistribution - * - * Out of respect for the original authors, this is licensed under - * the Mesa (MIT) license. Original license follows: - * - * ----------------------------------------------------------------------- - * - * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ void cRendererGL::LookAt( GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ ) { GLfloat m[16]; GLfloat x[3], y[3], z[3]; @@ -297,6 +298,142 @@ GLenum cRendererGL::GetCurrentMatrixMode() { return (GLenum)mode; } + +static int __gluInvertMatrixd( const GLfloat m[16], GLfloat invOut[16] ) { + float inv[16], det; + int i; + + inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15] + + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10]; + inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15] + - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10]; + inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15] + + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9]; + inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14] + - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9]; + inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15] + - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10]; + inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15] + + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10]; + inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15] + - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9]; + inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14] + + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9]; + inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15] + + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6]; + inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15] + - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6]; + inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15] + + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5]; + inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14] + - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5]; + inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11] + - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6]; + inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11] + + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6]; + inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11] + - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5]; + inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10] + + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5]; + + det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12]; + if (det == 0) + return GL_FALSE; + + det = 1.0 / det; + + for (i = 0; i < 16; i++) + invOut[i] = inv[i] * det; + + return GL_TRUE; +} + +static void __gluMultMatricesd(const GLfloat a[16], const GLfloat b[16], GLfloat r[16] ) { + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + r[i*4+j] = + a[i*4+0]*b[0*4+j] + + a[i*4+1]*b[1*4+j] + + a[i*4+2]*b[2*4+j] + + a[i*4+3]*b[3*4+j]; + } + } +} + +static void __gluMultMatrixVecd( const GLfloat matrix[16], const GLfloat in[4], GLfloat out[4] ) { + int i; + for (i=0; i<4; i++) { + out[i] = + in[0] * matrix[0*4+i] + + in[1] * matrix[1*4+i] + + in[2] * matrix[2*4+i] + + in[3] * matrix[3*4+i]; + } +} + +GLint cRendererGL::Project( GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *winx, GLfloat *winy, GLfloat *winz ) { + float in[4]; + float out[4]; + + in[0]=objx; + in[1]=objy; + in[2]=objz; + in[3]=1.0; + __gluMultMatrixVecd(modelMatrix, in, out); + __gluMultMatrixVecd(projMatrix, out, in); + if (in[3] == 0.0) return GL_FALSE; + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + /* Map x, y and z to range 0-1 */ + in[0] = in[0] * 0.5 + 0.5; + in[1] = in[1] * 0.5 + 0.5; + in[2] = in[2] * 0.5 + 0.5; + + /* Map x,y to viewport */ + in[0] = in[0] * viewport[2] + viewport[0]; + in[1] = in[1] * viewport[3] + viewport[1]; + + *winx=in[0]; + *winy=in[1]; + *winz=in[2]; + return GL_TRUE; +} + +GLint cRendererGL::UnProject( GLfloat winx, GLfloat winy, GLfloat winz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *objx, GLfloat *objy, GLfloat *objz ) { + float finalMatrix[16]; + float in[4]; + float out[4]; + + __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE); + + in[0]=winx; + in[1]=winy; + in[2]=winz; + in[3]=1.0; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecd(finalMatrix, in, out); + if (out[3] == 0.0) return GL_FALSE; + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + *objx = out[0]; + *objy = out[1]; + *objz = out[2]; + return GL_TRUE; +} + #endif }} diff --git a/src/graphics/renderer/crenderergl.hpp b/src/graphics/renderer/crenderergl.hpp index a18ae21b3..51f143d8a 100644 --- a/src/graphics/renderer/crenderergl.hpp +++ b/src/graphics/renderer/crenderergl.hpp @@ -71,6 +71,10 @@ class EE_API cRendererGL : public cGL { void GetCurrentMatrix( GLenum mode, GLfloat * m ); GLenum GetCurrentMatrixMode(); + + GLint Project( GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *winx, GLfloat *winy, GLfloat *winz ); + + GLint UnProject( GLfloat winx, GLfloat winy, GLfloat winz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *objx, GLfloat *objy, GLfloat *objz ); protected: }; diff --git a/src/graphics/renderer/crenderergl3.cpp b/src/graphics/renderer/crenderergl3.cpp index 626e7b77f..4eb1650e0 100644 --- a/src/graphics/renderer/crenderergl3.cpp +++ b/src/graphics/renderer/crenderergl3.cpp @@ -557,11 +557,13 @@ void cRendererGL3::fromGLMmat4( glm::mat4 from, GLfloat * to ) { void cRendererGL3::GetCurrentMatrix( GLenum mode, GLfloat * m ) { switch ( mode ) { case GL_PROJECTION: + case GL_PROJECTION_MATRIX: { fromGLMmat4( mProjectionMatrix.top(), m ); break; } case GL_MODELVIEW: + case GL_MODELVIEW_MATRIX: { fromGLMmat4( mModelViewMatrix.top(), m ); break; @@ -578,11 +580,13 @@ void cRendererGL3::MatrixMode(GLenum mode) { switch ( mCurrentMode ) { case GL_PROJECTION: + case GL_PROJECTION_MATRIX: { mCurMatrix = &mProjectionMatrix; break; } case GL_MODELVIEW: + case GL_MODELVIEW_MATRIX: { mCurMatrix = &mModelViewMatrix; break; @@ -798,6 +802,36 @@ std::string cRendererGL3::GetBaseVertexShader() { return mBaseVertexShader; } +GLint cRendererGL3::Project( GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *winx, GLfloat *winy, GLfloat *winz ) { + glm::vec3 tv3( glm::project( glm::vec3( objx, objy, objz ), toGLMmat4( modelMatrix ), toGLMmat4( projMatrix ), glm::vec4( viewport[0], viewport[1], viewport[2], viewport[3] ) ) ); + + if ( NULL != winx ) + *winx = tv3.x; + + if ( NULL != winy ) + *winy = tv3.y; + + if ( NULL != winz ) + *winz = tv3.z; + + return GL_TRUE; +} + +GLint cRendererGL3::UnProject( GLfloat winx, GLfloat winy, GLfloat winz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *objx, GLfloat *objy, GLfloat *objz ) { + glm::vec3 tv3( glm::unProject( glm::vec3( winx, winy, winz ), toGLMmat4( modelMatrix ), toGLMmat4( projMatrix ), glm::vec4( viewport[0], viewport[1], viewport[2], viewport[3] ) ) ); + + if ( NULL != objx ) + *objx = tv3.x; + + if ( NULL != objy ) + *objy = tv3.y; + + if ( NULL != objz ) + *objz = tv3.z; + + return GL_TRUE; +} + }} #endif diff --git a/src/graphics/renderer/crenderergl3.hpp b/src/graphics/renderer/crenderergl3.hpp index cb529ce15..82eaf84c5 100644 --- a/src/graphics/renderer/crenderergl3.hpp +++ b/src/graphics/renderer/crenderergl3.hpp @@ -124,6 +124,10 @@ class EE_API cRendererGL3 : public cGL { void BindGlobalVAO(); std::string GetBaseVertexShader(); + + GLint Project( GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *winx, GLfloat *winy, GLfloat *winz ); + + GLint UnProject( GLfloat winx, GLfloat winy, GLfloat winz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat *objx, GLfloat *objy, GLfloat *objz ); protected: std::stack mProjectionMatrix; // cpu-side GLint mProjectionMatrix_id; // cpu-side hook to shader uniform diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 08f3eb94c..ee0a4593a 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1210,7 +1210,7 @@ void cEETest::Render() { ColRR1, ColRR2, ColRR3, ColRR4 ); - mEEText.Draw( 0.f, (eeFloat)mWindow->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang ); + mEEText.Draw( 0.f, (eeFloat)mWindow->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER ); mInfoText.Draw( 6.f, 6.f ); diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp index 134a2ff06..42663d61b 100644 --- a/src/ui/cuimanager.cpp +++ b/src/ui/cuimanager.cpp @@ -229,6 +229,7 @@ cUIControl * cUIManager::DownControl() const { } void cUIManager::Draw() { + cGlobalBatchRenderer::instance()->Draw(); mControl->InternalDraw(); cGlobalBatchRenderer::instance()->Draw(); } diff --git a/src/window/cinput.cpp b/src/window/cinput.cpp index 9a089ab71..390dc3c3b 100644 --- a/src/window/cinput.cpp +++ b/src/window/cinput.cpp @@ -40,9 +40,9 @@ void cInput::SendEvent( InputEvent * Event ) { void cInput::ProcessEvent( InputEvent * Event ) { switch( Event->Type ) { case InputEvent::KeyDown: - { - if ( Event->key.keysym.sym > EE_KEYS_NUM ) - break; + { + if ( Event->key.keysym.sym > EE_KEYS_NUM ) + break; if ( Event->key.keysym.mod != 0xFFFFFFFF ) mInputMod = Event->key.keysym.mod; @@ -51,9 +51,9 @@ void cInput::ProcessEvent( InputEvent * Event ) { break; } case InputEvent::KeyUp: - { - if ( Event->key.keysym.sym > EE_KEYS_NUM ) - break; + { + if ( Event->key.keysym.sym > EE_KEYS_NUM ) + break; PushKey( &mKeysDown [ Event->key.keysym.sym / 8 ], Event->key.keysym.sym % 8, false ); PushKey( &mKeysUp [ Event->key.keysym.sym / 8 ], Event->key.keysym.sym % 8, true ); @@ -211,6 +211,10 @@ eeVector2i cInput::GetMousePos() const { return mMousePos; } +void cInput::SetMousePos( const eeVector2i& Pos ) { + mMousePos = Pos; +} + eeVector2f cInput::GetMousePosf() { return eeVector2f( (eeFloat)mMousePos.x, (eeFloat)mMousePos.y ); } diff --git a/src/window/cinput.hpp b/src/window/cinput.hpp index 824f9c951..2243af718 100644 --- a/src/window/cinput.hpp +++ b/src/window/cinput.hpp @@ -110,6 +110,9 @@ class EE_API cInput { /** @return The position vector converted to float */ eeVector2f GetMousePosf(); + /** This will change the value of the mouse pos, will not REALLY move the mouse ( for that is InjectMousePos ). */ + void SetMousePos( const eeVector2i& Pos ); + /** @return The mouse position over the current view */ eeVector2i GetMousePosFromView( const cView& View ); diff --git a/src/window/cwindow.cpp b/src/window/cwindow.cpp index b8f4e2a17..9f2404686 100644 --- a/src/window/cwindow.cpp +++ b/src/window/cwindow.cpp @@ -54,7 +54,7 @@ bool cWindow::Resizeable() const { } void cWindow::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height, const bool& UpdateProjectionMatrix ) { - GLi->Viewport( x, GetHeight() - Height - y, Width, Height ); + GLi->Viewport( x, GetHeight() - ( y + Height ), Width, Height ); if ( UpdateProjectionMatrix ) { GLi->MatrixMode( GL_PROJECTION ); @@ -99,13 +99,16 @@ void cWindow::Setup2D( const bool& KeepView ) { GLi->Disable( GL_DEPTH_TEST ); GLi->Disable( GL_LIGHTING ); - if ( !KeepView ) + if ( !KeepView ) { SetView( mDefaultView ); + mCurrentView->NeedUpdate(); + } + cTextureFactory::instance()->SetPreBlendFunc( ALPHA_NORMAL, true ); if ( GLv_3 != GLi->Version() ) { - #ifndef EE_GLES + #ifndef EE_GLES2 GLi->TexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); GLi->TexEnvi( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE ); #endif @@ -271,7 +274,7 @@ void cWindow::Display() { void cWindow::ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) { cGlobalBatchRenderer::instance()->Draw(); - GLi->Scissor( x, GetHeight() - Height - y, Width, Height ); + GLi->Scissor( x, GetHeight() - ( y + Height ), Width, Height ); GLi->Enable( GL_SCISSOR_TEST ); }