void ScriptRenderTexture2D::internal_create(MonoObject* instance, MonoArray* colorSurfaces, ScriptTexture* 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;

			ScriptTexture* scriptSurface = colorSurfacesList.get<ScriptTexture*>(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);
	}
Ejemplo n.º 2
0
	RenderTextureProperties::RenderTextureProperties(const RENDER_TEXTURE_DESC& desc, bool requiresFlipping)
	{
		HTexture texture = desc.colorSurface.texture;

		if (texture.isLoaded())
		{
			const TextureProperties& props = texture->getProperties();
			construct(&props, requiresFlipping);
		}
		else
			construct(nullptr, requiresFlipping);
	}
Ejemplo n.º 3
0
	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 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);
	}