From 3b4fba409933ffc7ec2f1718b9f0ae37d1191d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 9 Jun 2022 20:22:48 -0300 Subject: [PATCH] Changed BlendMode pre-loaded modes. Now they are a function, since they could be used before the memory initialization provoking errors in emscripten. GLES2 is now the default renderer for emscripten. Fixed several rendering issues with GLES2 as WebGL (point sprites, bad states). Fixed chipmunk in emscripten. Improved debugging for emscripten debug builds. --- bin/assets/shaders/gaussian_blur.frag | 32 ++--- include/eepp/graphics/batchrenderer.hpp | 34 ++--- include/eepp/graphics/blendmode.hpp | 23 ++-- .../eepp/graphics/renderer/renderergles2.hpp | 1 + include/eepp/graphics/scrollparallax.hpp | 9 +- include/eepp/graphics/sprite.hpp | 31 ++--- include/eepp/graphics/text.hpp | 2 +- include/eepp/graphics/texture.hpp | 20 +-- include/eepp/graphics/textureregion.hpp | 6 +- .../eepp/maps/gameobjecttextureregionex.hpp | 2 +- premake4.lua | 24 +++- src/eepp/graphics/batchrenderer.cpp | 39 +----- src/eepp/graphics/blendmode.cpp | 116 ++++++++++++++---- src/eepp/graphics/glyphdrawable.cpp | 2 +- src/eepp/graphics/particlesystem.cpp | 2 +- src/eepp/graphics/primitivedrawable.cpp | 2 +- src/eepp/graphics/primitives.cpp | 2 +- src/eepp/graphics/renderer/renderer.cpp | 2 +- src/eepp/graphics/renderer/renderergles2.cpp | 40 +++--- .../renderer/shaders/primitive.vert.h | 2 + src/eepp/graphics/scrollparallax.cpp | 2 +- src/eepp/graphics/sprite.cpp | 68 +--------- src/eepp/graphics/texture.cpp | 2 +- src/eepp/maps/gameobject.cpp | 3 +- src/eepp/maps/gameobjecttextureregion.cpp | 2 +- src/eepp/maps/gameobjectvirtual.cpp | 2 +- src/eepp/physics/shapepoint.cpp | 3 +- src/eepp/physics/space.cpp | 2 +- src/eepp/scene/node.cpp | 2 +- src/eepp/ui/css/stylesheetproperty.cpp | 8 +- src/eepp/window/window.cpp | 2 +- .../external_shader/external_shader.cpp | 6 +- src/examples/physics/physics.cpp | 62 +++++----- src/examples/sprites/sprites.cpp | 4 +- src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp | 2 +- src/tests/test_all/test.cpp | 23 ++-- src/thirdparty/chipmunk/cpBBTree.c | 7 +- src/thirdparty/chipmunk/cpSpace.c | 7 +- 38 files changed, 311 insertions(+), 287 deletions(-) diff --git a/bin/assets/shaders/gaussian_blur.frag b/bin/assets/shaders/gaussian_blur.frag index 44a1dbbed..2cdae901e 100644 --- a/bin/assets/shaders/gaussian_blur.frag +++ b/bin/assets/shaders/gaussian_blur.frag @@ -1,60 +1,60 @@ uniform sampler2D textureUnit0; uniform vec2 textureRes; -uniform float radius; uniform int dir; +const float radius = 16.; float SCurve (float x) { x = x * 2.0 - 1.0; return -x * abs(x) * 0.5 + x + 0.5; } -vec4 BlurH(sampler2D source, vec2 size, vec2 uv, float radius) { +vec4 BlurH(sampler2D source, vec2 size, vec2 uv) { if (radius >= 1.0) { vec4 A = vec4(0.0); vec4 C = vec4(0.0); float width = 1.0 / size.x; - float divisor = 0.0; + float divisor = 0.0; float weight = 0.0; float radiusMultiplier = 1.0 / radius; - + for (float x = -radius; x <= radius; x++) { A = texture2D(source, uv + vec2(x * width, 0.0)); weight = SCurve(1.0 - (abs(x) * radiusMultiplier)); C += A * weight; - divisor += weight; + divisor += weight; } return vec4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0); } - + return texture2D(source, uv); } -vec4 BlurV(sampler2D source, vec2 size, vec2 uv, float radius) { +vec4 BlurV(sampler2D source, vec2 size, vec2 uv) { if (radius >= 1.0) { - vec4 A = vec4(0.0); - vec4 C = vec4(0.0); + vec4 A = vec4(0.0); + vec4 C = vec4(0.0); float height = 1.0 / size.y; - float divisor = 0.0; + float divisor = 0.0; float weight = 0.0; float radiusMultiplier = 1.0 / radius; - + for (float y = -radius; y <= radius; y++) { A = texture2D(source, uv + vec2(0.0, y * height)); weight = SCurve(1.0 - (abs(y) * radiusMultiplier)); C += A * weight; - divisor += weight; + divisor += weight; } - + return vec4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0); } - + return texture2D(source, uv); } void main() { gl_FragColor = dir != 0 ? - BlurV(textureUnit0, textureRes.xy, gl_TexCoord[0].xy, radius) : - BlurH(textureUnit0, textureRes.xy, gl_TexCoord[0].xy, radius); + BlurV(textureUnit0, textureRes.xy, gl_TexCoord[0].xy) : + BlurH(textureUnit0, textureRes.xy, gl_TexCoord[0].xy); } diff --git a/include/eepp/graphics/batchrenderer.hpp b/include/eepp/graphics/batchrenderer.hpp index 1a2138446..66d8964cf 100644 --- a/include/eepp/graphics/batchrenderer.hpp +++ b/include/eepp/graphics/batchrenderer.hpp @@ -44,7 +44,7 @@ class EE_API BatchRenderer { Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized ); /** Set the predefined blending function to use on the batch */ - void setBlendMode( const BlendMode& Blend ); + void setBlendMode( const BlendMode& blend ); /** Set if every batch call have to be immediately rendered */ void setBatchForceRendering( const bool& force ) { mForceRendering = force; } @@ -303,28 +303,28 @@ class EE_API BatchRenderer { const bool& getForceBlendModeChange() const; protected: - VertexData* mVertex; - unsigned int mVertexSize; - VertexData* mTVertex; - unsigned int mNumVertex; + VertexData* mVertex{ nullptr }; + unsigned int mVertexSize{ 0 }; + VertexData* mTVertex{ nullptr }; + unsigned int mNumVertex{ 0 }; - const Texture* mTexture; - BlendMode mBlend; + const Texture* mTexture{ nullptr }; + BlendMode mBlend{ BlendMode::Alpha() }; - Vector2f mTexCoord[4]; - Color mVerColor[4]; + Vector2f mTexCoord[4]{ Vector2f::Zero, Vector2f::Zero, Vector2f::Zero, Vector2f::Zero }; + Color mVerColor[4]{ Color::White, Color::White, Color::White, Color::White }; - PrimitiveType mCurrentMode; + PrimitiveType mCurrentMode{ PRIMITIVE_QUADS }; - Float mRotation; - Vector2f mScale; - Vector2f mPosition; - Vector2f mCenter; + Float mRotation{ 0.f }; + Vector2f mScale{ 1.f, 1.f }; + Vector2f mPosition{ 0.f, 0.f }; + Vector2f mCenter{ 0.f, 0.f }; - Texture::CoordinateType mCoordinateType; + Texture::CoordinateType mCoordinateType{ Texture::CoordinateType::Normalized }; - bool mForceRendering; - bool mForceBlendMode; + bool mForceRendering{ false }; + bool mForceBlendMode{ true }; void flush(); diff --git a/include/eepp/graphics/blendmode.hpp b/include/eepp/graphics/blendmode.hpp index 811605253..b6f7f1136 100644 --- a/include/eepp/graphics/blendmode.hpp +++ b/include/eepp/graphics/blendmode.hpp @@ -2,12 +2,13 @@ #define EE_GRAPHICS_BLENDMODE_HPP #include +#include namespace EE { namespace Graphics { class EE_API BlendMode { public: - enum Factor { + enum class Factor { Zero, /// (0, 0, 0, 0) One, /// (1, 1, 1, 1) SrcColor, /// (src.r, src.g, src.b, src.a) @@ -20,15 +21,24 @@ class EE_API BlendMode { OneMinusDstAlpha /// (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a) }; - enum Equation { + enum class Equation { Add, /// Pixel = Src * SrcFactor + Dst * DstFactor Subtract, /// Pixel = Src * SrcFactor - Dst * DstFactor ReverseSubtract /// Pixel = Dst * DstFactor - Src * SrcFactor }; + static BlendMode Alpha(); /// Blend source and dest according to dest alpha + static BlendMode Add(); /// Add source to dest + static BlendMode Multiply(); /// Multiply source and dest + static BlendMode None(); /// Overwrite dest with source + + static std::string equationToString( const Equation& eq ); + + static std::string factorToString( const Factor& fc ); + BlendMode(); - BlendMode( Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add ); + BlendMode( Factor sourceFactor, Factor destinationFactor, Equation blendEquation = BlendMode::Equation::Add ); BlendMode( Factor colorSourceFactor, Factor colorDestinationFactor, Equation colorBlendEquation, Factor alphaSourceFactor, Factor alphaDestinationFactor, @@ -50,6 +60,8 @@ class EE_API BlendMode { Factor alphaDstFactor; /// Destination blending factor for the alpha channel Equation alphaEquation; /// Blending equation for the alpha channel + std::string toString() const; + protected: static BlendMode sLastBlend; }; @@ -57,11 +69,6 @@ class EE_API BlendMode { EE_API bool operator==( const BlendMode& left, const BlendMode& right ); EE_API bool operator!=( const BlendMode& left, const BlendMode& right ); -EE_API extern const BlendMode BlendAlpha; /// Blend source and dest according to dest alpha -EE_API extern const BlendMode BlendAdd; /// Add source to dest -EE_API extern const BlendMode BlendMultiply; /// Multiply source and dest -EE_API extern const BlendMode BlendNone; /// Overwrite dest with source - }} // namespace EE::Graphics #endif diff --git a/include/eepp/graphics/renderer/renderergles2.hpp b/include/eepp/graphics/renderer/renderergles2.hpp index 8026c3e39..8d763ef71 100644 --- a/include/eepp/graphics/renderer/renderergles2.hpp +++ b/include/eepp/graphics/renderer/renderergles2.hpp @@ -82,6 +82,7 @@ class EE_API RendererGLES2 : public RendererGLShader { Int32 mTexActive; int mTexActiveLoc; int mClippingEnabledLoc; + int mPointSizeLoc; float mPointSize; int mTextureUnits[EE_MAX_TEXTURE_UNITS]; int mTextureUnitsStates[EE_MAX_TEXTURE_UNITS]; diff --git a/include/eepp/graphics/scrollparallax.hpp b/include/eepp/graphics/scrollparallax.hpp index f325301ac..034f28b2b 100644 --- a/include/eepp/graphics/scrollparallax.hpp +++ b/include/eepp/graphics/scrollparallax.hpp @@ -28,10 +28,11 @@ class EE_API ScrollParallax { * @param size The size of the parallax * @param speed Speed of movement ( in Pixels Per Second ) * @param color The Texture Color - * @param Blend The Blend Mode ( default BlendAlpha ) */ + * @param Blend The Blend Mode ( default BlendMode::Alpha() ) */ ScrollParallax( TextureRegion* textureRegion, const Vector2f& position = Vector2f(), const Sizef& size = Sizef(), const Vector2f& speed = Vector2f(), - const Color& color = Color::White, const BlendMode& Blend = BlendAlpha ); + const Color& color = Color::White, + const BlendMode& Blend = BlendMode::Alpha() ); /** Create's the Scroll Parallax * @param textureRegion The TextureRegion to Draw @@ -39,12 +40,12 @@ class EE_API ScrollParallax { * @param size The size of the parallax * @param speed Speed of movement ( in Pixels Per Second ) * @param color The Texture Color - * @param Blend The Blend Mode ( default BlendAlpha ) + * @param Blend The Blend Mode ( default BlendMode::Alpha() ) * @return True if success */ bool create( TextureRegion* textureRegion, const Vector2f& position = Vector2f(), const Sizef& size = Sizef(), const Vector2f& speed = Vector2f(), - const Color& color = Color::White, const BlendMode& Blend = BlendAlpha ); + const Color& color = Color::White, const BlendMode& Blend = BlendMode::Alpha() ); /** Set the parallax texture color. */ void setColor( const Color& Color ) { mColor = Color; } diff --git a/include/eepp/graphics/sprite.hpp b/include/eepp/graphics/sprite.hpp index 66f3635dc..9f30cf332 100644 --- a/include/eepp/graphics/sprite.hpp +++ b/include/eepp/graphics/sprite.hpp @@ -356,27 +356,28 @@ class EE_API Sprite : public Drawable { SPRITE_FLAG_EVENTS_ENABLED = ( 1 << 4 ) }; - Uint32 mFlags; - OriginPoint mOrigin; - Float mRotation; - Vector2f mScale; - Float mAnimSpeed; + Uint32 mFlags{ SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED }; + OriginPoint mOrigin{ OriginPoint::OriginCenter }; + Float mRotation{ 0.f }; + Vector2f mScale{ 1.f, 1.f }; + Float mAnimSpeed{ 16.f }; - Color* mVertexColors; + Color* mVertexColors{ nullptr }; - int mRepetitions; //!< Number of repetions of the animation, default -1 that equals to loop. + int mRepetitions{ + -1 }; //!< Number of repetions of the animation, default -1 that equals to loop. - BlendMode mBlend; - RenderMode mEffect; + BlendMode mBlend{ BlendMode::Alpha() }; + RenderMode mEffect{ RENDER_NORMAL }; - unsigned int mCurrentFrame; - Float mfCurrentFrame; - unsigned int mCurrentSubFrame; - unsigned int mSubFrames; - unsigned int mAnimTo; + unsigned int mCurrentFrame{ 0 }; + Float mfCurrentFrame{ 0 }; + unsigned int mCurrentSubFrame{ 0 }; + unsigned int mSubFrames{ 1 }; + unsigned int mAnimTo{ 0 }; SpriteCallback mCb; - void* mUserData; + void* mUserData{ nullptr }; class Frame { public: diff --git a/include/eepp/graphics/text.hpp b/include/eepp/graphics/text.hpp index b6be4f6da..04a6c6c55 100644 --- a/include/eepp/graphics/text.hpp +++ b/include/eepp/graphics/text.hpp @@ -96,7 +96,7 @@ class EE_API Text { /** Draw the cached text on screen */ void draw( const Float& X, const Float& Y, const Vector2f& scale = Vector2f::One, - const Float& rotation = 0, BlendMode effect = BlendAlpha, + const Float& rotation = 0, BlendMode effect = BlendMode::Alpha(), const OriginPoint& rotationCenter = OriginPoint::OriginCenter, const OriginPoint& scaleCenter = OriginPoint::OriginCenter ); diff --git a/include/eepp/graphics/texture.hpp b/include/eepp/graphics/texture.hpp index e2c5325be..6a9123cab 100644 --- a/include/eepp/graphics/texture.hpp +++ b/include/eepp/graphics/texture.hpp @@ -179,13 +179,13 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl * @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 BlendAlpha ) + * @param Blend Set the Blend Mode ( default BlendMode::Alpha() ) * @param width The width of the texture rendered * @param height The height of the texture rendered */ void drawFast( const Float& x, const Float& y, const Float& Angle = 0.0f, const Vector2f& scale = Vector2f::One, const Color& color = Color::White, - const BlendMode& Blend = BlendAlpha, const Float& width = 0, + const BlendMode& Blend = BlendMode::Alpha(), const Float& width = 0, const Float& height = 0 ); /** Render the texture on screen @@ -194,7 +194,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl * @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 BlendAlpha ) + * @param Blend Set the Blend Mode ( default BlendMode::Alpha() ) * @param Effect Set the Render Effect ( default RN_NORMAL, no effect ) * @param Center The rotation and scaling center. The center point is relative to the top-left * corner of the object. @@ -203,7 +203,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl */ void draw( const Float& x, const Float& y, const Float& Angle = 0, const Vector2f& scale = Vector2f::One, const Color& color = Color::White, - const BlendMode& Blend = BlendAlpha, const RenderMode& Effect = RENDER_NORMAL, + const BlendMode& Blend = BlendMode::Alpha(), const RenderMode& Effect = RENDER_NORMAL, OriginPoint Center = OriginPoint( OriginPoint::OriginCenter ), const Rect& texSector = Rect( 0, 0, 0, 0 ) ); @@ -220,7 +220,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl * @param Color1 The Left - Bottom vertex color * @param Color2 The Right - Bottom vertex color * @param Color3 The Right - Top vertex color - * @param Blend Set the Blend Mode ( default BlendAlpha ) + * @param Blend Set the Blend Mode ( default BlendMode::Alpha() ) * @param Effect Set the Render Effect ( default RN_NORMAL, no effect ) * @param Center The rotation and scaling center. The center point is relative to the top-left * corner of the object. @@ -232,7 +232,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl const Color& Color1 = Color( 255, 255, 255, 255 ), const Color& Color2 = Color( 255, 255, 255, 255 ), const Color& Color3 = Color( 255, 255, 255, 255 ), - const BlendMode& Blend = BlendAlpha, const RenderMode& Effect = RENDER_NORMAL, + const BlendMode& Blend = BlendMode::Alpha(), const RenderMode& Effect = RENDER_NORMAL, OriginPoint Center = OriginPoint( OriginPoint::OriginCenter ), const Rect& texSector = Rect( 0, 0, 0, 0 ) ); @@ -242,13 +242,13 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl * @param Angle The Angle of the Quad2f rendered * @param scale The Scale of the Quad2f rendered * @param color The Quad2f color - * @param Blend Set the Blend Mode ( default BlendAlpha ) + * @param Blend Set the Blend Mode ( default BlendMode::Alpha() ) * @param texSector The texture sector to render. You can render only a part of the texture. ( * default render all the texture ) */ void drawQuad( const Quad2f& Q, const Vector2f& Offset = Vector2f(), const Float& Angle = 0.0f, const Vector2f& scale = Vector2f::One, const Color& color = Color::White, - const BlendMode& Blend = BlendAlpha, + const BlendMode& Blend = BlendMode::Alpha(), const Rect& texSector = Rect( 0, 0, 0, 0 ) ); /** Render a quad on Screen @@ -260,7 +260,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl * @param Color1 The Left - Bottom vertex color * @param Color2 The Right - Bottom vertex color * @param Color3 The Right - Top vertex color - * @param Blend Set the Blend Mode ( default BlendAlpha ) + * @param Blend Set the Blend Mode ( default BlendMode::Alpha() ) * @param texSector The texture sector to render. You can render only a part of the texture. ( * default render all the texture ) */ @@ -269,7 +269,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl const Color& Color1 = Color( 255, 255, 255, 255 ), const Color& Color2 = Color( 255, 255, 255, 255 ), const Color& Color3 = Color( 255, 255, 255, 255 ), - const BlendMode& Blend = BlendAlpha, Rect texSector = Rect( 0, 0, 0, 0 ) ); + const BlendMode& Blend = BlendMode::Alpha(), Rect texSector = Rect( 0, 0, 0, 0 ) ); Sizef getSize(); diff --git a/include/eepp/graphics/textureregion.hpp b/include/eepp/graphics/textureregion.hpp index b4816b76e..fa7040ad3 100644 --- a/include/eepp/graphics/textureregion.hpp +++ b/include/eepp/graphics/textureregion.hpp @@ -92,19 +92,19 @@ class EE_API TextureRegion : public DrawableResource { void draw( const Float& X, const Float& Y, const Color& color = Color::White, const Float& Angle = 0.f, const Vector2f& Scale = Vector2f::One, - const BlendMode& Blend = BlendAlpha, const RenderMode& Effect = RENDER_NORMAL, + const BlendMode& Blend = BlendMode::Alpha(), const RenderMode& Effect = RENDER_NORMAL, OriginPoint Center = OriginPoint( OriginPoint::OriginCenter ) ); void draw( const Float& X, const Float& Y, const Float& Angle, const Vector2f& Scale, const Color& Color0 = Color::White, const Color& Color1 = Color::White, const Color& Color2 = Color::White, const Color& Color3 = Color::White, - const BlendMode& Blend = BlendAlpha, const RenderMode& Effect = RENDER_NORMAL, + const BlendMode& Blend = BlendMode::Alpha(), const RenderMode& Effect = RENDER_NORMAL, OriginPoint Center = OriginPoint( OriginPoint::OriginCenter ) ); void draw( const Quad2f Q, const Vector2f& offset = Vector2f(), const Float& Angle = 0.f, const Vector2f& Scale = Vector2f::One, const Color& Color0 = Color::White, const Color& Color1 = Color::White, const Color& Color2 = Color::White, - const Color& Color3 = Color::White, const BlendMode& Blend = BlendAlpha ); + const Color& Color3 = Color::White, const BlendMode& Blend = BlendMode::Alpha() ); virtual void draw(); diff --git a/include/eepp/maps/gameobjecttextureregionex.hpp b/include/eepp/maps/gameobjecttextureregionex.hpp index beff4b531..39987cac7 100644 --- a/include/eepp/maps/gameobjecttextureregionex.hpp +++ b/include/eepp/maps/gameobjecttextureregionex.hpp @@ -10,7 +10,7 @@ class EE_API GameObjectTextureRegionEx : public GameObjectTextureRegion { public: GameObjectTextureRegionEx( const Uint32& Flags, MapLayer* Layer, Graphics::TextureRegion* TextureRegion = NULL, - const Vector2f& Pos = Vector2f(), BlendMode Blend = BlendAlpha, + const Vector2f& Pos = Vector2f(), BlendMode Blend = BlendMode::Alpha(), RenderMode Render = RENDER_NORMAL, Float Angle = 0.f, Vector2f Scale = Vector2f::One, Color color = Color::White ); diff --git a/premake4.lua b/premake4.lua index f184d91ba..bbe973fba 100644 --- a/premake4.lua +++ b/premake4.lua @@ -317,6 +317,9 @@ function build_base_configuration( package_name ) buildoptions{ "-Wall", "-std=gnu99" } end targetname ( package_name .. "-debug" ) + if os.is_real("emscripten") then + buildoptions{ "-g3" } + end configuration "release" defines { "NDEBUG" } @@ -324,10 +327,13 @@ function build_base_configuration( package_name ) if not is_vs() then buildoptions{ "-Wall", "-std=gnu99" } end + if os.is_real("emscripten") then + buildoptions{ "-O3" } + end targetname ( package_name ) configuration "emscripten" - buildoptions { "-O3 -s USE_SDL=2 -s PRECISE_F32=1 -s ENVIRONMENT=worker,web" } + buildoptions { "-s USE_SDL=2" } if _OPTIONS["with-emscripten-pthreads"] then buildoptions { "-s USE_PTHREADS=1" } end @@ -347,6 +353,9 @@ function build_base_cpp_configuration( package_name ) if not is_vs() then buildoptions{ "-Wall" } end + if os.is_real("emscripten") then + buildoptions{ "-g3" } + end targetname ( package_name .. "-debug" ) configuration "release" @@ -355,10 +364,13 @@ function build_base_cpp_configuration( package_name ) if not is_vs() then buildoptions{ "-Wall" } end + if os.is_real("emscripten") then + buildoptions{ "-O3" } + end targetname ( package_name ) configuration "emscripten" - buildoptions { "-O3 -s USE_SDL=2 -s PRECISE_F32=1 -s ENVIRONMENT=worker,web" } + buildoptions { "-s USE_SDL=2" } if _OPTIONS["with-emscripten-pthreads"] then buildoptions { "-s USE_PTHREADS=1" } end @@ -494,6 +506,10 @@ function build_link_configuration( package_name, use_ee_icon ) buildoptions{ "-Wall -Wno-long-long" } end + if os.is_real("emscripten") then + linkoptions{ "--profiling --profiling-funcs -s DEMANGLE_SUPPORT=1" } + end + fix_shared_lib_linking_path( package_name, "libeepp-debug" ) if not os.is_real("emscripten") then @@ -522,9 +538,9 @@ function build_link_configuration( package_name, use_ee_icon ) add_cross_config_links() configuration "emscripten" - linkoptions { "-O3 -s TOTAL_MEMORY=67108864" } + linkoptions { "-s TOTAL_MEMORY=67108864 -sALLOW_MEMORY_GROWTH" } linkoptions { "-s USE_SDL=2" } - buildoptions { "-O3 -s USE_SDL=2 -s PRECISE_F32=1 -s ENVIRONMENT=worker,web" } + buildoptions { "-s USE_SDL=2" } defines { "NO_POSIX_SPAWN" } if _OPTIONS["with-emscripten-pthreads"] then diff --git a/src/eepp/graphics/batchrenderer.cpp b/src/eepp/graphics/batchrenderer.cpp index 46db0519a..16f2b42cb 100644 --- a/src/eepp/graphics/batchrenderer.cpp +++ b/src/eepp/graphics/batchrenderer.cpp @@ -14,40 +14,12 @@ BatchRenderer* BatchRenderer::New( const unsigned int& Prealloc ) { return eeNew( BatchRenderer, ( Prealloc ) ); } -BatchRenderer::BatchRenderer() : - mVertex( NULL ), - mVertexSize( 0 ), - mTVertex( NULL ), - mNumVertex( 0 ), - mTexture( NULL ), - mBlend( BlendAlpha ), - mCurrentMode( PRIMITIVE_QUADS ), - mRotation( 0.0f ), - mScale( 1.0f, 1.0f ), - mPosition( 0.0f, 0.0f ), - mCenter( 0.0f, 0.0f ), - mCoordinateType( Texture::CoordinateType::Normalized ), - mForceRendering( false ), - mForceBlendMode( true ) { +BatchRenderer::BatchRenderer() { allocVertexs( 4096 ); init(); } -BatchRenderer::BatchRenderer( const unsigned int& Prealloc ) : - mVertex( NULL ), - mVertexSize( 0 ), - mTVertex( NULL ), - mNumVertex( 0 ), - mTexture( NULL ), - mBlend( BlendAlpha ), - mCurrentMode( PRIMITIVE_QUADS ), - mRotation( 0.0f ), - mScale( 1.0f, 1.0f ), - mPosition( 0.0f, 0.0f ), - mCenter( 0.0f, 0.0f ), - mCoordinateType( Texture::CoordinateType::Normalized ), - mForceRendering( false ), - mForceBlendMode( true ) { +BatchRenderer::BatchRenderer( const unsigned int& Prealloc ) { allocVertexs( Prealloc ); init(); } @@ -84,11 +56,12 @@ void BatchRenderer::setTexture( const Texture* texture, Texture::CoordinateType mCoordinateType = coordinateType; } -void BatchRenderer::setBlendMode( const BlendMode& Blend ) { - if ( Blend != mBlend ) +void BatchRenderer::setBlendMode( const BlendMode& blend ) { + if ( blend != mBlend ) flush(); - mBlend = Blend; + if ( mBlend != blend ) + mBlend = blend; } void BatchRenderer::addVertexs( const unsigned int& num ) { diff --git a/src/eepp/graphics/blendmode.cpp b/src/eepp/graphics/blendmode.cpp index 732a29530..39944a00c 100644 --- a/src/eepp/graphics/blendmode.cpp +++ b/src/eepp/graphics/blendmode.cpp @@ -7,25 +7,25 @@ namespace EE { namespace Graphics { Uint32 factorToGlConstant( BlendMode::Factor blendFactor ) { switch ( blendFactor ) { - case BlendMode::Zero: + case BlendMode::Factor::Zero: return GL_ZERO; - case BlendMode::One: + case BlendMode::Factor::One: return GL_ONE; - case BlendMode::SrcColor: + case BlendMode::Factor::SrcColor: return GL_SRC_COLOR; - case BlendMode::OneMinusSrcColor: + case BlendMode::Factor::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; - case BlendMode::DstColor: + case BlendMode::Factor::DstColor: return GL_DST_COLOR; - case BlendMode::OneMinusDstColor: + case BlendMode::Factor::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; - case BlendMode::SrcAlpha: + case BlendMode::Factor::SrcAlpha: return GL_SRC_ALPHA; - case BlendMode::OneMinusSrcAlpha: + case BlendMode::Factor::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; - case BlendMode::DstAlpha: + case BlendMode::Factor::DstAlpha: return GL_DST_ALPHA; - case BlendMode::OneMinusDstAlpha: + case BlendMode::Factor::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; } @@ -36,11 +36,11 @@ Uint32 factorToGlConstant( BlendMode::Factor blendFactor ) { Uint32 equationToGlConstant( BlendMode::Equation blendEquation ) { switch ( blendEquation ) { - case BlendMode::Add: + case BlendMode::Equation::Add: return GL_FUNC_ADD; - case BlendMode::Subtract: + case BlendMode::Equation::Subtract: return GL_FUNC_SUBTRACT; - case BlendMode::ReverseSubtract: + case BlendMode::Equation::ReverseSubtract: return GL_FUNC_REVERSE_SUBTRACT; } @@ -49,22 +49,80 @@ Uint32 equationToGlConstant( BlendMode::Equation blendEquation ) { return GL_FUNC_ADD; } -const BlendMode BlendAlpha( BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, - BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add ); -const BlendMode BlendAdd( BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add, BlendMode::One, - BlendMode::One, BlendMode::Add ); -const BlendMode BlendMultiply( BlendMode::DstColor, BlendMode::Zero ); -const BlendMode BlendNone( BlendMode::One, BlendMode::Zero ); +BlendMode BlendMode::Alpha() { + static const BlendMode BlendAlpha{ BlendMode::Factor::SrcAlpha, + BlendMode::Factor::OneMinusSrcAlpha, + BlendMode::Equation::Add, + BlendMode::Factor::One, + BlendMode::Factor::OneMinusSrcAlpha, + BlendMode::Equation::Add }; + return BlendAlpha; +} -BlendMode BlendMode::sLastBlend = BlendAlpha; +BlendMode BlendMode::Add() { + static const BlendMode BlendAdd{ BlendMode::Factor::SrcAlpha, BlendMode::Factor::One, + BlendMode::Equation::Add, BlendMode::Factor::One, + BlendMode::Factor::One, BlendMode::Equation::Add }; + return BlendAdd; +} + +BlendMode BlendMode::Multiply() { + static const BlendMode BlendMultiply{ BlendMode::Factor::DstColor, BlendMode::Factor::Zero }; + return BlendMultiply; +} + +BlendMode BlendMode::None() { + static const BlendMode BlendNone{ BlendMode::Factor::One, BlendMode::Factor::Zero }; + return BlendNone; +} + +BlendMode BlendMode::sLastBlend = BlendMode::Add(); + +std::string BlendMode::equationToString( const Equation& eq ) { + switch ( eq ) { + case BlendMode::Equation::Add: + return "Add"; + case BlendMode::Equation::Subtract: + return "Substract"; + case BlendMode::Equation::ReverseSubtract: + return "ReverseSubtract"; + } + return ""; +} + +std::string BlendMode::factorToString( const Factor& fc ) { + switch ( fc ) { + case BlendMode::Factor::Zero: + return "Zero"; + case BlendMode::Factor::One: + return "One"; + case BlendMode::Factor::SrcColor: + return "SrcColor"; + case BlendMode::Factor::OneMinusSrcColor: + return "OneMinusSrcColor"; + case BlendMode::Factor::DstColor: + return "DstColor"; + case BlendMode::Factor::OneMinusDstColor: + return "OneMinusDstColor"; + case BlendMode::Factor::SrcAlpha: + return "SrcAlpha"; + case BlendMode::Factor::OneMinusSrcAlpha: + return "OneMinusSrcAlpha"; + case BlendMode::Factor::DstAlpha: + return "DstAlpha"; + case BlendMode::Factor::OneMinusDstAlpha: + return "OneMinusDstAlpha"; + } + return ""; +} BlendMode::BlendMode() : - colorSrcFactor( BlendMode::SrcAlpha ), - colorDstFactor( BlendMode::OneMinusSrcAlpha ), - colorEquation( BlendMode::Add ), - alphaSrcFactor( BlendMode::One ), - alphaDstFactor( BlendMode::OneMinusSrcAlpha ), - alphaEquation( BlendMode::Add ) {} + colorSrcFactor( BlendMode::Factor::SrcAlpha ), + colorDstFactor( BlendMode::Factor::OneMinusSrcAlpha ), + colorEquation( BlendMode::Equation::Add ), + alphaSrcFactor( BlendMode::Factor::One ), + alphaDstFactor( BlendMode::Factor::OneMinusSrcAlpha ), + alphaEquation( BlendMode::Equation::Add ) {} BlendMode::BlendMode( Factor sourceFactor, Factor destinationFactor, Equation blendEquation ) : colorSrcFactor( sourceFactor ), @@ -125,4 +183,10 @@ BlendMode BlendMode::getPreBlendFunc() { return sLastBlend; } +std::string BlendMode::toString() const { + return factorToString( colorSrcFactor ) + " " + factorToString( colorDstFactor ) + " " + + equationToString( colorEquation ) + " " + factorToString( alphaSrcFactor ) + " " + + factorToString( alphaDstFactor ) + " " + equationToString( alphaEquation ); +} + }} // namespace EE::Graphics diff --git a/src/eepp/graphics/glyphdrawable.cpp b/src/eepp/graphics/glyphdrawable.cpp index d8649db8e..952b24644 100644 --- a/src/eepp/graphics/glyphdrawable.cpp +++ b/src/eepp/graphics/glyphdrawable.cpp @@ -31,7 +31,7 @@ void GlyphDrawable::draw( const Vector2f& position, const Sizef& size ) { BatchRenderer* BR = GlobalBatchRenderer::instance(); BR->setTexture( mTexture, mTexture->getCoordinateType() ); - BR->setBlendMode( BlendAlpha ); + BR->setBlendMode( BlendMode::Alpha() ); BR->quadsBegin(); BR->quadsSetColor( mColor ); BR->quadsSetTexCoord( mSrcRect.Left, mSrcRect.Top, mSrcRect.Left + mSrcRect.Right, diff --git a/src/eepp/graphics/particlesystem.cpp b/src/eepp/graphics/particlesystem.cpp index e35af44d3..599673269 100644 --- a/src/eepp/graphics/particlesystem.cpp +++ b/src/eepp/graphics/particlesystem.cpp @@ -18,7 +18,7 @@ ParticleSystem::ParticleSystem() : mPLeft( 0 ), mLoops( 0 ), mEffect( ParticleEffect::Nofx ), - mBlend( BlendAdd ), + mBlend( BlendMode::Add() ), mColor(), mProgression( 0 ), mDirection( 0 ), diff --git a/src/eepp/graphics/primitivedrawable.cpp b/src/eepp/graphics/primitivedrawable.cpp index ea3cb6f2f..9d950cdf5 100644 --- a/src/eepp/graphics/primitivedrawable.cpp +++ b/src/eepp/graphics/primitivedrawable.cpp @@ -7,7 +7,7 @@ namespace EE { namespace Graphics { PrimitiveDrawable::PrimitiveDrawable( Type drawableType ) : Drawable( drawableType ), mFillMode( DRAW_FILL ), - mBlendMode( BlendAlpha ), + mBlendMode( BlendMode::Alpha() ), mLineWidth( 1.f ), mNeedsUpdate( true ), mRecreateVertexBuffer( true ), diff --git a/src/eepp/graphics/primitives.cpp b/src/eepp/graphics/primitives.cpp index ae07181ce..63b66b5ba 100644 --- a/src/eepp/graphics/primitives.cpp +++ b/src/eepp/graphics/primitives.cpp @@ -10,7 +10,7 @@ namespace EE { namespace Graphics { static GlobalBatchRenderer* sBR = NULL; Primitives::Primitives() : - mFillMode( DRAW_FILL ), mBlendMode( BlendAlpha ), mLineWidth( 1.f ), mForceDraw( true ) { + mFillMode( DRAW_FILL ), mBlendMode( BlendMode::Alpha() ), mLineWidth( 1.f ), mForceDraw( true ) { if ( NULL == sBR ) { sBR = GlobalBatchRenderer::instance(); } diff --git a/src/eepp/graphics/renderer/renderer.cpp b/src/eepp/graphics/renderer/renderer.cpp index 743039149..e0fd54ee6 100644 --- a/src/eepp/graphics/renderer/renderer.cpp +++ b/src/eepp/graphics/renderer/renderer.cpp @@ -57,7 +57,7 @@ Renderer* Renderer::createSingleton( GraphicsLibraryVersion ver ) { if ( GLv_default == ver ) #ifndef EE_GLES1_DEFAULT #ifdef EE_GLES2 - ver = GLv_3CP; + ver = GLv_ES2; #else ver = GLv_ES1; #endif diff --git a/src/eepp/graphics/renderer/renderergles2.cpp b/src/eepp/graphics/renderer/renderergles2.cpp index ba990583a..56a7059c0 100644 --- a/src/eepp/graphics/renderer/renderergles2.cpp +++ b/src/eepp/graphics/renderer/renderergles2.cpp @@ -7,18 +7,18 @@ namespace EE { namespace Graphics { -const char* EEGLES2_STATES_NAME[] = {"dgl_Vertex", "dgl_Normal", "dgl_FrontColor"}; +const char* EEGLES2_STATES_NAME[] = { "dgl_Vertex", "dgl_Normal", "dgl_FrontColor" }; -const char* EEGLES2_TEXTUREUNIT_NAMES[] = {"dgl_MultiTexCoord0", "dgl_MultiTexCoord1", - "dgl_MultiTexCoord2", "dgl_MultiTexCoord3"}; +const char* EEGLES2_TEXTUREUNIT_NAMES[] = { "dgl_MultiTexCoord0", "dgl_MultiTexCoord1", + "dgl_MultiTexCoord2", "dgl_MultiTexCoord3" }; -const char* EEGLES2_PLANES_ENABLED_NAME[] = {"dgl_ClipEnabled[0]", "dgl_ClipEnabled[1]", - "dgl_ClipEnabled[2]", "dgl_ClipEnabled[3]", - "dgl_ClipEnabled[4]", "dgl_ClipEnabled[5]"}; +const char* EEGLES2_PLANES_ENABLED_NAME[] = { "dgl_ClipEnabled[0]", "dgl_ClipEnabled[1]", + "dgl_ClipEnabled[2]", "dgl_ClipEnabled[3]", + "dgl_ClipEnabled[4]", "dgl_ClipEnabled[5]" }; -const char* EEGLES2_PLANES_NAMENABLED_NAME[] = {"dgl_ClipPlane[0]", "dgl_ClipPlane[1]", - "dgl_ClipPlane[2]", "dgl_ClipPlane[3]", - "dgl_ClipPlane[4]", "dgl_ClipPlane[5]"}; +const char* EEGLES2_PLANES_NAMENABLED_NAME[] = { "dgl_ClipPlane[0]", "dgl_ClipPlane[1]", + "dgl_ClipPlane[2]", "dgl_ClipPlane[3]", + "dgl_ClipPlane[4]", "dgl_ClipPlane[5]" }; #ifdef EE_GLES2 const GLchar* GLES2_SHADER_HEAD = "precision mediump float;\nprecision lowp int;\n"; @@ -51,6 +51,9 @@ RendererGLES2::RendererGLES2() : mCurShaderLocal( true ) { mQuadsSupported = false; mQuadVertexs = 6; +#if !defined( EE_GLES2 ) + Renderer::enable( GL_VERTEX_PROGRAM_POINT_SIZE ); +#endif } RendererGLES2::~RendererGLES2() {} @@ -189,11 +192,15 @@ void RendererGLES2::setShader( ShaderProgram* Shader ) { checkLocalShader(); + if ( !mCurShader ) + return; + mProjectionMatrix_id = mCurShader->getUniformLocation( "dgl_ProjectionMatrix" ); mModelViewMatrix_id = mCurShader->getUniformLocation( "dgl_ModelViewMatrix" ); mTextureMatrix_id = mCurShader->getUniformLocation( "dgl_TextureMatrix" ); mTexActiveLoc = mCurShader->getUniformLocation( "dgl_TexActive" ); mClippingEnabledLoc = mCurShader->getUniformLocation( "dgl_ClippingEnabled" ); + mPointSizeLoc = mCurShader->getUniformLocation( "dgl_PointSize" ); mCurActiveTex = 0; Uint32 i; @@ -243,6 +250,10 @@ void RendererGLES2::setShader( ShaderProgram* Shader ) { mCurShader->setUniform( mClippingEnabledLoc, 0 ); } + if ( -1 != mPointSizeLoc ) { + mCurShader->setUniform( mPointSizeLoc, mPointSize ); + } + for ( i = 0; i < EE_MAX_PLANES; i++ ) { if ( -1 != mPlanes[i] ) { mCurShader->setUniform( EEGLES2_PLANES_ENABLED_NAME[i], 0 ); @@ -286,8 +297,6 @@ void RendererGLES2::enable( unsigned int cap ) { case GL_POINT_SPRITE: { mPointSpriteEnabled = 1; - // Renderer::Enable( GL_VERTEX_PROGRAM_POINT_SIZE ); - setShader( EEGLES2_SHADER_POINTSPRITE ); return; @@ -304,6 +313,7 @@ void RendererGLES2::disable( unsigned int cap ) { mTexActive = 0; if ( !mClippingEnabled ) { + disableClientState( GL_TEXTURE_COORD_ARRAY ); setShader( EEGLES2_SHADER_PRIMITIVE ); } else if ( -1 != mTexActiveLoc ) { mCurShader->setUniform( mTexActiveLoc, mTexActive ); @@ -335,8 +345,6 @@ void RendererGLES2::disable( unsigned int cap ) { case GL_POINT_SPRITE: { mPointSpriteEnabled = 0; - // Renderer::Disable( GL_VERTEX_PROGRAM_POINT_SIZE ); - setShader( EEGLES2_SHADER_BASE ); return; @@ -387,7 +395,7 @@ void RendererGLES2::disableClientState( unsigned int array ) { } void RendererGLES2::vertexPointer( int size, unsigned int type, int stride, const void* pointer, - unsigned int allocate ) { + unsigned int /*allocate*/ ) { const int index = mAttribsLoc[EEGL_VERTEX_ARRAY]; if ( -1 != index ) { @@ -402,7 +410,7 @@ void RendererGLES2::vertexPointer( int size, unsigned int type, int stride, cons } void RendererGLES2::colorPointer( int size, unsigned int type, int stride, const void* pointer, - unsigned int allocate ) { + unsigned int /*allocate*/ ) { const int index = mAttribsLoc[EEGL_COLOR_ARRAY]; if ( -1 != index ) { @@ -421,7 +429,7 @@ void RendererGLES2::colorPointer( int size, unsigned int type, int stride, const } void RendererGLES2::texCoordPointer( int size, unsigned int type, int stride, const void* pointer, - unsigned int allocate ) { + unsigned int /*allocate*/ ) { if ( mCurShaderLocal ) { if ( 1 == mTexActive ) { if ( mCurShader == mShaders[EEGLES2_SHADER_PRIMITIVE] ) { diff --git a/src/eepp/graphics/renderer/shaders/primitive.vert.h b/src/eepp/graphics/renderer/shaders/primitive.vert.h index 62e3a1751..6297f642b 100644 --- a/src/eepp/graphics/renderer/shaders/primitive.vert.h +++ b/src/eepp/graphics/renderer/shaders/primitive.vert.h @@ -2,11 +2,13 @@ const GLchar * EEGLES2_SHADER_PRIMITIVE_VS = R"( uniform mat4 dgl_ProjectionMatrix; uniform mat4 dgl_ModelViewMatrix; +uniform float dgl_PointSize; attribute vec4 dgl_Vertex; attribute vec4 dgl_FrontColor; varying vec4 dgl_Color; void main(void) { + gl_PointSize = dgl_PointSize; dgl_Color = dgl_FrontColor; gl_Position = dgl_ProjectionMatrix * ( dgl_ModelViewMatrix * dgl_Vertex ); } diff --git a/src/eepp/graphics/scrollparallax.cpp b/src/eepp/graphics/scrollparallax.cpp index bf5cf819d..c6059a221 100644 --- a/src/eepp/graphics/scrollparallax.cpp +++ b/src/eepp/graphics/scrollparallax.cpp @@ -4,7 +4,7 @@ namespace EE { namespace Graphics { ScrollParallax::ScrollParallax() : - mTextureRegion( NULL ), mBlend( BlendAlpha ), mColor( 255, 255, 255, 255 ) {} + mTextureRegion( NULL ), mBlend( BlendMode::Alpha() ), mColor( 255, 255, 255, 255 ) {} ScrollParallax::~ScrollParallax() {} diff --git a/src/eepp/graphics/sprite.cpp b/src/eepp/graphics/sprite.cpp index 617e34d2f..3cd6549cd 100644 --- a/src/eepp/graphics/sprite.cpp +++ b/src/eepp/graphics/sprite.cpp @@ -28,79 +28,21 @@ Sprite* Sprite::New( const Uint32& TexId, const Sizef& DestSize, const Vector2i& return eeNew( Sprite, ( TexId, DestSize, offset, TexSector ) ); } -Sprite::Sprite() : - Drawable( Drawable::SPRITE ), - mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mRotation( 0.f ), - mScale( 1.f, 1.f ), - mAnimSpeed( 16.f ), - mVertexColors( NULL ), - mRepetitions( -1 ), - mBlend( BlendAlpha ), - mEffect( RENDER_NORMAL ), - mCurrentFrame( 0 ), - mfCurrentFrame( 0.f ), - mCurrentSubFrame( 0 ), - mSubFrames( 1 ), - mAnimTo( 0 ), - mUserData( NULL ) {} +Sprite::Sprite() : Drawable( Drawable::SPRITE ) {} Sprite::Sprite( const std::string& name, const std::string& extension, TextureAtlas* SearchInTextureAtlas ) : - Drawable( Drawable::SPRITE ), - mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mRotation( 0.f ), - mScale( 1.f, 1.f ), - mAnimSpeed( 16.f ), - mVertexColors( NULL ), - mRepetitions( -1 ), - mBlend( BlendAlpha ), - mEffect( RENDER_NORMAL ), - mCurrentFrame( 0 ), - mfCurrentFrame( 0.f ), - mCurrentSubFrame( 0 ), - mSubFrames( 1 ), - mAnimTo( 0 ), - mUserData( NULL ) { + Drawable( Drawable::SPRITE ) { addFramesByPattern( name, extension, SearchInTextureAtlas ); } -Sprite::Sprite( TextureRegion* TextureRegion ) : - Drawable( Drawable::SPRITE ), - mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mRotation( 0.f ), - mScale( 1.f, 1.f ), - mAnimSpeed( 16.f ), - mVertexColors( NULL ), - mRepetitions( -1 ), - mBlend( BlendAlpha ), - mEffect( RENDER_NORMAL ), - mCurrentFrame( 0 ), - mfCurrentFrame( 0.f ), - mCurrentSubFrame( 0 ), - mSubFrames( 1 ), - mAnimTo( 0 ), - mUserData( NULL ) { +Sprite::Sprite( TextureRegion* TextureRegion ) : Drawable( Drawable::SPRITE ) { createStatic( TextureRegion ); } Sprite::Sprite( const Uint32& TexId, const Sizef& DestSize, const Vector2i& Offset, const Rect& TexSector ) : - Drawable( Drawable::SPRITE ), - mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mRotation( 0.f ), - mScale( 1.f, 1.f ), - mAnimSpeed( 16.f ), - mVertexColors( NULL ), - mRepetitions( -1 ), - mBlend( BlendAlpha ), - mEffect( RENDER_NORMAL ), - mCurrentFrame( 0 ), - mfCurrentFrame( 0.f ), - mCurrentSubFrame( 0 ), - mSubFrames( 1 ), - mAnimTo( 0 ), - mUserData( NULL ) { + Drawable( Drawable::SPRITE ) { createStatic( TexId, DestSize, Offset, TexSector ); } @@ -194,7 +136,7 @@ void Sprite::reset() { mRotation = 0; mColor = Color::White; - mBlend = BlendAlpha; + mBlend = BlendMode::Alpha(); mEffect = RENDER_NORMAL; mCurrentFrame = 0; diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index aa3b4abb6..0c17d8bdd 100644 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -942,7 +942,7 @@ void Texture::draw( const Vector2f& position ) { } void Texture::draw( const Vector2f& position, const Sizef& size ) { - drawFast( position.x, position.y, 0, Vector2f::One, mColor, BlendAlpha, size.x, size.y ); + drawFast( position.x, position.y, 0, Vector2f::One, mColor, BlendMode::Alpha(), size.x, size.y ); } }} // namespace EE::Graphics diff --git a/src/eepp/maps/gameobject.cpp b/src/eepp/maps/gameobject.cpp index 284d76054..27085ace4 100644 --- a/src/eepp/maps/gameobject.cpp +++ b/src/eepp/maps/gameobject.cpp @@ -122,7 +122,8 @@ RenderMode GameObject::getRenderModeFromFlags() { } BlendMode GameObject::getBlendModeFromFlags() { - return isBlendAdd() ? BlendMode( BlendMode::DstColor, BlendMode::One ) : BlendAlpha; + return isBlendAdd() ? BlendMode( BlendMode::Factor::DstColor, BlendMode::Factor::One ) + : BlendMode::Alpha(); } MapLayer* GameObject::getLayer() const { diff --git a/src/eepp/maps/gameobjecttextureregion.cpp b/src/eepp/maps/gameobjecttextureregion.cpp index f7640c37a..77e7b1d23 100644 --- a/src/eepp/maps/gameobjecttextureregion.cpp +++ b/src/eepp/maps/gameobjecttextureregion.cpp @@ -44,7 +44,7 @@ void GameObjectTextureRegion::draw() { getRenderModeFromFlags() ); } else { mTextureRegion->draw( mPos.x, mPos.y, *LM->getTileColor( Tile ), getRotation(), - Vector2f::One, BlendAlpha, getRenderModeFromFlags() ); + Vector2f::One, BlendMode::Alpha(), getRenderModeFromFlags() ); } } else { if ( LM->isByVertex() ) { diff --git a/src/eepp/maps/gameobjectvirtual.cpp b/src/eepp/maps/gameobjectvirtual.cpp index c92a3a10e..45d5e592f 100644 --- a/src/eepp/maps/gameobjectvirtual.cpp +++ b/src/eepp/maps/gameobjectvirtual.cpp @@ -88,7 +88,7 @@ void GameObjectVirtual::draw() { } else { mTextureRegion->draw( mPos.x, mPos.y, LM->getColorFromPos( Vector2f( mPos.x, mPos.y ) ), - getRotation(), Vector2f::One, BlendAlpha, getRenderModeFromFlags() ); + getRotation(), Vector2f::One, BlendMode::Alpha(), getRenderModeFromFlags() ); } } } else { diff --git a/src/eepp/physics/shapepoint.cpp b/src/eepp/physics/shapepoint.cpp index d05e1c447..a039e2485 100644 --- a/src/eepp/physics/shapepoint.cpp +++ b/src/eepp/physics/shapepoint.cpp @@ -44,8 +44,6 @@ void ShapePoint::draw( Space* space ) { #ifdef PHYSICS_RENDERER_ENABLED BatchRenderer* BR = GlobalBatchRenderer::instance(); - BR->setPointSize( mDrawRadius ); - BR->setTexture( NULL ); BR->pointsBegin(); BR->pointSetColor( colorForShape( mShape, space->getSpace() ) ); @@ -53,6 +51,7 @@ void ShapePoint::draw( Space* space ) { cpCircleShape* cs = (cpCircleShape*)mShape; BR->batchPoint( cs->CP_PRIVATE( tc ).x, cs->CP_PRIVATE( tc ).y ); + BR->setPointSize( mDrawRadius ); BR->drawOpt(); #endif diff --git a/src/eepp/physics/space.cpp b/src/eepp/physics/space.cpp index ce115a0d6..54b86f509 100644 --- a/src/eepp/physics/space.cpp +++ b/src/eepp/physics/space.cpp @@ -288,7 +288,7 @@ void Space::draw() { #ifdef PHYSICS_RENDERER_ENABLED BatchRenderer* BR = GlobalBatchRenderer::instance(); - BR->setBlendMode( BlendAlpha ); + BR->setBlendMode( BlendMode::Alpha() ); PhysicsManager::DrawSpaceOptions* options = PhysicsManager::instance()->getDrawOptions(); diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 70246e1f0..d63dfc5f7 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -25,7 +25,7 @@ Node::Node() : mNext( NULL ), mPrev( NULL ), mNodeFlags( NODE_FLAG_POSITION_DIRTY | NODE_FLAG_POLYGON_DIRTY ), - mBlend( BlendAlpha ), + mBlend( BlendMode::Alpha() ), mNumCallBacks( 0 ), mVisible( true ), mEnabled( true ), diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index ed38da8b4..8303d4a60 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -343,13 +343,13 @@ static BlendMode toBlendMode( std::string val ) { BlendMode blendMode; if ( val == "add" ) - blendMode = BlendAdd; + blendMode = BlendMode::Add(); else if ( val == "alpha" ) - blendMode = BlendAlpha; + blendMode = BlendMode::Alpha(); else if ( val == "multiply" ) - blendMode = BlendMultiply; + blendMode = BlendMode::Multiply(); else if ( val == "none" ) - blendMode = BlendNone; + blendMode = BlendMode::None(); return blendMode; } diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index 7879cf6c4..1ad212fdd 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -204,7 +204,7 @@ void Window::setup2D( const bool& KeepView ) { setView( mDefaultView, true ); } - BlendMode::setMode( BlendAlpha, true ); + BlendMode::setMode( BlendMode::Alpha(), true ); if ( GLv_3CP != GLi->version() && GLv_3 != GLi->version() && GLv_ES2 != GLi->version() ) { #if !defined( EE_GLES2 ) || defined( EE_GLES_BOTH ) diff --git a/src/examples/external_shader/external_shader.cpp b/src/examples/external_shader/external_shader.cpp index 0833285b5..28a1b5e1e 100644 --- a/src/examples/external_shader/external_shader.cpp +++ b/src/examples/external_shader/external_shader.cpp @@ -21,7 +21,7 @@ Vector3ff* vertices = eeNewArray( Vector3ff, ParticlesNum ); Vector3ff* velocities = eeNewArray( Vector3ff, ParticlesNum ); ColorAf* colors = eeNewArray( ColorAf, ParticlesNum ); -void videoResize( EE::Window::Window* w ) { +void videoResize( EE::Window::Window* ) { /// Video Resize event will re-setup the 2D projection and states, so we must rebuild them. aspectRatio = (Float)win->getWidth() / (Float)win->getHeight(); tw = (Float)win->getWidth() / 2; @@ -57,8 +57,8 @@ void videoResize( EE::Window::Window* w ) { GLi->enableClientState( GL_VERTEX_ARRAY ); GLi->enableClientState( GL_COLOR_ARRAY ); - /// Reset the default blend func ( by default eepp use BlendAlpha ) - BlendMode::setMode( BlendAdd ); + /// Reset the default blend func ( by default eepp use BlendMode::Alpha() ) + BlendMode::setMode( BlendMode::Add() ); /// Set the line width GLi->lineWidth( 2 ); diff --git a/src/examples/physics/physics.cpp b/src/examples/physics/physics.cpp index 4adb7972b..296bb263b 100644 --- a/src/examples/physics/physics.cpp +++ b/src/examples/physics/physics.cpp @@ -102,7 +102,7 @@ static const char image_bitmap[] = { 127, -1, -29, -4, 127, -64, 15, -8, 0, 0, 55, -1, -1, -121, -8, 127, -97, -25, -8, 0, 63, -61, -61, -4, 127, -1, -29, -4, 63, -64, 15, -32, 0, 0, 23, -1, -2, 3, -16, 63, 15, -61, -16, 0, 31, -127, -127, -8, 31, -1, -127, - -8, 31, -128, 7, -128, 0, 0}; + -8, 31, -128, 7, -128, 0, 0 }; int get_pixel( int x, int y ) { return ( image_bitmap[( x >> 3 ) + y * image_row_length] >> ( ~x & 0x7 ) ) & 1; @@ -260,7 +260,7 @@ struct Emitter { }; Emitter emitterInstance; -cpBool blockerBegin( Arbiter* arb, Space* space, void* unused ) { +cpBool blockerBegin( Arbiter* arb, Space*, void* ) { Shape *a, *b; arb->getShapes( &a, &b ); @@ -271,7 +271,7 @@ cpBool blockerBegin( Arbiter* arb, Space* space, void* unused ) { return cpFalse; // Return values from sensors callbacks are ignored, } -void blockerSeparate( Arbiter* arb, Space* space, void* unused ) { +void blockerSeparate( Arbiter* arb, Space*, void* ) { Shape *a, *b; arb->getShapes( &a, &b ); @@ -280,7 +280,7 @@ void blockerSeparate( Arbiter* arb, Space* space, void* unused ) { emitter->blocked--; } -void postStepRemove( Space* space, void* tshape, void* unused ) { +void postStepRemove( Space* space, void* tshape, void* ) { Shape* shape = reinterpret_cast( tshape ); if ( NULL != mMouseJoint && @@ -295,7 +295,7 @@ void postStepRemove( Space* space, void* tshape, void* unused ) { Shape::Free( shape, true ); } -cpBool catcherBarBegin( Arbiter* arb, Space* space, void* unused ) { +cpBool catcherBarBegin( Arbiter* arb, Space* space, void* ) { Shape *a, *b; arb->getShapes( &a, &b ); @@ -303,7 +303,7 @@ cpBool catcherBarBegin( Arbiter* arb, Space* space, void* unused ) { emitter->queue++; - space->addPostStepCallback( cb::Make3( &postStepRemove ), b, NULL ); + space->addPostStepCallback( &postStepRemove, b, NULL ); return cpFalse; } @@ -343,15 +343,15 @@ void demo3Create() { Space::CollisionHandler handler; handler.a = BLOCKING_SENSOR_TYPE; handler.b = BALL_TYPE; - handler.begin = cb::Make3( &blockerBegin ); - handler.separate = cb::Make3( &blockerSeparate ); + handler.begin = &blockerBegin; + handler.separate = &blockerSeparate; mSpace->addCollisionHandler( handler ); handler.reset(); // Reset all the values and the callbacks ( set the callbacks as !IsSet() handler.a = CATCH_SENSOR_TYPE; handler.b = BALL_TYPE; - handler.begin = cb::Make3( &catcherBarBegin ); + handler.begin = &catcherBarBegin; mSpace->addCollisionHandler( handler ); } @@ -377,12 +377,12 @@ enum { COLLIDE_STICK_SENSOR = 1 }; #define STICK_SENSOR_THICKNESS 2.5f -void postStepAddJoint( Space* space, void* key, void* data ) { +void postStepAddJoint( Space* space, void* key, void* ) { Constraint* joint = (Constraint*)key; space->addConstraint( joint ); } -cpBool stickyPreSolve( Arbiter* arb, Space* space, void* data ) { +cpBool stickyPreSolve( Arbiter* arb, Space* space, void* ) { // We want to fudge the collisions a bit to allow shapes to overlap more. // This simulates their squishy sticky surface, and more importantly // keeps them from separating and destroying the joint. @@ -424,7 +424,7 @@ cpBool stickyPreSolve( Arbiter* arb, Space* space, void* data ) { joint->setMaxForce( 3e3 ); // Schedule a post-step() callback to add the joint. - space->addPostStepCallback( cb::Make3( &postStepAddJoint ), joint, NULL ); + space->addPostStepCallback( &postStepAddJoint, joint, NULL ); // Store the joint on the arbiter so we can remove it later. arb->setUserData( joint ); @@ -443,13 +443,13 @@ cpBool stickyPreSolve( Arbiter* arb, Space* space, void* data ) { // pointer). } -void postStepRemoveJoint( Space* space, void* key, void* data ) { +void postStepRemoveJoint( Space* space, void* key, void* ) { Constraint* joint = (Constraint*)key; space->removeConstraint( joint ); Constraint::Free( joint ); } -void stickySeparate( Arbiter* arb, Space* space, void* data ) { +void stickySeparate( Arbiter* arb, Space* space, void* ) { Constraint* joint = (Constraint*)arb->getUserData(); if ( joint ) { @@ -459,7 +459,7 @@ void stickySeparate( Arbiter* arb, Space* space, void* data ) { joint->setMaxForce( 0.0f ); // Perform the removal in a post-step() callback. - space->addPostStepCallback( cb::Make3( &postStepRemoveJoint ), joint, NULL ); + space->addPostStepCallback( &postStepRemoveJoint, joint, NULL ); // NULL out the reference to the joint. // Not required, but it's a good practice. @@ -538,8 +538,8 @@ void demo4Create() { Space::CollisionHandler c; c.a = COLLIDE_STICK_SENSOR; c.b = COLLIDE_STICK_SENSOR; - c.preSolve = cb::Make3( &stickyPreSolve ); - c.separate = cb::Make3( &stickySeparate ); + c.preSolve = &stickyPreSolve; + c.separate = &stickySeparate; mSpace->addCollisionHandler( c ); } @@ -570,24 +570,24 @@ void physicsCreate() { // Add the demos physicDemo demo; - demo.init = cb::Make0( &demo1Create ); - demo.update = cb::Make0( &demo1Update ); - demo.destroy = cb::Make0( &demo1Destroy ); + demo.init = &demo1Create; + demo.update = &demo1Update; + demo.destroy = &demo1Destroy; mDemo.push_back( demo ); - demo.init = cb::Make0( &demo2Create ); - demo.update = cb::Make0( &demo2Update ); - demo.destroy = cb::Make0( &demo2Destroy ); + demo.init = &demo2Create; + demo.update = &demo2Update; + demo.destroy = &demo2Destroy; mDemo.push_back( demo ); - demo.init = cb::Make0( &demo3Create ); - demo.update = cb::Make0( &demo3Update ); - demo.destroy = cb::Make0( &demo3Destroy ); + demo.init = &demo3Create; + demo.update = &demo3Update; + demo.destroy = &demo3Destroy; mDemo.push_back( demo ); - demo.init = cb::Make0( &demo4Create ); - demo.update = cb::Make0( &demo4Update ); - demo.destroy = cb::Make0( &demo4Destroy ); + demo.init = &demo4Create; + demo.update = &demo4Update; + demo.destroy = &demo4Destroy; mDemo.push_back( demo ); ChangeDemo( 0 ); @@ -649,9 +649,9 @@ void mainLoop() { mWindow->display(); } -EE_MAIN_FUNC int main( int argc, char* argv[] ) { +EE_MAIN_FUNC int main( int, char*[] ) { mWindow = Engine::instance()->createWindow( WindowSettings( 1024, 768, "eepp - Physics" ), - ContextSettings( true ) ); + ContextSettings( true, EE::Graphics::GLv_ES2 ) ); if ( mWindow->isOpen() ) { KM = mWindow->getInput(); diff --git a/src/examples/sprites/sprites.cpp b/src/examples/sprites/sprites.cpp index 81e31cde9..217db6c30 100644 --- a/src/examples/sprites/sprites.cpp +++ b/src/examples/sprites/sprites.cpp @@ -88,7 +88,7 @@ void mainLoop() { win->display(); } -EE_MAIN_FUNC int main( int argc, char* argv[] ) { +EE_MAIN_FUNC int main( int, char*[] ) { // Create a new window win = Engine::instance()->createWindow( WindowSettings( 640, 480, "eepp - Sprites" ), ContextSettings( true ) ); @@ -135,7 +135,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { Blindy.setRenderMode( RENDER_MIRROR ); // Set the Blend Mode of the sprite - Blindy.setBlendMode( BlendAdd ); + Blindy.setBlendMode( BlendMode::Add() ); // Set the primitive fill mode P.setFillMode( DRAW_LINE ); diff --git a/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp b/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp index c76c393b9..489ddd97c 100644 --- a/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp +++ b/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp @@ -110,7 +110,7 @@ void mainLoop() { win->display(); } -EE_MAIN_FUNC int main( int argc, char* argv[] ) { +EE_MAIN_FUNC int main( int, char*[] ) { // Create a new window win = Engine::instance()->createWindow( WindowSettings( 1024, 768, "eepp - VBO - FBO and Batch Rendering" ), diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index fae8ea1e8..fe0ef0f21 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -52,7 +52,6 @@ class UIBlurredWindow : public UIWindow { mBlurShader->bind(); - mBlurShader->setUniform( "radius", 16.f ); mBlurShader->setUniform( "dir", (Int32)0 ); mBlurShader->setUniform( "textureRes", mFboBlur->getSizef() ); @@ -186,7 +185,7 @@ void EETest::init() { WP.start(); Batch.allocVertexs( 2048 ); - Batch.setBlendMode( BlendAdd ); + Batch.setBlendMode( BlendMode::Add() ); mFBO = FrameBuffer::New( 256, 256 ); @@ -1602,13 +1601,13 @@ void EETest::screen2() { if ( mUseShaders ) mShaderProgram->unbind(); - TNP[3]->draw( HWidth - 128, HHeight, 0, Vector2f::One, Color( 255, 255, 255, 150 ), BlendAlpha, + TNP[3]->draw( HWidth - 128, HHeight, 0, Vector2f::One, Color( 255, 255, 255, 150 ), BlendMode::Alpha(), RENDER_ISOMETRIC ); TNP[3]->draw( HWidth - 128, HHeight - 128, 0, Vector2f::One, Color( 255, 255, 255, 50 ), - BlendAlpha, RENDER_ISOMETRIC ); - TNP[3]->draw( HWidth - 128, HHeight, 0, Vector2f::One, Color( 255, 255, 255, 50 ), BlendAlpha, + BlendMode::Alpha(), RENDER_ISOMETRIC ); + TNP[3]->draw( HWidth - 128, HHeight, 0, Vector2f::One, Color( 255, 255, 255, 50 ), BlendMode::Alpha(), RENDER_ISOMETRIC_VERTICAL ); - TNP[3]->draw( HWidth, HHeight, 0, Vector2f::One, Color( 255, 255, 255, 50 ), BlendAlpha, + TNP[3]->draw( HWidth, HHeight, 0, Vector2f::One, Color( 255, 255, 255, 50 ), BlendMode::Alpha(), RENDER_ISOMETRIC_VERTICAL_NEGATIVE ); alpha = ( !aside ) ? alpha + et.asMilliseconds() * 0.1f : alpha - et.asMilliseconds() * 0.1f; @@ -1622,7 +1621,7 @@ void EETest::screen2() { Color Col( 255, 255, 255, (int)alpha ); TNP[1]->drawEx( (Float)mWindow->getWidth() - 128.f, (Float)mWindow->getHeight() - 128.f, 128.f, - 128.f, ang, Vector2f::One, Col, Col, Col, Col, BlendAdd, + 128.f, ang, Vector2f::One, Col, Col, Col, Col, BlendMode::Add(), RENDER_FLIPPED_MIRRORED ); SP.setPosition( Vector2f( alpha, alpha ) ); @@ -2232,30 +2231,30 @@ void EETest::demo1Create() { mSpace->setGravity( cVectNew( 0, 100 ) ); mSpace->setSleepTimeThreshold( 0.5f ); - Body *body, *statiBody = mSpace->getStaticBody(); + Body *body, *staticBody = mSpace->getStaticBody(); Shape* shape; shape = mSpace->addShape( - ShapeSegment::New( statiBody, cVectNew( 0, mWindow->getHeight() ), + ShapeSegment::New( staticBody, cVectNew( 0, mWindow->getHeight() ), cVectNew( mWindow->getWidth(), mWindow->getHeight() ), 0.0f ) ); shape->setE( 1.0f ); shape->setU( 1.0f ); shape->setLayers( NOT_GRABABLE_MASK ); shape = mSpace->addShape( - ShapeSegment::New( statiBody, cVectNew( mWindow->getWidth(), 0 ), + ShapeSegment::New( staticBody, cVectNew( mWindow->getWidth(), 0 ), cVectNew( mWindow->getWidth(), mWindow->getHeight() ), 0.0f ) ); shape->setE( 1.0f ); shape->setU( 1.0f ); shape->setLayers( NOT_GRABABLE_MASK ); - shape = mSpace->addShape( ShapeSegment::New( statiBody, cVectNew( 0, 0 ), + shape = mSpace->addShape( ShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( 0, mWindow->getHeight() ), 0.0f ) ); shape->setE( 1.0f ); shape->setU( 1.0f ); shape->setLayers( NOT_GRABABLE_MASK ); - shape = mSpace->addShape( ShapeSegment::New( statiBody, cVectNew( 0, 0 ), + shape = mSpace->addShape( ShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( mWindow->getWidth(), 0 ), 0.0f ) ); shape->setE( 1.0f ); shape->setU( 1.0f ); diff --git a/src/thirdparty/chipmunk/cpBBTree.c b/src/thirdparty/chipmunk/cpBBTree.c index b1286867d..17953673f 100644 --- a/src/thirdparty/chipmunk/cpBBTree.c +++ b/src/thirdparty/chipmunk/cpBBTree.c @@ -630,13 +630,18 @@ cpBBTreeContains(cpBBTree *tree, void *obj, cpHashValue hashid) //MARK: Reindex +static void LeafUpdate2(void* elt, void* data) +{ + LeafUpdate((Node*)elt, (cpBBTree*)data); +} + static void cpBBTreeReindexQuery(cpBBTree *tree, cpSpatialIndexQueryFunc func, void *data) { if(!tree->root) return; // LeafUpdate() may modify tree->root. Don't cache it. - cpHashSetEach(tree->leaves, (cpHashSetIteratorFunc)LeafUpdate, tree); + cpHashSetEach(tree->leaves, (cpHashSetIteratorFunc)LeafUpdate2, tree); cpSpatialIndex *staticIndex = tree->spatialIndex.staticIndex; Node *staticRoot = (staticIndex && staticIndex->klass == Klass() ? ((cpBBTree *)staticIndex)->root : NULL); diff --git a/src/thirdparty/chipmunk/cpSpace.c b/src/thirdparty/chipmunk/cpSpace.c index 111d0d244..149a0d0ed 100644 --- a/src/thirdparty/chipmunk/cpSpace.c +++ b/src/thirdparty/chipmunk/cpSpace.c @@ -141,10 +141,15 @@ cpSpaceNew(void) return cpSpaceInit(cpSpaceAlloc()); } +void cpBodyActivate2(cpBody *body, void *data) +{ + cpBodyActivate(body); +} + void cpSpaceDestroy(cpSpace *space) { - cpSpaceEachBody(space, (cpSpaceBodyIteratorFunc)cpBodyActivate, NULL); + cpSpaceEachBody(space, (cpSpaceBodyIteratorFunc)cpBodyActivate2, NULL); cpSpatialIndexFree(space->staticShapes); cpSpatialIndexFree(space->activeShapes);