void ScriptRenderTexture2D::internal_getColorSurfaces(ScriptRenderTexture2D* thisPtr, MonoArray** value)
	{
		if (thisPtr->mIsMulti)
		{
			SPtr<MultiRenderTexture> tex = thisPtr->getMultiRenderTexture();

			UINT32 numColorSurfaces = tex->getColorSurfaceCount();
			ScriptArray outArray = ScriptArray::create<ScriptTexture2D>(numColorSurfaces);

			for (UINT32 i = 0; i < numColorSurfaces; i++)
			{
				HTexture colorTex = tex->getBindableColorTexture(i);

				ScriptTexture2D* scriptSurface;
				ScriptResourceManager::instance().getScriptResource(colorTex, &scriptSurface, true);

				outArray.set(i, scriptSurface->getManagedInstance());
				*value = outArray.getInternal();
			}
		}
		else
		{
			SPtr<RenderTexture> tex = thisPtr->getRenderTexture();
			ScriptArray outArray = ScriptArray::create<ScriptTexture2D>(1);

			HTexture colorTex = tex->getBindableColorTexture();

			ScriptTexture2D* scriptSurface;
			ScriptResourceManager::instance().getScriptResource(colorTex, &scriptSurface, true);

			outArray.set(0, scriptSurface->getManagedInstance());
			*value = outArray.getInternal();
		}
	}
Exemplo n.º 2
0
	void ScriptRenderTexture2D::internal_getDepthStencilSurface(ScriptRenderTexture2D* thisPtr, MonoObject** value)
	{
		SPtr<RenderTexture> tex = thisPtr->getRenderTexture();
		HTexture depthTex = tex->getDepthStencilTexture();

		ScriptTexture2D* scriptSurface;
		ScriptResourceManager::instance().getScriptResource(depthTex, &scriptSurface, true);

		*value = scriptSurface->getManagedInstance();
	}
Exemplo n.º 3
0
	void ScriptRenderTexture2D::internal_create(MonoObject* instance, MonoArray* colorSurfaces, ScriptTexture2D* depthStencilSurface)
	{
		ScriptArray colorSurfacesList(colorSurfaces);

		RENDER_SURFACE_DESC depthStencilSurfaceDesc;
		if (depthStencilSurface != nullptr)
		{
			depthStencilSurfaceDesc.face = 0;
			depthStencilSurfaceDesc.mipLevel = 0;
			depthStencilSurfaceDesc.numFaces = 1;

			HTexture textureHandle = depthStencilSurface->getHandle();
			if (!textureHandle.isLoaded())
			{
				LOGERR("Render texture must be created using a fully loaded texture.");
			}
			else
				depthStencilSurfaceDesc.texture = textureHandle;
		}

		UINT32 numSurfaces = std::min(colorSurfacesList.size(), (UINT32)BS_MAX_MULTIPLE_RENDER_TARGETS);

		RENDER_TEXTURE_DESC desc;
		for (UINT32 i = 0; i < numSurfaces; i++)
		{
			RENDER_SURFACE_DESC surfaceDesc;
			surfaceDesc.face = 0;
			surfaceDesc.mipLevel = 0;
			surfaceDesc.numFaces = 1;

			ScriptTexture2D* scriptSurface = colorSurfacesList.get<ScriptTexture2D*>(i);
			if (scriptSurface != nullptr)
			{
				HTexture textureHandle = scriptSurface->getHandle();
				if (!textureHandle.isLoaded())
				{
					LOGERR("Render texture must be created using a fully loaded texture.");
				}
				else
					surfaceDesc.texture = textureHandle;
			}

			desc.colorSurfaces[i] = surfaceDesc;
		}

		desc.depthStencilSurface = depthStencilSurfaceDesc;

		SPtr<RenderTarget> tex = RenderTexture::create(desc);
		new (bs_alloc<ScriptRenderTexture2D>()) ScriptRenderTexture2D(tex, instance);
	}
	MonoObject* ScriptSpriteTexture::internal_GetTexture(ScriptSpriteTexture* thisPtr)
	{
		HSpriteTexture spriteTexture = thisPtr->getHandle();
		if (!spriteTexture.isLoaded())
			return nullptr;

		HTexture texture = spriteTexture->getTexture();
		if (!texture.isLoaded())
			return nullptr;

		ScriptTexture2D* scriptTexture = nullptr;
		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);

		return scriptTexture->getManagedInstance();
	}
	void ScriptSpriteTexture::internal_createInstance(MonoObject* instance, MonoObject* texture, Vector2* offset, Vector2* scale)
	{
		ScriptTexture2D* scriptTexture = ScriptTexture2D::toNative(texture);
		ScriptSpriteTexture* scriptInstance;

		if (scriptTexture == nullptr)
		{
			ScriptResourceManager::instance().createScriptResource(instance, SpriteTexture::dummy(), &scriptInstance);
		}
		else
		{
			HSpriteTexture spriteTexture = SpriteTexture::create(*offset, *scale, scriptTexture->getHandle());

			ScriptResourceManager::instance().createScriptResource(instance, spriteTexture, &scriptInstance);
		}
	}
	void ScriptRenderTexture2D::internal_getDepthStencilSurface(ScriptRenderTexture2D* thisPtr, MonoObject** value)
	{
		HTexture colorTex;
		if (thisPtr->mIsMulti)
		{
			SPtr<MultiRenderTexture> tex = thisPtr->getMultiRenderTexture();
			colorTex = tex->getBindableDepthStencilTexture();
		}
		else
		{
			SPtr<RenderTexture> tex = thisPtr->getRenderTexture();
			colorTex = tex->getBindableDepthStencilTexture();
		}

		ScriptTexture2D* scriptSurface;
		ScriptResourceManager::instance().getScriptResource(colorTex, &scriptSurface, true);

		*value = scriptSurface->getManagedInstance();
	}
Exemplo n.º 7
0
	void ScriptRenderTexture2D::internal_getColorSurfaces(ScriptRenderTexture2D* thisPtr, MonoArray** value)
	{
		SPtr<RenderTexture> tex = thisPtr->getRenderTexture();

		UINT32 numColorSurfaces = BS_MAX_MULTIPLE_RENDER_TARGETS;
		ScriptArray outArray = ScriptArray::create<ScriptTexture2D>(numColorSurfaces);

		for (UINT32 i = 0; i < numColorSurfaces; i++)
		{
			HTexture colorTex = tex->getColorTexture(i);

			if (colorTex != nullptr)
			{
				ScriptTexture2D* scriptSurface;
				ScriptResourceManager::instance().getScriptResource(colorTex, &scriptSurface, true);

				outArray.set<MonoObject*>(i, scriptSurface->getManagedInstance());
			}
			else
				outArray.set<MonoObject*>(i, nullptr);
		}

		*value = outArray.getInternal();
	}
	void ScriptRenderTexture2D::internal_create(MonoObject* instance, MonoArray* colorSurfaces, MonoObject* depthStencilSurface)
	{
		ScriptArray colorSurfacesList(colorSurfaces);

		RENDER_SURFACE_DESC depthStencilSurfaceDesc;
		ScriptTexture2D* scriptDepthStencilSurface = ScriptTexture2D::toNative(depthStencilSurface);
		if (scriptDepthStencilSurface != nullptr)
		{
			depthStencilSurfaceDesc.face = 0;
			depthStencilSurfaceDesc.mipLevel = 0;
			depthStencilSurfaceDesc.numFaces = 1;

			HTexture textureHandle = scriptDepthStencilSurface->getHandle();
			if (!textureHandle.isLoaded())
			{
				LOGERR("Render texture must be created using a fully loaded texture.");
			}
			else
				depthStencilSurfaceDesc.texture = textureHandle;
		}

		SPtr<RenderTarget> tex;

		UINT32 numSurfaces = colorSurfacesList.size();
		bool isMulti = numSurfaces > 1;
		if (isMulti)
		{
			MULTI_RENDER_TEXTURE_DESC desc;

			for (UINT32 i = 0; i < numSurfaces; i++)
			{
				RENDER_SURFACE_DESC surfaceDesc;
				surfaceDesc.face = 0;
				surfaceDesc.mipLevel = 0;
				surfaceDesc.numFaces = 1;

				MonoObject* surfaceObj = colorSurfacesList.get<MonoObject*>(i);
				ScriptTexture2D* scriptSurface = ScriptTexture2D::toNative(surfaceObj);

				if (scriptSurface != nullptr)
				{
					HTexture textureHandle = scriptSurface->getHandle();
					if (!textureHandle.isLoaded())
					{
						LOGERR("Render texture must be created using a fully loaded texture.");
					}
					else
						surfaceDesc.texture = textureHandle;
				}

				desc.colorSurfaces.push_back(surfaceDesc);
			}

			desc.depthStencilSurface = depthStencilSurfaceDesc;

			tex = MultiRenderTexture::create(desc);
		}
		else
		{
			RENDER_SURFACE_DESC surfaceDesc;
			surfaceDesc.face = 0;
			surfaceDesc.mipLevel = 0;
			surfaceDesc.numFaces = 1;

			if (colorSurfacesList.size() > 0)
			{
				MonoObject* surfaceObj = colorSurfacesList.get<MonoObject*>(0);
				ScriptTexture2D* scriptSurface = ScriptTexture2D::toNative(surfaceObj);

				if (scriptSurface != nullptr)
				{
					HTexture textureHandle = scriptSurface->getHandle();
					if (!textureHandle.isLoaded())
					{
						LOGERR("Render texture must be created using a fully loaded texture.");
					}
					else
						surfaceDesc.texture = textureHandle;
				}
			}

			RENDER_TEXTURE_DESC desc;
			desc.colorSurface = surfaceDesc;
			desc.depthStencilSurface = depthStencilSurfaceDesc;
			tex = RenderTexture::create(desc);
		}

		new (bs_alloc<ScriptRenderTexture2D>()) ScriptRenderTexture2D(tex, isMulti, instance);
	}