Skip to content

Commit

Permalink
SparkGL animated image support (#2230)
Browse files Browse the repository at this point in the history
* SparkGL animated image support

* updates for animated images
  • Loading branch information
mfiess authored Mar 4, 2020
1 parent 7b35800 commit 11190bd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions examples/pxScene2d/src/pxImageA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "pxImageA.h"
#include "pxContext.h"
#include <algorithm>
#include "pxTimer.h"

extern pxContext context;

Expand Down Expand Up @@ -397,9 +398,58 @@ rtError pxImageA::setResolveWithoutParent(bool v)
return RT_OK;
}

rtError pxImageA::animateImage()
{
if (getImageAResource() == NULL || !mImageLoaded)
{
return RT_OK;
}

double t = pxSeconds();
pxTimedOffscreenSequence& imageSequence = getImageAResource()->getTimedOffscreenSequence();
uint32_t numFrames = imageSequence.numFrames();

if (numFrames > 0)
{
if (mFrameTime < 0)
{
mCurFrame = 0;
mFrameTime = t;
}

for (; mCurFrame < numFrames; mCurFrame++)
{
double d = imageSequence.getDuration(mCurFrame);
if (mFrameTime + d >= t)
break;
mFrameTime += d;
}

if (mCurFrame >= numFrames)
{
mCurFrame = numFrames - 1; // snap animation to last frame

if (!imageSequence.numPlays() || mPlays < imageSequence.numPlays())
{
mFrameTime = -1; // reset animation
mPlays++;
}
}

if (mCachedFrame != mCurFrame)
{
pxOffscreen &o = imageSequence.getFrameBuffer(mCurFrame);
mTexture = context.createTexture(o);
mCachedFrame = mCurFrame;
}
}
return RT_OK;
}

rtDefineObject(pxImageA, pxObject);
rtDefineProperty(pxImageA, url);
rtDefineProperty(pxImageA, resource);
rtDefineProperty(pxImageA, stretchX);
rtDefineProperty(pxImageA, stretchY);
rtDefineProperty(pxImageA, resolveWithoutParent);
rtDefineMethod(pxImageA, animateImage);
2 changes: 2 additions & 0 deletions examples/pxScene2d/src/pxImageA.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class pxImageA: public pxObject, pxResourceListener
rtProperty(stretchY, stretchY, setStretchY, int32_t);
rtProperty(resource, resource, setResource, rtObjectRef);
rtProperty(resolveWithoutParent, resolveWithoutParent, setResolveWithoutParent, bool);
rtMethodNoArgAndNoReturn("animateImage", animateImage);

pxImageA(pxScene2d* scene);
virtual ~pxImageA();
Expand All @@ -53,6 +54,7 @@ class pxImageA: public pxObject, pxResourceListener
rtError removeResourceListener();
rtError resolveWithoutParent(bool& v) const;
rtError setResolveWithoutParent(bool v);
rtError animateImage();
virtual void resourceReady(rtString readyResolution);
virtual void resourceDirty();

Expand Down
2 changes: 2 additions & 0 deletions examples/pxScene2d/src/pxScene2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ pxScene2d::pxScene2d(bool top, pxScriptView* scriptView)
// capabilities.video.player = 1
// capabilities.sparkgl.nativedrawing = 1
// capabilities.sparkgl.supports1080 = 1
// capabilities.sparkgl.animatedImages = 1

mCapabilityVersions = new rtMapObject;

Expand Down Expand Up @@ -677,6 +678,7 @@ pxScene2d::pxScene2d(bool top, pxScriptView* scriptView)
}
}
sparkGlCapabilities.set("supports1080", 1);
sparkGlCapabilities.set("animatedImages", 1);
mCapabilityVersions.set("sparkgl", sparkGlCapabilities);

//////////////////////////////////////////////////////
Expand Down

0 comments on commit 11190bd

Please sign in to comment.