Skip to content

Commit

Permalink
GLCore support wip
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Mar 7, 2016
1 parent 89b4181 commit 6d57385
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 46 deletions.
74 changes: 45 additions & 29 deletions Plugin/FrameCapturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,8 @@
// Foundation
// -------------------------------------------------------------

struct fcCallbackData
{
fcCallback callback;
void *userdata;

fcCallbackData(fcCallback cb = nullptr, void *ud = nullptr) : callback(cb), userdata(ud) {}
bool operator==(const fcCallbackData &v) const { return callback == v.callback && userdata == v.userdata; }
void operator()() { callback(userdata); }
};

namespace {
std::string g_fcModulePath;
std::vector<fcCallbackData> g_callbacks;
}

fcCLinkage fcExport void fcSetModulePath(const char *path)
Expand Down Expand Up @@ -77,33 +66,50 @@ fcCLinkage fcExport uint64_t fcStreamGetWrittenSize(fcStream *s)
}


#ifndef fcStaticLink

typedef std::function<void()> fcDeferredCall;
namespace {
std::vector<fcDeferredCall> g_deferred_calls;
}

fcCLinkage fcExport int fcAddCallback(fcCallback cb, void *userdata)
fcCLinkage fcExport int fcAddDeferredCall(const fcDeferredCall& dc, int index = -1)
{
// search empty object and return its position if found
for (int i = 0; i < (int)g_callbacks.size(); ++i) {
if (g_callbacks[i].callback == nullptr) {
g_callbacks[i] = fcCallbackData(cb, userdata);
return i;
if (index == -1) {
// search empty object and return its position if found
for (int i = 1; i < (int)g_deferred_calls.size(); ++i) {
if (!g_deferred_calls[i]) {
g_deferred_calls[i] = dc;
return i;
}
}
}

// allocate new one
g_callbacks.emplace_back(fcCallbackData(cb, userdata));
return (int)g_callbacks.size() - 1;
// 0th is "null" object
if (g_deferred_calls.empty()) { g_deferred_calls.emplace_back(fcDeferredCall()); }

// allocate new one
g_deferred_calls.emplace_back(dc);
return (int)g_deferred_calls.size() - 1;
}
else {
g_deferred_calls[index] = dc;
return index;
}
}

fcCLinkage fcExport void fcEraseCallback(int id)
fcCLinkage fcExport void fcEraseDeferredCall(int id)
{
g_callbacks[id] = fcCallbackData();
g_deferred_calls[id] = fcDeferredCall();
}

fcCLinkage fcExport void fcCallCallback(int id)
fcCLinkage fcExport void fcCallDeferredCall(int id)
{
auto& cb = g_callbacks[id];
if (cb.callback) { cb(); }
auto& dc = g_deferred_calls[id];
if (dc) { dc(); }
}

#endif // fcStaticLink



// -------------------------------------------------------------
Expand Down Expand Up @@ -141,17 +147,27 @@ fcCLinkage fcExport void fcPngDestroyContext(fcIPngContext *ctx)
ctx->release();
}

fcCLinkage fcExport bool fcPngExportPixels(fcIPngContext *ctx, const char *path, const void *pixels, int width, int height, fcPixelFormat fmt, bool flipY)
{
return ctx->exportPixels(path, pixels, width, height, fmt, flipY);
}

fcCLinkage fcExport bool fcPngExportTexture(fcIPngContext *ctx, const char *path, void *tex, int width, int height, fcPixelFormat fmt, bool flipY)
{
return ctx->exportTexture(path, tex, width, height, fmt, flipY);
}

fcCLinkage fcExport bool fcPngExportPixels(fcIPngContext *ctx, const char *path, const void *pixels, int width, int height, fcPixelFormat fmt, bool flipY)
#ifndef fcStaticLink
fcCLinkage fcExport int fcPngExportTextureDeferred(fcIPngContext *ctx, const char *path_, void *tex, int width, int height, fcPixelFormat fmt, bool flipY, int index=-1)
{
return ctx->exportPixels(path, pixels, width, height, fmt, flipY);
std::string path = path_;
return fcAddDeferredCall([=]() {
fcPngExportTexture(ctx, path.c_str(), tex, width, height, fmt, flipY);
}, index);
}
#endif // fcStaticLink

#endif // #fcSupportPNG
#endif // fcSupportPNG


// -------------------------------------------------------------
Expand Down
19 changes: 7 additions & 12 deletions Plugin/FrameCapturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ fcCLinkage fcExport void fcGfxSync();

fcCLinkage fcExport void fcSetModulePath(const char *path);
fcCLinkage fcExport const char* fcGetModulePath();
fcCLinkage fcExport fcTime fcGetTime();

typedef void(__stdcall *fcCallback)(void *userdata);
fcCLinkage fcExport int fcAddCallback(fcCallback cb, void *userdata);
fcCLinkage fcExport void fcEraseCallback(int id);
fcCLinkage fcExport void fcCallCallback(int id);
fcCLinkage fcExport fcTime fcGetTime(); // current time in seconds


#ifndef fcImpl
Expand Down Expand Up @@ -115,8 +110,8 @@ struct fcPngConfig
};
fcCLinkage fcExport fcIPngContext* fcPngCreateContext(const fcPngConfig *conf = nullptr);
fcCLinkage fcExport void fcPngDestroyContext(fcIPngContext *ctx);
fcCLinkage fcExport bool fcPngExportTexture(fcIPngContext *ctx, const char *path, void *tex, int width, int height, fcPixelFormat fmt, bool flipY = false);
fcCLinkage fcExport bool fcPngExportPixels(fcIPngContext *ctx, const char *path, const void *pixels, int width, int height, fcPixelFormat fmt, bool flipY = false);
fcCLinkage fcExport bool fcPngExportTexture(fcIPngContext *ctx, const char *path, void *tex, int width, int height, fcPixelFormat fmt, bool flipY = false);


// -------------------------------------------------------------
Expand All @@ -131,8 +126,8 @@ struct fcExrConfig
fcCLinkage fcExport fcIExrContext* fcExrCreateContext(const fcExrConfig *conf = nullptr);
fcCLinkage fcExport void fcExrDestroyContext(fcIExrContext *ctx);
fcCLinkage fcExport bool fcExrBeginFrame(fcIExrContext *ctx, const char *path, int width, int height);
fcCLinkage fcExport bool fcExrAddLayerTexture(fcIExrContext *ctx, void *tex, fcPixelFormat fmt, int ch, const char *name, bool flipY = false);
fcCLinkage fcExport bool fcExrAddLayerPixels(fcIExrContext *ctx, const void *pixels, fcPixelFormat fmt, int ch, const char *name, bool flipY = false);
fcCLinkage fcExport bool fcExrAddLayerTexture(fcIExrContext *ctx, void *tex, fcPixelFormat fmt, int ch, const char *name, bool flipY = false);
fcCLinkage fcExport bool fcExrEndFrame(fcIExrContext *ctx);


Expand All @@ -152,9 +147,9 @@ struct fcGifConfig
fcCLinkage fcExport fcIGifContext* fcGifCreateContext(const fcGifConfig *conf);
fcCLinkage fcExport void fcGifDestroyContext(fcIGifContext *ctx);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcGifAddFrameTexture(fcIGifContext *ctx, void *tex, fcPixelFormat fmt, bool keyframe = false, fcTime timestamp = -1.0);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcGifAddFramePixels(fcIGifContext *ctx, const void *pixels, fcPixelFormat fmt, bool keyframe = false, fcTime timestamp = -1.0);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcGifAddFrameTexture(fcIGifContext *ctx, void *tex, fcPixelFormat fmt, bool keyframe = false, fcTime timestamp = -1.0);
fcCLinkage fcExport bool fcGifWrite(fcIGifContext *ctx, fcStream *stream, int begin_frame = 0, int end_frame = -1);

fcCLinkage fcExport void fcGifClearFrame(fcIGifContext *ctx);
Expand Down Expand Up @@ -207,10 +202,10 @@ fcCLinkage fcExport const char* fcMP4GetAudioEncoderInfo(fcIMP4Context *ctx)
fcCLinkage fcExport const char* fcMP4GetVideoEncoderInfo(fcIMP4Context *ctx);
fcCLinkage fcExport void fcMP4AddOutputStream(fcIMP4Context *ctx, fcStream *stream);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcMP4AddVideoFrameTexture(fcIMP4Context *ctx, void *tex, fcPixelFormat fmt, fcTime timestamp = -1);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcMP4AddVideoFramePixels(fcIMP4Context *ctx, const void *pixels, fcPixelFormat fmt, fcTime timestamp = -1.0);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcMP4AddVideoFrameTexture(fcIMP4Context *ctx, void *tex, fcPixelFormat fmt, fcTime timestamp = -1);
// timestamp=-1 is treated as current time.
fcCLinkage fcExport bool fcMP4AddAudioFrame(fcIMP4Context *ctx, const float *samples, int num_samples, fcTime timestamp = -1.0);

#endif // FrameCapturer_h
12 changes: 7 additions & 5 deletions Plugin/GraphicsDevice/fcGraphicsDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ static void UNITY_INTERFACE_API UnityOnGraphicsDeviceEvent(UnityGfxDeviceEventTy
}
}

fcCLinkage fcExport void fcCallDeferredCall(int id);
static void UNITY_INTERFACE_API UnityRenderEvent(int eventID)
{
fcCallCallback(eventID);
fcCallDeferredCall(eventID);
}

extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
Expand All @@ -130,14 +131,15 @@ UnityPluginUnload()
unity_gfx->UnregisterDeviceEventCallback(UnityOnGraphicsDeviceEvent);
}

fcCLinkage fcExport IUnityInterfaces* fcGetUnityInterface()
extern "C" UnityRenderingEvent UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
fcGetRenderEventFunc()
{
return g_unity_interface;
return UnityRenderEvent;
}

fcCLinkage fcExport UnityRenderingEvent fcGetRenderEventFunc()
fcCLinkage fcExport IUnityInterfaces* fcGetUnityInterface()
{
return UnityRenderEvent;
return g_unity_interface;
}

#ifdef fcWindows
Expand Down

0 comments on commit 6d57385

Please sign in to comment.