mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-11 17:17:42 +03:00
Refactored 2d clip planes stack.
--HG-- branch : dev
This commit is contained in:
@@ -11,8 +11,6 @@ namespace EE { namespace Graphics {
|
||||
|
||||
class EE_API Drawable {
|
||||
public:
|
||||
Drawable( EE_DRAWABLE_TYPE drawableType );
|
||||
|
||||
virtual Sizef getSize() = 0;
|
||||
|
||||
virtual void draw() = 0;
|
||||
@@ -49,6 +47,8 @@ class EE_API Drawable {
|
||||
Color mColor;
|
||||
Vector2f mPosition;
|
||||
|
||||
Drawable( EE_DRAWABLE_TYPE drawableType );
|
||||
|
||||
virtual void onAlphaChange();
|
||||
|
||||
virtual void onColorFilterChange();
|
||||
|
||||
@@ -9,8 +9,6 @@ class VertexBuffer;
|
||||
|
||||
class EE_API PrimitiveDrawable : public Drawable {
|
||||
public:
|
||||
PrimitiveDrawable( EE_DRAWABLE_TYPE drawableType );
|
||||
|
||||
virtual ~PrimitiveDrawable();
|
||||
|
||||
virtual void draw( const Vector2f& position, const Sizef& size );
|
||||
@@ -33,6 +31,8 @@ class EE_API PrimitiveDrawable : public Drawable {
|
||||
/** @return The line with to draw primitives */
|
||||
const Float& getLineWidth() const;
|
||||
protected:
|
||||
PrimitiveDrawable( EE_DRAWABLE_TYPE drawableType );
|
||||
|
||||
EE_FILL_MODE mFillMode;
|
||||
EE_BLEND_MODE mBlendMode;
|
||||
Float mLineWidth;
|
||||
|
||||
@@ -48,7 +48,9 @@ class EE_API ClippingMask {
|
||||
void stencilMaskDisable( bool clearMasks = false );
|
||||
protected:
|
||||
std::list<Rectf> mScissorsClipped;
|
||||
std::list<Rectf> mPlanesClipped;
|
||||
bool mPushScissorClip;
|
||||
bool mPushClip;
|
||||
|
||||
std::vector<const Drawable*> mDrawables;
|
||||
Mode mMode;
|
||||
|
||||
@@ -223,14 +223,12 @@ class EE_API Renderer {
|
||||
|
||||
Uint32 mExtensions;
|
||||
Uint32 mStateFlags;
|
||||
bool mPushClip;
|
||||
bool mQuadsSupported;
|
||||
bool mBlendEnabled;
|
||||
int mQuadVertexs;
|
||||
float mLineWidth;
|
||||
unsigned int mCurVAO;
|
||||
|
||||
std::list<Rectf> mPlanesClipped;
|
||||
ClippingMask * mClippingMask;
|
||||
private:
|
||||
void writeExtension( Uint8 Pos, Uint32 BitWrite );
|
||||
|
||||
@@ -48,12 +48,36 @@ void ClippingMask::clipDisable() {
|
||||
|
||||
void ClippingMask::clipPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
|
||||
GlobalBatchRenderer::instance()->draw();
|
||||
GLi->clip2DPlaneEnable( x, y, Width, Height );
|
||||
|
||||
Rectf r( x, y, x + Width, y + Height );
|
||||
|
||||
if ( !mPlanesClipped.empty() ) {
|
||||
Rectf r2 = mPlanesClipped.back();
|
||||
r.shrink( r2 );
|
||||
}
|
||||
|
||||
GLi->clip2DPlaneEnable( r.Left, r.Top, r.getWidth(), r.getHeight() );
|
||||
|
||||
if ( mPushClip ) {
|
||||
mPlanesClipped.push_back( r );
|
||||
}
|
||||
}
|
||||
|
||||
void ClippingMask::clipPlaneDisable() {
|
||||
GlobalBatchRenderer::instance()->draw();
|
||||
GLi->clip2DPlaneDisable();
|
||||
|
||||
if ( ! mPlanesClipped.empty() ) { // This should always be true
|
||||
mPlanesClipped.pop_back();
|
||||
}
|
||||
|
||||
if ( mPlanesClipped.empty() ) {
|
||||
GLi->clip2DPlaneDisable();
|
||||
} else {
|
||||
Rectf R( mPlanesClipped.back() );
|
||||
mPushClip = false;
|
||||
clipPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() );
|
||||
mPushClip = true;
|
||||
}
|
||||
}
|
||||
|
||||
ClippingMask::ClippingMask() :
|
||||
|
||||
@@ -110,7 +110,6 @@ void Renderer::destroySingleton() {
|
||||
Renderer::Renderer() :
|
||||
mExtensions(0),
|
||||
mStateFlags( 1 << RSF_LINE_SMOOTH ),
|
||||
mPushClip( true ),
|
||||
mQuadsSupported( true ),
|
||||
mBlendEnabled( false ),
|
||||
mQuadVertexs( 4 ),
|
||||
|
||||
@@ -231,11 +231,6 @@ void RendererGL::pointSize( float size ) {
|
||||
void RendererGL::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
|
||||
Rectf r( x, y, x + Width, y + Height );
|
||||
|
||||
if ( !mPlanesClipped.empty() ) {
|
||||
Rectf r2 = mPlanesClipped.back();
|
||||
r.shrink( r2 );
|
||||
}
|
||||
|
||||
double clip_left[] = { 1.0 , 0.0 , 0.0, -r.Left };
|
||||
double clip_right[] = { -1.0, 0.0 , 0.0, r.Right };
|
||||
double clip_top[] = { 0.0 , 1.0 , 0.0, -r.Top };
|
||||
@@ -250,28 +245,13 @@ void RendererGL::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32&
|
||||
clipPlane(GL_CLIP_PLANE1, clip_right);
|
||||
clipPlane(GL_CLIP_PLANE2, clip_top);
|
||||
clipPlane(GL_CLIP_PLANE3, clip_bottom);
|
||||
|
||||
if ( mPushClip ) {
|
||||
mPlanesClipped.push_back( r );
|
||||
}
|
||||
}
|
||||
|
||||
void RendererGL::clip2DPlaneDisable() {
|
||||
if ( ! mPlanesClipped.empty() ) { // This should always be true
|
||||
mPlanesClipped.pop_back();
|
||||
}
|
||||
|
||||
if ( mPlanesClipped.empty() ) {
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
} else {
|
||||
Rectf R( mPlanesClipped.back() );
|
||||
mPushClip = false;
|
||||
clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() );
|
||||
mPushClip = true;
|
||||
}
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
}
|
||||
|
||||
void RendererGL::clipPlane( unsigned int plane, const double *equation ) {
|
||||
|
||||
@@ -543,11 +543,6 @@ void RendererGL3::matrixMode(unsigned int mode) {
|
||||
void RendererGL3::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
|
||||
Rectf r( x, y, x + Width, y + Height );
|
||||
|
||||
if ( !mPlanesClipped.empty() ) {
|
||||
Rectf r2 = mPlanesClipped.back();
|
||||
r.shrink( r2 );
|
||||
}
|
||||
|
||||
glm::vec4 vclip_left ( 1.0 , 0.0 , 0.0 , -r.Left );
|
||||
glm::vec4 vclip_right ( -1.0 , 0.0 , 0.0 , r.Right );
|
||||
glm::vec4 vclip_top ( 0.0 , 1.0 , 0.0 , -r.Top );
|
||||
@@ -569,28 +564,13 @@ void RendererGL3::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32
|
||||
glUniform4fv( mPlanes[1], 1, static_cast<const float*>( &vclip_right[0] ) );
|
||||
glUniform4fv( mPlanes[2], 1, static_cast<const float*>( &vclip_top[0] ) );
|
||||
glUniform4fv( mPlanes[3], 1, static_cast<const float*>( &vclip_bottom[0] ) );
|
||||
|
||||
if ( mPushClip ) {
|
||||
mPlanesClipped.push_back( r );
|
||||
}
|
||||
}
|
||||
|
||||
void RendererGL3::clip2DPlaneDisable() {
|
||||
if ( ! mPlanesClipped.empty() ) { // This should always be true
|
||||
mPlanesClipped.pop_back();
|
||||
}
|
||||
|
||||
if ( mPlanesClipped.empty() ) {
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
} else {
|
||||
Rectf R( mPlanesClipped.back() );
|
||||
mPushClip = false;
|
||||
clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() );
|
||||
mPushClip = true;
|
||||
}
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
}
|
||||
|
||||
void RendererGL3::pointSize( float size ) {
|
||||
|
||||
@@ -616,11 +616,6 @@ void RendererGL3CP::matrixMode(unsigned int mode) {
|
||||
void RendererGL3CP::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
|
||||
Rectf r( x, y, x + Width, y + Height );
|
||||
|
||||
if ( !mPlanesClipped.empty() ) {
|
||||
Rectf r2 = mPlanesClipped.back();
|
||||
r.shrink( r2 );
|
||||
}
|
||||
|
||||
glm::vec4 vclip_left ( 1.0 , 0.0 , 0.0 , -r.Left );
|
||||
glm::vec4 vclip_right ( -1.0 , 0.0 , 0.0 , r.Right );
|
||||
glm::vec4 vclip_top ( 0.0 , 1.0 , 0.0 , -r.Top );
|
||||
@@ -642,28 +637,13 @@ void RendererGL3CP::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int
|
||||
glUniform4fv( mPlanes[1], 1, static_cast<const float*>( &vclip_right[0] ) );
|
||||
glUniform4fv( mPlanes[2], 1, static_cast<const float*>( &vclip_top[0] ) );
|
||||
glUniform4fv( mPlanes[3], 1, static_cast<const float*>( &vclip_bottom[0] ) );
|
||||
|
||||
if ( mPushClip ) {
|
||||
mPlanesClipped.push_back( r );
|
||||
}
|
||||
}
|
||||
|
||||
void RendererGL3CP::clip2DPlaneDisable() {
|
||||
if ( ! mPlanesClipped.empty() ) { // This should always be true
|
||||
mPlanesClipped.pop_back();
|
||||
}
|
||||
|
||||
if ( mPlanesClipped.empty() ) {
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
} else {
|
||||
Rectf R( mPlanesClipped.back() );
|
||||
mPushClip = false;
|
||||
clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() );
|
||||
mPushClip = true;
|
||||
}
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
}
|
||||
|
||||
void RendererGL3CP::pointSize( float size ) {
|
||||
|
||||
@@ -619,11 +619,6 @@ void RendererGLES2::matrixMode(unsigned int mode) {
|
||||
void RendererGLES2::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
|
||||
Rectf r( x, y, x + Width, y + Height );
|
||||
|
||||
if ( !mPlanesClipped.empty() ) {
|
||||
Rectf r2 = mPlanesClipped.back();
|
||||
r.shrink( r2 );
|
||||
}
|
||||
|
||||
glm::vec4 vclip_left ( 1.0 , 0.0 , 0.0 , -r.Left );
|
||||
glm::vec4 vclip_right ( -1.0 , 0.0 , 0.0 , r.Right );
|
||||
glm::vec4 vclip_top ( 0.0 , 1.0 , 0.0 , -r.Top );
|
||||
@@ -645,28 +640,13 @@ void RendererGLES2::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int
|
||||
glUniform4fv( mPlanes[1], 1, static_cast<const float*>( &vclip_right[0] ) );
|
||||
glUniform4fv( mPlanes[2], 1, static_cast<const float*>( &vclip_top[0] ) );
|
||||
glUniform4fv( mPlanes[3], 1, static_cast<const float*>( &vclip_bottom[0] ) );
|
||||
|
||||
if ( mPushClip ) {
|
||||
mPlanesClipped.push_back( r );
|
||||
}
|
||||
}
|
||||
|
||||
void RendererGLES2::clip2DPlaneDisable() {
|
||||
if ( ! mPlanesClipped.empty() ) { // This should always be true
|
||||
mPlanesClipped.pop_back();
|
||||
}
|
||||
|
||||
if ( mPlanesClipped.empty() ) {
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
} else {
|
||||
Rectf R( mPlanesClipped.back() );
|
||||
mPushClip = false;
|
||||
clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() );
|
||||
mPushClip = true;
|
||||
}
|
||||
GLi->disable(GL_CLIP_PLANE0);
|
||||
GLi->disable(GL_CLIP_PLANE1);
|
||||
GLi->disable(GL_CLIP_PLANE2);
|
||||
GLi->disable(GL_CLIP_PLANE3);
|
||||
}
|
||||
|
||||
void RendererGLES2::pointSize( float size ) {
|
||||
|
||||
Reference in New Issue
Block a user