Exemple #1
0
bool GSDevice10::Create(int type, Texture& t, int w, int h, int format)
{
	HRESULT hr;

	D3D10_TEXTURE2D_DESC desc;

	memset(&desc, 0, sizeof(desc));

	desc.Width = w;
	desc.Height = h;
	desc.Format = (DXGI_FORMAT)format;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.SampleDesc.Count = 1;
	desc.SampleDesc.Quality = 0;
	desc.Usage = D3D10_USAGE_DEFAULT;

	switch(type)
	{
	case GSTexture::RenderTarget:
		desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
		break;
	case GSTexture::DepthStencil:
		desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
		break;
	case GSTexture::Texture:
		desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
		break;
	case GSTexture::Offscreen:
		desc.Usage = D3D10_USAGE_STAGING;
		desc.CPUAccessFlags |= D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
		break;
	}

	CComPtr<ID3D10Texture2D> texture;

	hr = m_dev->CreateTexture2D(&desc, NULL, &texture);

	if(SUCCEEDED(hr))
	{
		t = Texture(texture);

		switch(type)
		{
		case GSTexture::RenderTarget:
			ClearRenderTarget(t, 0);
			break;
		case GSTexture::DepthStencil:
			ClearDepth(t, 0);
			break;
		}

		return true;
	}

	return false;
}
void AsciiRenderer::CreateBuffers(const unsigned int width, const unsigned int height)
{
	assert(width != 0);
	assert(height != 0);
	m_Width = width;
	m_Height = height;
	m_ColorBuffer = new char*[height];
	m_DepthBuffer = new float*[height];
	for(unsigned int y = 0; y < height; ++y)
	{
		m_ColorBuffer[y] = new char[width];
		m_DepthBuffer[y] = new float[width];
	}
	ClearColor();
	ClearDepth();
}
Exemple #3
0
GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, bool msaa, int format)
{
    // A wrapper to call GSTextureOGL, with the different kind of parameter
    GSTextureOGL* t = NULL;
    t = new GSTextureOGL(type, w, h, format, m_fbo_read);

    switch(type)
    {
    case GSTexture::RenderTarget:
        ClearRenderTarget(t, 0);
        break;
    case GSTexture::DepthStencil:
        ClearDepth(t, 0);
        // No need to clear the stencil now.
        break;
    }
    return t;
}
void StateRenderTest::Render()
{
	auto renderInterface = m_appData->renderInterface;
	auto keyboard = m_appData->keyboard;
	auto mouse = m_appData->mouse;
	auto shaderPack = m_appData->shaderPack;
	auto debugWorld = m_appData->debugWorld;

	shaderPack->UpdateFrameBuffers(renderInterface, m_camera.GetViewMatrix());

	//if (!m_haveWrittenToTexture)
	//{
	//	beTexture writeTexture;
	//	beTexture::LoadOptions textureLoadOptions;
	//	textureLoadOptions.height = 512;
	//	textureLoadOptions.width = 512;
	//	textureLoadOptions.format = beTextureFormat::R32G32B32_FLOAT;
	//	writeTexture.InitAsTarget(renderInterface, textureLoadOptions);
	//	defer(
	//		writeTexture.Deinit();
	//	);
	//	m_haveWrittenToTexture = true;
	//	writeTexture.SetAsTarget(renderInterface);
	//	writeTexture.Clear(renderInterface, V40());
	//	m_models[3].Render(renderInterface, shaderPack, beRendering::ShaderType::Colour);
	//	
	//	renderInterface->DisableZBuffer();
	//	shaderPack->shaderTexture2d.SetShaderParameters(renderInterface, m_camera.GetViewMatrix());
	//		
	//	//m_bitmapTexQuad.Render(renderInterface);
	//	//textureShader2d.Render(renderInterface, m_bitmapTexQuad.GetIndexCount(), m_bitmapTexQuad.GetTexture());
	//	
	//	renderInterface->EnableAlpha();
	//	m_bitmapTextDynamic.InitText(renderInterface, &m_font, "initial string", 1.f, 640.f, 0, false, beFont::WrapMode::Default);
	//	m_bitmapTextDynamic.SetPosition((float)(-writeTexture.GetWidth() / 2), (float)(writeTexture.GetHeight() / 2));
	//	m_bitmapTextDynamic.Render(renderInterface);
	//	shaderPack->shaderTexture2d.Render(renderInterface, m_bitmapTextDynamic.GetIndexCount(), m_bitmapTextDynamic.GetTexture(), true);
	//	renderInterface->DisableAlpha();
	//	renderInterface->EnableZBuffer();
	//	renderInterface->RestoreRenderTarget();
	//	writeTexture.FinaliseTarget();
	//			
	//	m_bitmapTextPreRendered.Init(renderInterface, writeTexture);
	//	m_bitmapTextPreRendered.SetPosition(-400, -400);
	//}
	
	auto renderFrame = [&](bool writingToScreenGrabTexture)
	{
		beModel* modelToRender = m_modelToUse < m_models.Count() ? &m_models[m_modelToUse] : nullptr;
			
		if (modelToRender)
		{
			modelToRender->Render(renderInterface, shaderPack, m_shaderToUse);
		}

		if (m_renderGrid)
		{
			m_gridModel.Render(renderInterface, shaderPack);
		}

		debugWorld->SetRenderAxes(m_renderAxes);
		debugWorld->Render(renderInterface, &shaderPack->shaderColour, m_camera.GetViewMatrix(), m_camera.GetPosition());

		renderInterface->DisableZBuffer();
		shaderPack->shaderTexture2d.SetShaderParameters(renderInterface, m_camera.GetViewMatrix());
			
		if (m_bitmapScreenGrab.GetTexture() && !writingToScreenGrabTexture)
		{
			m_bitmapScreenGrab.Render(renderInterface);
			shaderPack->shaderTexture2d.Render(renderInterface, m_bitmapScreenGrab.GetIndexCount(), m_bitmapScreenGrab.GetTexture(), true);
		}
			
		m_bitmapTexQuadNorm.Render(renderInterface);
		shaderPack->shaderTexture2d.Render(renderInterface, m_bitmapTexQuadNorm.GetIndexCount(), m_bitmapTexQuadNorm.GetTexture(), true);
	
		m_bitmapTexQuadPixelCoord.Render(renderInterface);
		shaderPack->shaderTexture2d.Render(renderInterface, m_bitmapTexQuadPixelCoord.GetIndexCount(), m_bitmapTexQuadPixelCoord.GetTexture(), false);

		renderInterface->EnableAlpha();

		{
			const Vec3 cameraPos = m_camera.GetPosition();
			const Matrix viewMatrix = m_camera.GetViewMatrix();

			const float screenX = (float)mouse->GetX();
			const float screenY = (float)mouse->GetY();
			Vec3 worldPos, worldDir;
			const bool isInBounds = beCameraUtils::GetScreeenToWorldRay(*renderInterface, m_camera.GetViewMatrix(), screenX, screenY, &worldPos, &worldDir);
			auto maybeRealWorldPos = beCameraUtils::WorldPosFromScreenPos(*renderInterface, m_camera.GetViewMatrix(), (int)screenX, (int)screenY);

			if (!isInBounds)
			{
				worldPos = V3N1();
				worldDir = V3N1();
			}
			if (!maybeRealWorldPos)
			{
				maybeRealWorldPos = V3N1();
			}


			fmt::memory_buffer message;
			fmt::format_to(message, "Dynamic Text\n");
			fmt::format_to(message, "Mouse [X, Y]: [{}, {}]\n", mouse->GetX(), mouse->GetY());
			fmt::format_to(message, "Camera [X, Y, Z]: [{:.2f}, {:.2f}, {:.2f}]\n", cameraPos.x, cameraPos.y, cameraPos.z);
			fmt::format_to(message, "Mat Right [X, Y, Z, W]: [{:.2f}, {:.2f}, {:.2f}, {:.2f}]\n", viewMatrix.m[0][0], viewMatrix.m[0][1], viewMatrix.m[0][2], viewMatrix.m[0][3]);
			fmt::format_to(message, "Mat Up    [X, Y, Z, W]: [{:.2f}, {:.2f}, {:.2f}, {:.2f}]\n", viewMatrix.m[1][0], viewMatrix.m[1][1], viewMatrix.m[1][2], viewMatrix.m[1][3]);
			fmt::format_to(message, "-Mat Forw [X, Y, Z, W]: [{:.2f}, {:.2f}, {:.2f}, {:.2f}]\n", viewMatrix.m[2][0], viewMatrix.m[2][1], viewMatrix.m[2][2], viewMatrix.m[2][3]);
			fmt::format_to(message, "_Mat Pos  [X, Y, Z, W]: [{:.2f}, {:.2f}, {:.2f}, {:.2f}]\n", viewMatrix.m[3][0], viewMatrix.m[3][1], viewMatrix.m[3][2], viewMatrix.m[3][3]);
			;
			if (isInBounds)
			{
				fmt::format_to(message, "ClickPos [X, Y, Z]: [{:.2f}, {:.2f}, {:.2f}]\n", worldPos.x, worldPos.y, worldPos.z);
				fmt::format_to(message, "ClickDir [X, Y, Z]: [{:.2f}, {:.2f}, {:.2f}]\n", worldDir.x, worldDir.y, worldDir.z);
			}
			if (maybeRealWorldPos)
			{
				fmt::format_to(message, "Collision [X, Y, Z]: [{:.2f}, {:.2f}, {:.2f}]\n", maybeRealWorldPos->x, maybeRealWorldPos->y, maybeRealWorldPos->z);
			}

			beString messageStr = fmt::to_string(message);
			m_bitmapTextDynamic.InitText(renderInterface, &m_font, messageStr.c_str(), 1.5f, 512.f, 0, false, beFont::WrapMode::Default);
			m_bitmapTextDynamic.Render(renderInterface);
			shaderPack->shaderTexture2d.Render(renderInterface, m_bitmapTextDynamic.GetIndexCount(), m_bitmapTextDynamic.GetTexture(), false, beShaderTexture2d::TextureMode::Clamped);
		}
			
		renderInterface->DisableAlpha();
			
		renderInterface->EnableZBuffer();
	};
	
	const bool doScreenGrab = keyboard->IsPressed(beKeyboard::Button::Space);
	if (doScreenGrab)
	{
		m_screenGrabTexture.SetAsTarget(renderInterface);
		m_screenGrabTexture.Clear(renderInterface, V40());
		renderFrame(true);
		renderInterface->RestoreRenderTarget();
		m_bitmapScreenGrab.Init(renderInterface, m_screenGrabTexture);
		renderInterface->ClearDepth();
	}
	renderFrame(false);
}
Exemple #5
0
GSTexture* GSDevice11::CreateSurface(int type, int w, int h, bool msaa, int format)
{
	HRESULT hr;

	D3D11_TEXTURE2D_DESC desc;

	memset(&desc, 0, sizeof(desc));

	desc.Width = w;
	desc.Height = h;
	desc.Format = (DXGI_FORMAT)format;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.SampleDesc.Count = 1;
	desc.SampleDesc.Quality = 0;
	desc.Usage = D3D11_USAGE_DEFAULT;

	if(msaa)
	{
		desc.SampleDesc = m_msaa_desc;
	}

	switch(type)
	{
	case GSTexture::RenderTarget:
		desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
		break;
	case GSTexture::DepthStencil:
		desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
		break;
	case GSTexture::Texture:
		desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		break;
	case GSTexture::Offscreen:
		desc.Usage = D3D11_USAGE_STAGING;
		desc.CPUAccessFlags |= D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
		break;
	}

	GSTexture11* t = NULL;

	CComPtr<ID3D11Texture2D> texture;

	hr = m_dev->CreateTexture2D(&desc, NULL, &texture);

	if(SUCCEEDED(hr))
	{
		t = new GSTexture11(texture);

		switch(type)
		{
		case GSTexture::RenderTarget:
			ClearRenderTarget(t, 0);
			break;
		case GSTexture::DepthStencil:
			ClearDepth(t);
			break;
		}
	}
	else
	{
		throw std::bad_alloc();
	}

	return t;
}