|
@@ -7,6 +7,11 @@
|
|
|
#include "BsTexture.h"
|
|
#include "BsTexture.h"
|
|
|
#include "BsPixelUtil.h"
|
|
#include "BsPixelUtil.h"
|
|
|
#include "BsException.h"
|
|
#include "BsException.h"
|
|
|
|
|
+#include "BsScriptPixelData.h"
|
|
|
|
|
+#include "BsScriptAsyncOp.h"
|
|
|
|
|
+#include "BsCoreThread.h"
|
|
|
|
|
+
|
|
|
|
|
+using namespace std::placeholders;
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
@@ -19,30 +24,64 @@ namespace BansheeEngine
|
|
|
void ScriptTexture2D::initRuntimeData()
|
|
void ScriptTexture2D::initRuntimeData()
|
|
|
{
|
|
{
|
|
|
metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptTexture2D::internal_createInstance);
|
|
metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptTexture2D::internal_createInstance);
|
|
|
|
|
+ metaData.scriptClass->addInternalCall("Internal_GetPixels", &ScriptTexture2D::internal_getPixels);
|
|
|
|
|
+ metaData.scriptClass->addInternalCall("Internal_GetGPUPixels", &ScriptTexture2D::internal_getGPUPixels);
|
|
|
|
|
+ metaData.scriptClass->addInternalCall("Internal_SetPixels", &ScriptTexture2D::internal_setPixels);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void ScriptTexture2D::internal_createInstance(MonoObject* instance, UINT32 format, UINT32 width, UINT32 height, bool hasMipmaps, bool gammaCorrection)
|
|
|
|
|
|
|
+ void ScriptTexture2D::internal_createInstance(MonoObject* instance, PixelFormat format, UINT32 width,
|
|
|
|
|
+ UINT32 height, TextureUsage usage, UINT32 numSamples, bool hasMipmaps, bool gammaCorrection)
|
|
|
{
|
|
{
|
|
|
- PixelFormat texFormat = PF_R8G8B8;
|
|
|
|
|
- switch(format)
|
|
|
|
|
- {
|
|
|
|
|
- case 0: // RGB
|
|
|
|
|
- texFormat = PF_R8G8B8;
|
|
|
|
|
- break;
|
|
|
|
|
- case 1: // RGBA
|
|
|
|
|
- texFormat = PF_R8G8B8A8;
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- BS_EXCEPT(InvalidParametersException, "Unsupported texture format");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
int numMips = 0;
|
|
int numMips = 0;
|
|
|
if(hasMipmaps)
|
|
if(hasMipmaps)
|
|
|
- numMips = PixelUtil::getMaxMipmaps(width, height, 1, texFormat);
|
|
|
|
|
|
|
+ numMips = PixelUtil::getMaxMipmaps(width, height, 1, format);
|
|
|
|
|
|
|
|
- HTexture texture = Texture::create(TEX_TYPE_2D, width, height, numMips, texFormat, TU_STATIC, gammaCorrection);
|
|
|
|
|
|
|
+ HTexture texture = Texture::create(TEX_TYPE_2D, width, height, numMips, format, usage, gammaCorrection, numSamples);
|
|
|
|
|
|
|
|
- ScriptResourceManager::instance().createScriptTexture(instance, texture);
|
|
|
|
|
|
|
+ ScriptResourceManager::instance().createScriptTexture2D(instance, texture);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MonoObject* ScriptTexture2D::internal_getPixels(ScriptTexture2D* thisPtr, UINT32 mipLevel)
|
|
|
|
|
+ {
|
|
|
|
|
+ HTexture texture = thisPtr->mTexture;
|
|
|
|
|
+ UINT32 subresourceIdx = texture->mapToSubresourceIdx(0, mipLevel);
|
|
|
|
|
+
|
|
|
|
|
+ PixelDataPtr pixelData = thisPtr->mTexture->allocateSubresourceBuffer(subresourceIdx);
|
|
|
|
|
+
|
|
|
|
|
+ thisPtr->mTexture->readDataSim(*pixelData, mipLevel);
|
|
|
|
|
+
|
|
|
|
|
+ return ScriptPixelData::create(pixelData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MonoObject* ScriptTexture2D::internal_getGPUPixels(ScriptTexture2D* thisPtr, UINT32 mipLevel)
|
|
|
|
|
+ {
|
|
|
|
|
+ HTexture texture = thisPtr->mTexture;
|
|
|
|
|
+ UINT32 subresourceIdx = texture->mapToSubresourceIdx(0, mipLevel);
|
|
|
|
|
+
|
|
|
|
|
+ PixelDataPtr readData = texture->allocateSubresourceBuffer(subresourceIdx);
|
|
|
|
|
+
|
|
|
|
|
+ AsyncOp asyncOp = gCoreAccessor().readSubresource(texture.getInternalPtr(), subresourceIdx, readData);
|
|
|
|
|
+
|
|
|
|
|
+ std::function<MonoObject*(const AsyncOp&, const PixelDataPtr&)> asyncOpToMono =
|
|
|
|
|
+ [&](const AsyncOp& op, const PixelDataPtr& returnValue)
|
|
|
|
|
+ {
|
|
|
|
|
+ return ScriptPixelData::create(returnValue);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return ScriptAsyncOp::create(asyncOp, std::bind(asyncOpToMono, _1, readData));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void ScriptTexture2D::internal_setPixels(ScriptTexture2D* thisPtr, MonoObject* data, UINT32 mipLevel)
|
|
|
|
|
+ {
|
|
|
|
|
+ ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(data);
|
|
|
|
|
+
|
|
|
|
|
+ if (scriptPixelData != nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ HTexture texture = thisPtr->mTexture;
|
|
|
|
|
+ UINT32 subresourceIdx = texture->mapToSubresourceIdx(0, mipLevel);
|
|
|
|
|
+
|
|
|
|
|
+ gCoreAccessor().writeSubresource(texture.getInternalPtr(), subresourceIdx, scriptPixelData->getInternalValue());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ScriptTexture2D::_onManagedInstanceDeleted()
|
|
void ScriptTexture2D::_onManagedInstanceDeleted()
|