예제 #1
0
void CRenderingContext::RenderWireBox(const AABB& aabbBounds)
{
	BeginRenderLines();
		Vertex(aabbBounds.m_vecMaxs);
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMaxs.y, aabbBounds.m_vecMaxs.z));
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMaxs.y, aabbBounds.m_vecMins.z));
		Vertex(Vector(aabbBounds.m_vecMaxs.x, aabbBounds.m_vecMaxs.y, aabbBounds.m_vecMins.z));
		Vertex(aabbBounds.m_vecMaxs);

		Vertex(Vector(aabbBounds.m_vecMaxs.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMaxs.z));
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMaxs.z));
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMins.z));
		Vertex(Vector(aabbBounds.m_vecMaxs.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMins.z));
		Vertex(Vector(aabbBounds.m_vecMaxs.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMaxs.z));
	EndRender();

	BeginRenderLines();
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMaxs.y, aabbBounds.m_vecMaxs.z));
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMaxs.z));
	EndRender();

	BeginRenderLines();
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMaxs.y, aabbBounds.m_vecMins.z));
		Vertex(Vector(aabbBounds.m_vecMins.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMins.z));
	EndRender();

	BeginRenderLines();
		Vertex(Vector(aabbBounds.m_vecMaxs.x, aabbBounds.m_vecMaxs.y, aabbBounds.m_vecMins.z));
		Vertex(Vector(aabbBounds.m_vecMaxs.x, aabbBounds.m_vecMins.y, aabbBounds.m_vecMins.z));
	EndRender();
}
예제 #2
0
void CRenderingContext::RenderBillboard(const CMaterialHandle& hMaterial, float flRadius, Vector vecUp, Vector vecRight)
{
	TAssert(hMaterial.IsValid());
	if (!hMaterial.IsValid())
		return;

	vecUp *= flRadius;
	vecRight *= flRadius;

	// Clear out any existing rotation so that they don't interfere with the billboarding below.
	GetContext().m_mTransformations.SetAngles(EAngle(0, 0, 0));
	GetContext().m_bTransformUpdated = false;

	if (GetContext().m_hMaterial != hMaterial)
		UseMaterial(hMaterial);

	BeginRenderTriFan();
		TexCoord(0.0f, 1.0f);
		Vertex(-vecRight + vecUp);
		TexCoord(0.0f, 0.0f);
		Vertex(-vecRight - vecUp);
		TexCoord(1.0f, 0.0f);
		Vertex(vecRight - vecUp);
		TexCoord(1.0f, 1.0f);
		Vertex(vecRight + vecUp);
	EndRender();
}
예제 #3
0
    void VulkanWindow::Run()
    {
#ifdef _WIN32
        MSG msg;
        bool done = false;
        while ( !done )
        {
            if ( PeekMessage ( &msg, NULL, 0, 0, PM_REMOVE ) )
            {
                if ( msg.message == WM_QUIT )
                {
                    done = true;
                }
                else
                {
                    TranslateMessage ( &msg );
                    DispatchMessage ( &msg );
                }
            }
            else
            {
                BeginRender();
                EndRender();
            }
        }
#else
#endif
    }
	void RenderWindowD11_2::Render()
	{
		BeginRender();

		// Render all render component from scene
		if (m_bActive && m_pSceneToRender && m_pCamera) {	
			_lSceneObject objects;
			m_pSceneToRender->GetSceneObjects(objects);

			for (auto object : objects)
			{
				_lCoreComponent components;
				object->GetObjectComponents(components);

				for (auto component : components)
				{
					switch (component->GetType())
					{
					case Dex::OCT_RENDER:
					{
						RenderOneComponent(dynamic_cast<RenderComponentD11_2*>(component));
					}
					break;

					case Dex::OCT_CAMERA:
						break;
					case Dex::OCT_LIGHT:
						break;
					}
				}
			}
		}

		EndRender();
	}
예제 #5
0
	void Pipeline::OnRender(const App& app, const AppUpdateInfo&)
	{
		BeginRender();
		
		GfxTestureEx_SwapChain& swapChainTexture = m_swapChain.GetTexture();
		
		GfxGraphicsContext& context = m_contextManager.GetGraphicsContext(0);

		context.SetPipelineState(m_graphicsState);
						
		context.SetGraphicsRootSignature(m_rootSignature);

		context.SetRenderTarget(swapChainTexture);
			
		GfxViewport viewport(0.0f, 0.0f, (float)swapChainTexture.GetWidth(), (float)swapChainTexture.GetHeight());
		GfxScissor  scissor(0, 0, swapChainTexture.GetWidth(), swapChainTexture.GetHeight());
		context.SetViewports(1, &viewport);
		context.SetScissors(1, &scissor);

		swapChainTexture.SetClearColor(GfxColorRGBA(0.0f, 0.2f, 0.4f, 1.0f));
		context.ClearRenderTarget(swapChainTexture);

		context.SetPrimitiveTopology(GfxPrimitiveTopology::TriangleList);
		GfxVertexBufferView vbView(m_vertexBuffer, m_vertexBuffer.GetSize(), sizeof(PosColorVertex));
		context.SetVertexBuffer(
			0,
			vbView);
			
		context.DrawInstanced(3, 1, 0, 0);

		EndRender();
	}
예제 #6
0
	void SimpleSurface::applyFilter (Surface *inSrc, const Rect &inRect, ImagePoint inOffset, Filter *inFilter) {
		
		if (!mBase) return;
		FilterList f;
		f.push_back (inFilter);
		
		Rect src_rect (inRect.w, inRect.h);
		Rect dest = GetFilteredObjectRect (f, src_rect);
		
		inSrc->IncRef ();
		Surface *result = FilterBitmap (f, inSrc, src_rect, dest, false, ImagePoint (inRect.x, inRect.y));
		
		dest.Translate (inOffset.x, inOffset.y);
		
		src_rect = Rect (0, 0, result->Width (), result->Height ());
		int dx = dest.x;
		int dy = dest.y;
		dest = dest.Intersect (Rect (0, 0, mWidth, mHeight));
		dest.Translate (-dx, -dy);
		dest = dest.Intersect (src_rect);
		dest.Translate (dx, dy);
		
		int bpp = BytesPP ();
		
		RenderTarget t = BeginRender (dest, false);
		//printf("Copy back @ %d,%d %dx%d  + (%d,%d)\n", dest.x, dest.y, t.Width(), t.Height(), dx, dy);
		for (int y = 0; y < t.Height (); y++)
			memcpy ((void *)(t.Row (y + dest.y) + ((dest.x) * bpp)), result->Row (y - dy) - (dx * bpp), dest.w * bpp);
		
		EndRender ();
		
		result->DecRef ();
		
	}
예제 #7
0
void CompositorRenderPass::Commit(CommitContext& context) {
	
	if (context.rsys->GetTicket() != this->renderSystemTicket)	{
		if (numTextureToResolve == 1) {
			TextureUnit tu;
			RenderTarget* target = context.GetTargetByName(_rtJustOne.name);
			if (target && target->GetRenderTargetType() == RenderTargetType::TEXTURE) {
				tu.texture = static_cast<RenderTexture*>(target);
				parameters.SetData(&tu, _rtJustOne.offset);
			}
		} else {
			for (uint32 i = 0; i < numTextureToResolve; ++i) {
				TextureUnit tu;
				RenderTarget* target = context.GetTargetByName(_rtBunchOf[i].name);
				if (target && target->GetRenderTargetType() == RenderTargetType::TEXTURE) {
					tu.texture = static_cast<RenderTexture*>(target);
					parameters.SetData(&tu, _rtBunchOf[i].offset);
				}
			}
		}
		this->renderSystemTicket = context.rsys->GetTicket();
	}

	BeginRender(context);
	RenderPrimitive(context, (uint32)(ptrdiff_t)this, &primitive);
	EndRender(context);
}
void SpectralEffect::InitInGame()
{
	test.LoadFiles("Data.zip", d3dd);

	while (test.GetProgress() != 100)
	{
		Sleep (100);
	}
	
	string temp[1];
	temp[0] = "YellowBall.png";
	testpipe.SetPipeType(d3dd, 100, 100, 280, 5, 1, temp, 1, "Pipe.png");
	testcannons.InitCannonType(&testpipe, 30, 20, 100, 15, "Cannon.png");
	int time = 0, speed = 1;
	SetFPS(30);
	while (gameRunning)
	{
		StartFrame();
		BeginRender();
		testcannons.Render();
		testpipe.Render();
		EndRender();
		if (time > 500)
		{
			speed ++;
			testpipe.SetSpeed(speed);
			time = 0;
		}
		time ++;
		EndFrame();
	}

	gameRunning = true;
}
예제 #9
0
void CRenderSystemBase::ShowSplash(const std::string& message)
{
  if (!g_advancedSettings.m_splashImage && !(m_splashImage || !message.empty()))
    return;

  if (!m_splashImage)
  {
    std::string splashImage = "special://home/media/Splash.png";
    if (!XFILE::CFile::Exists(splashImage))
      splashImage = "special://xbmc/media/Splash.png";

    m_splashImage = std::unique_ptr<CGUIImage>(new CGUIImage(0, 0, 0, 0, g_graphicsContext.GetWidth(),
                                                       g_graphicsContext.GetHeight(), CTextureInfo(splashImage)));
    m_splashImage->SetAspectRatio(CAspectRatio::AR_SCALE);
  }

  g_graphicsContext.lock();
  g_graphicsContext.Clear();

  RESOLUTION_INFO res = g_graphicsContext.GetResInfo();
  g_graphicsContext.SetRenderingResolution(res, true);

  //render splash image
  BeginRender();

  m_splashImage->AllocResources();
  m_splashImage->Render();
  m_splashImage->FreeResources();

  if (!message.empty())
  {
    if (!m_splashMessageLayout)
    {
      auto messageFont = g_fontManager.LoadTTF("__splash__", "arial.ttf", 0xFFFFFFFF, 0, 20, FONT_STYLE_NORMAL, false, 1.0f, 1.0f, &res);
      if (messageFont)
        m_splashMessageLayout = std::unique_ptr<CGUITextLayout>(new CGUITextLayout(messageFont, true, 0));
    }

    if (m_splashMessageLayout)
    {
      m_splashMessageLayout->Update(message, 1150, false, true);
      float textWidth, textHeight;
      m_splashMessageLayout->GetTextExtent(textWidth, textHeight);

      int width = g_graphicsContext.GetWidth();
      int height = g_graphicsContext.GetHeight();
      float y = height - textHeight - 100;
      m_splashMessageLayout->RenderOutline(width/2, y, 0, 0xFF000000, XBFONT_CENTER_X, width);
    }
  }

  //show it on screen
  EndRender();
  g_graphicsContext.unlock();
  g_graphicsContext.Flip(true, false);
}
void CubemapGenerator::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
{
    updateCycle_++;
    if (updateCycle_ < 7)
        cameraNode_->SetWorldRotation(RotationOf(GetFaceForCycle(updateCycle_)));
    else
    {
        EndRender();
    }
}
예제 #11
0
		void Graphics::Update()
		{	
            BeginRender();
			Render3D();
            Begin2DRender();
            Render2D();
			End2DRender();
            PostRender3D();
            EndRender();
        }
예제 #12
0
HRESULT CObject::RenderObject()
{
	HRESULT hr = D3D_OK;

	CShaderManager::GetInstance()->SetObject( this );
	V_RETURN( BeginRender() );
	CShaderManager::GetInstance()->Render();
	V_RETURN( EndRender() );

	return hr;
}
예제 #13
0
void TerrainOverlay::RenderBeforeWater()
{
	if (!m_Terrain)
		return; // should never happen, but let's play it safe

#if CONFIG2_GLES
#warning TODO: implement TerrainOverlay::RenderOverlays for GLES
#else
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(GL_FALSE);
	// To ensure that outlines are drawn on top of the terrain correctly (and
	// don't Z-fight and flicker nastily), draw them as QUADS with the LINE
	// PolygonMode, and use PolygonOffset to pull them towards the camera.
	// (See e.g. http://www.opengl.org/resources/faq/technical/polygonoffset.htm)
	glPolygonOffset(-1.f, -1.f);
	glEnable(GL_POLYGON_OFFSET_LINE);

	pglActiveTextureARB(GL_TEXTURE0);
	glDisable(GL_TEXTURE_2D);

	StartRender();

	ssize_t min_i, min_j, max_i, max_j;
	GetTileExtents(min_i, min_j, max_i, max_j);
	// Clamp the min to 0, but the max to -1 - so tile -1 can never be rendered,
	// but if unclamped_max<0 then no tiles at all will be rendered. And the same
	// for the upper limit.
	min_i = clamp(min_i, ssize_t(0), m_Terrain->GetTilesPerSide());
	min_j = clamp(min_j, ssize_t(0), m_Terrain->GetTilesPerSide());
	max_i = clamp(max_i, ssize_t(-1), m_Terrain->GetTilesPerSide()-1);
	max_j = clamp(max_j, ssize_t(-1), m_Terrain->GetTilesPerSide()-1);

	for (m_j = min_j; m_j <= max_j; ++m_j)
		for (m_i = min_i; m_i <= max_i; ++m_i)
			ProcessTile(m_i, m_j);

	EndRender();

	// Clean up state changes
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_POLYGON_OFFSET_LINE);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDepthMask(GL_TRUE);
	glDisable(GL_BLEND);
#endif
}
예제 #14
0
void ForwardRenderPass::Commit(CommitContext& context) {

	/*context.sunLightIntensity = Vector4(1, 1, 1, 1);
	context.sunLightPosition = Vector4(0, 400, 0, 1);
	context.sunLightColor = Color(0.8f, 0.8f, 0.4f, 1);*/

	BeginRender(context);
	VisibilitySet& visibles = *context.visibiles;
	RenderQueueList& layerList = visibles.GetRenderQueues();
	for (auto &layer : layerList) {
		if (Test(layer.flags & RenderQueueFlags::FORWARD)) {
			for (auto &prim : layer.visibles) {
				RenderPrimitive(context, prim.first, prim.second);
			}
		}
	}
	EndRender(context);
}
예제 #15
0
void ParticleSystem::BeginRender()
{
	if(loaded)
	{
		EndRender();
	}

	material.texture = Texture::LoadFile("textures/Particle.png");

//	glGenVertexArrays(1, &vertexArray);
//	glBindVertexArray(vertexArray);

//	if(!material.shader->GetId())
	{
		material.shader = Shader::LoadFile("shaders/particles/Diffuse.vert", "shaders/particles/Diffuse.frag", "shaders/particles/Diffuse.geom");
	}

//	if(!material.texture->GetId())
	{
//		material.texture->LoadFile();
	}

	if(material.shader->GetId())
	{
		material.shader->AddUniform("model");
		material.shader->AddUniform("view");
		material.shader->AddUniform("projection");
		material.shader->AddUniform("viewportWidth");
		material.shader->AddUniform("cameraPosition");
		material.shader->AddUniform("systemPosition");
		material.shader->AddUniform("textureSampler");
	}

//	CreateBuffer(vertexBuffer, GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW);
//	CreateBuffer(colorBuffer, GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW);
//	CreateBuffer(sizeBuffer, GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW);
	Geometry::CreateBuffer(particleBuffer, GL_ARRAY_BUFFER, GL_STREAM_DRAW);
//	CreateBuffer(particles, GL_ARRAY_BUFFER, GL_STREAM_DRAW);

	loaded = true;
}
예제 #16
0
void CRenderingContext::RenderBillboard(const CMaterialHandle& hMaterial, float flRadius, Vector vecUp, Vector vecRight)
{
	TAssert(hMaterial.IsValid());
	if (!hMaterial.IsValid())
		return;

	vecUp *= flRadius;
	vecRight *= flRadius;

	UseMaterial(hMaterial);
	BeginRenderTriFan();
		TexCoord(0.0f, 1.0f);
		Vertex(-vecRight + vecUp);
		TexCoord(0.0f, 0.0f);
		Vertex(-vecRight - vecUp);
		TexCoord(1.0f, 0.0f);
		Vertex(vecRight - vecUp);
		TexCoord(1.0f, 1.0f);
		Vertex(vecRight + vecUp);
	EndRender();
}
예제 #17
0
void TerrainOverlay::Render()
{
	m_Terrain = g_Game->GetWorld()->GetTerrain();

	StartRender();

	ssize_t min_i, min_j, max_i, max_j;
	GetTileExtents(min_i, min_j, max_i, max_j);
	// Clamp the min to 0, but the max to -1 - so tile -1 can never be rendered,
	// but if unclamped_max<0 then no tiles at all will be rendered. And the same
	// for the upper limit.
	min_i = clamp(min_i, ssize_t(0), m_Terrain->GetTilesPerSide());
	min_j = clamp(min_j, ssize_t(0), m_Terrain->GetTilesPerSide());
	max_i = clamp(max_i, ssize_t(-1), m_Terrain->GetTilesPerSide()-1);
	max_j = clamp(max_j, ssize_t(-1), m_Terrain->GetTilesPerSide()-1);

	for (m_j = min_j; m_j <= max_j; ++m_j)
		for (m_i = min_i; m_i <= max_i; ++m_i)
			ProcessTile(m_i, m_j);

	EndRender();
}
예제 #18
0
bool RenderFunc()
{
    hge->Gfx_BeginScene();
    hge->Gfx_Clear(0xffffffff);

    if(!started) WelcomeRender();
    else
    if(started && !end) 
    {
        GamingRender();
        TimerRender();
    }
    else
    if(end) EndRender();

    fnt->SetScale(0.5);
    fnt->SetColor(0xff000000);
    fnt->printf(295, 570, HGETEXT_RIGHT, "FPS: %d\n%s", hge->Timer_GetFPS(), COPYRIGHT);

    hge->Gfx_EndScene();

    return false;
}
예제 #19
0
void CGUIWindowTestPattern::Render()
{
  BeginRender();
  const RESOLUTION_INFO info = g_graphicsContext.GetResInfo();

  int top    = info.Overscan.top;
  int bottom = info.Overscan.bottom;
  int left   = info.Overscan.left;
  int right  = info.Overscan.right;

  switch (m_pattern)
  {
    case 0:
      DrawContrastBrightnessPattern(top, left, bottom, right);
      break;

    case 1:
      DrawVerticalLines(top, left, bottom, right);
      break;

    case 2:
      DrawHorizontalLines(top, left, bottom, right);
      break;

    case 3:
      DrawCheckers(top, left, bottom, right);
      break;

    case 4:
      DrawBouncingRectangle(top, left, bottom, right);
      break;
  }

  EndRender();

  CGUIWindow::Render();
}
예제 #20
0
void CGUIWindowTestPattern::Render()
{
  BeginRender();

  int top = g_settings.m_ResInfo[g_graphicsContext.GetVideoResolution()].Overscan.top;
  int bottom = g_settings.m_ResInfo[g_graphicsContext.GetVideoResolution()].Overscan.bottom;
  int left = g_settings.m_ResInfo[g_graphicsContext.GetVideoResolution()].Overscan.left;
  int right = g_settings.m_ResInfo[g_graphicsContext.GetVideoResolution()].Overscan.right;

  switch (m_pattern)
  {
    case 0:
      DrawContrastBrightnessPattern(top, left, bottom, right);
      break;

    case 1:
      DrawVerticalLines(top, left, bottom, right);
      break;

    case 2:
      DrawHorizontalLines(top, left, bottom, right);
      break;

    case 3:
      DrawCheckers(top, left, bottom, right);
      break;

    case 4:
      DrawBouncingRectangle(top, left, bottom, right);
      break;
  }

  EndRender();

  CGUIWindow::Render();
}
예제 #21
0
void DCRenderer::Draw(f32 fDeltaTime)
{	
    // For our world matrix, we will just rotate the object about the y-axis.
    D3DXMATRIXA16 mxView, mxProj;

    D3DXVECTOR3 vEye(0.0f, 5.0f,-5.0f);
    D3DXVECTOR3 vAt(0.0f,0.0f,1.0f);
    D3DXVECTOR3 vUp(0.0f,1.0f,0.0f);

    float fAspectRatio = m_pRenderWidget->width() / (FLOAT)m_pRenderWidget->height();

    D3DXMatrixLookAtLH(&mxView, &vEye, &vAt, &vUp);
    D3DXMatrixPerspectiveFovLH(&mxProj, D3DX_PI/3, fAspectRatio, 0.001f, 100.0f);

 	//models
	// For our world matrix, we will just rotate the object about the y-axis.
	D3DXMATRIXA16 mxWorld, mxViewProj;

	D3DXMatrixIdentity(&mxViewProj);

	BM_AssertHr(DEVICEPTR->BeginScene());	
	{        
		BeginRender();
		DEVICEPTR->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_COLORVALUE(85.0f/255.0f,101.0f/255.0f,215.0f/255.0f,1.0f), 1.0f, 0 );
		BM_AssertHr(DEVICEPTR->EndScene());    

		//models		
		const std::vector<BatchNode>& nodes = BatchNodes;
		const u32 nodeNum = nodes.size();
		for(u32 nodeIdx = 0; nodeIdx<nodeNum; nodeIdx++)
		{
			BM_AssertHr(DEVICEPTR->BeginScene());
			const BatchNode& nodePtrRef = nodes[nodeIdx];
			const XMFLOAT3& translation = nodePtrRef.translation;
			D3DXMatrixTranslation(&mxWorld, translation.x, translation.y, translation.z);
			mxViewProj = mxView * mxProj;

			DEVICEPTR->SetVertexShaderConstantF(0,(float*)&(mxWorld),4);
			DEVICEPTR->SetVertexShaderConstantF(4,(float*)mViewProjMatrix,4);
			DEVICEPTR->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
			DEVICEPTR->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

			nodePtrRef.model->Draw(0);
			BM_AssertHr(DEVICEPTR->EndScene()); 
		}

		BM_AssertHr(DEVICEPTR->BeginScene());

		//terrain		
		if(TerrainPtr)
		{
			TerrainPtr->Draw(&mxWorld, (D3DXMATRIXA16*)mViewMatrix, (D3DXMATRIXA16*)mProjMatrix);
		}

		BMPostFXRenderer::GetInstance()->Render();

		EndRender();
		BM_AssertHr(DEVICEPTR->EndScene()); 
	}

	BatchNodes.clear();
}
예제 #22
0
	void Pipeline::OnRender(const App& app, const AppUpdateInfo&)
	{
		BeginRender();
		
		GfxGraphicsContext& context = m_contextManager.GetGraphicsContext(0);

		context.ResourceBarrier(
			m_depth,
			GfxResourceState::DepthWrite);

		context.ResourceBarrier(
			m_rt,
			GfxResourceState::RenderTarget);
		
		context.SetRenderTarget(m_rt, m_depth);

		GfxViewport viewport0 = GfxViewport(0.0f, 0.0f, (float)m_rt.GetWidth(), (float)m_rt.GetHeight());
		GfxScissor scissor0  = GfxScissor(0, 0, m_rt.GetWidth(), m_rt.GetHeight());
		context.SetViewports(1, &viewport0);
		context.SetScissors(1, &scissor0);

		context.ClearRenderTarget(m_rt);
		context.ClearDepthStencilTarget(m_depth);

		{
			m_renderer.SetViewMatrix(m_view);
			m_renderer.SetProjectionMatrix(m_proj);

			RendererGraphicsStateDesc renderDesc;
			renderDesc.m_rtvFormats[0] = GfxFormat::R8G8B8A8_Unorm;
			renderDesc.m_dsvFormat = GfxFormat::D32_Float;
			renderDesc.m_depthEnable = true;
			renderDesc.m_depthWriteMask = GfxDepthWriteMask::All;
			m_renderer.Render(
				context,
				RendererDrawStageType::RendererDrawStageType_Opaque,
				renderDesc);
		}
		
		context.ResourceBarrier(m_rt, GfxResourceState::PixelShaderResource);		
		context.ResourceBarrier(m_depth, GfxResourceState::GenericRead);
		
		// 箱を描いたレンダーターゲットテクスチャをスワップチェインに描画する
		{
			GfxTestureEx_SwapChain& swapChainTexture = m_swapChain.GetTexture();
			GfxViewport viewport1(0.0f, 0.0f, (float)swapChainTexture.GetWidth(), (float)swapChainTexture.GetHeight());
			GfxScissor  scissor1(0, 0, swapChainTexture.GetWidth(), swapChainTexture.GetHeight());
			context.SetRenderTarget(swapChainTexture);
			context.SetViewports(1, &viewport1);
			context.SetScissors(1, &scissor1);
		
			context.SetPipelineState(m_graphicsState);
			context.SetGraphicsRootSignature(m_rootSignature);

			context.SetDynamicViewDescriptor(0, 0, m_rt);
			context.SetDynamicSamplerDescriptor(1, 0, m_sampler);
			context.SetGraphicsRootCBV(2, m_constantBuffer.Get());

			swapChainTexture.SetClearColor(GfxColorRGBA(0.0f, 0.2f, 0.4f, 1.0f));
			context.ClearRenderTarget(swapChainTexture);

			context.SetPrimitiveTopology(GfxPrimitiveTopology::TriangleList);

			context.SetDynamicVB(0, ArraySize(kVertexData), sizeof(kVertexData[0]), kVertexData);

			context.DrawInstanced(6, 1, 0, 0);
		}

		EndRender();
	}
예제 #23
0
// |----------------------------------------------------------------------------|
// |						      Render										|
// |----------------------------------------------------------------------------|
bool GraphicsClass::Render(int mouseX, int mouseY, Coord camera_position)
{
	bool result;
	static float rotation = 0.0f;

	result = BeginRender();

	// Turn off the Z buffer and culling for skybox
	m_D3D->TurnZBufferOff();
	m_D3D->TurnOffBackCulling();

	// Skybox rendering
	D3DXMATRIX ident, translationMatrix;
	D3DXMatrixIdentity(&ident);
	D3DXMatrixTranslation(&translationMatrix, camera_position.x, camera_position.y, camera_position.z-300);
	result = result && SunRender(*m_skybox, ident, translationMatrix, ident);

	// Turn the Z buffer and back culling on now that skybox is rendered.
	m_D3D->TurnZBufferOn();
	m_D3D->TurnOnBackCulling();

	// Render planets
	ModelClass* planet_model(0);

	m_sun->GetModel(planet_model);
	result = result && SunRender(*planet_model, m_sun->GetScale(), m_sun->GetTranslate(), 
		m_sun->GetRotate());
	
	m_mercury->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_mercury->GetScale(), m_mercury->GetTranslate(), 
		m_mercury->GetRotate());
	
	m_venus->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_venus->GetScale(), m_venus->GetTranslate(), 
		m_venus->GetRotate());
	
	m_earth->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_earth->GetScale(), m_earth->GetTranslate(), 
		m_earth->GetRotate());
	
	m_mars->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_mars->GetScale(), m_mars->GetTranslate(), 
		m_mars->GetRotate());
	
	m_jupiter->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_jupiter->GetScale(), m_jupiter->GetTranslate(), 
		m_jupiter->GetRotate());
	
	m_saturn->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_saturn->GetScale(), m_saturn->GetTranslate(), 
		m_saturn->GetRotate());
	
	m_uranus->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_uranus->GetScale(), m_uranus->GetTranslate(), 
		m_uranus->GetRotate());
	
	m_neptune->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_neptune->GetScale(), m_neptune->GetTranslate(), 
		m_neptune->GetRotate());
	
	m_halley->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_halley->GetScale(), m_halley->GetTranslate(), 
		m_halley->GetRotate());
	
	m_luna->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_luna->GetScale(), m_luna->GetTranslate(), 
		m_luna->GetRotate());
	
	m_phobos->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_phobos->GetScale(), m_phobos->GetTranslate(), 
		m_phobos->GetRotate());
	
	m_deimos->GetModel(planet_model);
	result = result && ModelRender(*planet_model, m_deimos->GetScale(), m_deimos->GetTranslate(), 
		m_deimos->GetRotate());

	// Turn on alpha blending.
	m_D3D->TurnOnAlphaBlending();

	// Put the particle system vertex and index buffers on the graphics pipeline to prepare them for drawing.
	m_ParticleSystem->Render(m_D3D->GetDeviceContext());

	// Render the particles using the texture shader.
	D3DXMatrixIdentity(&worldMatrix);
	result = m_ParticleShader->Render(m_D3D->GetDeviceContext(), m_ParticleSystem->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, 
					  m_ParticleSystem->GetTexture());
	if(!result)
	{
		return false;
	}

	// Turn off alpha blending.
	m_D3D->TurnOffAlphaBlending();

	// Turn off the Z buffer to begin all 2D rendering.
	m_D3D->TurnZBufferOff();

	// Turn on the alpha blending before rendering the text.
	m_D3D->TurnOnAlphaBlending();

	// BITMAP rendering
	result = result && BitmapRender(*crosshairs, mouseX-30, mouseY-25);
	result = result && BitmapRender(*HUD, 0, 0);

	// TEXT rendering
	result = m_Text->Render(m_D3D->GetDeviceContext(), worldMatrix, orthoMatrix);
	if(!result)
	{
		return false;
	}

	// Turn off alpha blending after rendering the text.
	m_D3D->TurnOffAlphaBlending();

	// TITLE SCREEN rendering
	if (m_screen == 0) result = result && BitmapRender(*m_titleScreen, 0, 0);
	if (m_screen == 1) result = result && BitmapRender(*m_controlsScreen, 0, 0);

	// Turn the Z buffer back on now that all 2D rendering has completed.
	m_D3D->TurnZBufferOn();

	// Perform closing actions
	result = result && EndRender();

	return result;
}
예제 #24
0
int main(){
	auto pLogger = CB::Log::CLogger::GetInstance();
	pLogger->AddStream(CB::IO::File::Open(L"main.log", CB::IO::File::AccessType::WriteOnly, CB::IO::File::OpenAction::AlwaysCreate).Cast<CB::IO::IStream>());
	pLogger->AddStream(CB::IO::Console::Create().Cast<CB::IO::IStream>(), CB::Log::CTextFormatter::Create(CB::String::Encoding::ANSI).Cast<CB::Log::IEntryFormatter>());
	pLogger->SetDebugMode(true);

	try{
		auto pWinDriver = CB::Window::LoadDriver(L"MSWindowDriver");
		auto pGraphicDriver = CB::Graphic::LoadDriver(L"OGLGraphicDriver");
		{
			auto pWinManager = pWinDriver->CreateManager();
			auto pGraphicManager = pGraphicDriver->CreateManager(pWinManager);
			
			CB::Math::CSize outSize(640, 480);
			auto pWindow = pWinManager->CreateWindow(L"GraphicTest", CB::Window::Style::Single, outSize);

			auto pGraphicAdapter = pGraphicManager->GetDefaultAdapter();

			CB::Graphic::CDisplayMode dispMode(pWindow->GetSize(), 0, CB::Graphic::BufferFormat::B8G8R8X8);
			CB::Graphic::CDeviceDesc devDesc(pWindow, dispMode, CB::Graphic::BufferFormat::D24S8, false);

			CB::Collection::CList<CB::Graphic::FeatureLevel> featureLevels;
			featureLevels.Add(CB::Graphic::FeatureLevel::Level_1);

			auto pGraphicDevice = pGraphicAdapter->CreateDevice(pWindow, devDesc, featureLevels);

			pWindow->OnClose += CB::Signals::CFunc<const bool, CB::CRefPtr<CB::Window::IWindow>>(CloseEvent);

			pWindow->SetVisible(true);

			CB::Graphic::CDepthStencilStateDesc depthDesc;
			depthDesc.bDepthTestEnabled = true;
			depthDesc.uDepthFunction = CB::Graphic::CompareFunc::LessEqual;
			auto pDepthState = pGraphicDevice->CreateState(depthDesc);
			pGraphicDevice->SetState(pDepthState.Cast<CB::Graphic::IDeviceState>());

			CB::Graphic::CRasterizerStateDesc rastDesc;
			rastDesc.uCullMode = CB::Graphic::CullMode::None;
			auto pRastState = pGraphicDevice->CreateState(rastDesc);
			pGraphicDevice->SetState(pRastState.Cast<CB::Graphic::IDeviceState>());

			CB::Graphic::CBlendStateDesc blendDesc;
			blendDesc.ColorBlend.uDestOperand = CB::Graphic::BlendOption::OneMinusSourceAlpha;
			blendDesc.ColorBlend.uSourceOperand = CB::Graphic::BlendOption::SourceAlpha;
			blendDesc.ColorBlend.uOperation = CB::Graphic::BlendOperation::Add;
			blendDesc.AlphaBlend.uDestOperand = CB::Graphic::BlendOption::OneMinusSourceAlpha;
			blendDesc.AlphaBlend.uSourceOperand = CB::Graphic::BlendOption::SourceAlpha;
			blendDesc.AlphaBlend.uOperation = CB::Graphic::BlendOperation::Add;
			blendDesc.bEnabled[0] = true;
			auto pBlendState = pGraphicDevice->CreateState(blendDesc);
			pGraphicDevice->SetState(pBlendState.Cast<CB::Graphic::IDeviceState>());

			auto pFontManager = CB::Font::CManager::Create();

			auto pFontStream = CB::IO::File::Open(L"Assets/font.ttf").Cast<CB::IO::IStream>();
			auto pFont = pFontManager->Load(pFontStream);
			
			pFont->SelectFace(0);
			pFont->SetSize(24);

			CB::Collection::CList<CB::Tools::CFontCharDesc> charDescs;
			CB::Tools::CFontTextureGenerator fontGen(pGraphicDevice);

			fontGen.MaxTextureSize.Set(512, 512);
			auto pTexture = fontGen.Generate(pFont, charDescs);

			CB::Tools::CTextMeshGenerator textGen(charDescs);
			CB::Tools::CMeshRawIVT textMesh;

			textGen.Generate(L"Marek	M³ynarski!", textMesh);

			CB::Collection::CList<CB::Graphic::CVertexElement> vEls;
			vEls.Add(CB::Graphic::CVertexElement(0, L"vinput.vPosition", CB::Graphic::VertexType::Float, 3, 0));
			vEls.Add(CB::Graphic::CVertexElement(1, L"vinput.vTexCoord", CB::Graphic::VertexType::Float, 2, 0));

			GraphicTest::CShaderLoader shaders(pGraphicDevice, L"Shaders/TextureShader.cg");

			auto pTextDecl = pGraphicDevice->CreateVertexDeclaration(shaders.pVertexShader, vEls);

			auto pTextVertexBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Vertex, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.Vertices);
			auto pTextTCoordBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Vertex, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.TexCoords);
			auto pTextIndexBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Index, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.Indices);

			float32 fAspect = (float32)outSize.Width / (float32)outSize.Height;
			CB::Math::CMatrix mProj = CB::Math::CMatrix::GetPerspective(fAspect, 60.0f, 1.0f, 100.0f);
			CB::Math::CMatrix mView = CB::Math::CMatrix::GetTranslation(-4.0f, 0.0f, -3.4f);
			CB::Math::CMatrix mModel = CB::Math::CMatrix::GetIdentity();

			shaders.pFragmentShader->SetSampler(L"texDiffuse", pTexture.Cast<CB::Graphic::IBaseTexture>());
			pTexture->SetFilters(CB::Graphic::TextureFilter::Linear, CB::Graphic::TextureFilter::Linear, CB::Graphic::TextureFilter::Linear);
			pTexture->SetAnisotropy(8);
			//g_pTexture = texture.pTexture;			

			while(g_bRun){
				pGraphicDevice->Clear(1.0f, 1);
				pGraphicDevice->Clear(CB::Math::CColor(1.0f, 0.5f, 0.0f, 1.0f));

				pGraphicDevice->BeginRender();

				pGraphicDevice->SetShader(shaders.pVertexShader);
				pGraphicDevice->SetShader(shaders.pFragmentShader);

				static float32 fV = 0.0f;
				fV += 20 * g_Timer.GetTimeDelta();
				mModel = CB::Math::CMatrix::GetRotation(CB::Math::AxisOrientation::AxisX, fV);

				shaders.pVertexShader->SetUniform(L"vinput.mProj", mProj);
				shaders.pVertexShader->SetUniform(L"vinput.mView", mView);
				shaders.pVertexShader->SetUniform(L"vinput.mModel", mModel);

				pGraphicDevice->SetVertexDeclaration(pTextDecl);
				pGraphicDevice->SetVertexBuffer(0, pTextVertexBuffer);
				pGraphicDevice->SetVertexBuffer(1, pTextTCoordBuffer);
				pGraphicDevice->SetIndexBuffer(pTextIndexBuffer);

				pGraphicDevice->RenderIndexed(textMesh.uNumberOfPolygons);

				pGraphicDevice->EndRender();

				g_Timer.Update();
				pWinManager->ProcessEvents();

				float fFPS = 1.0f / (g_Timer.GetTimeDelta() == 0.0f ? 1.0f : g_Timer.GetTimeDelta());
				uint32 uFPS = (uint32)fFPS;

				textMesh.Clear();
				textGen.Generate(L"FPS: " + CB::String::ToString(uFPS), textMesh);

				pTextVertexBuffer->LoadData(textMesh.Vertices);
				pTextTCoordBuffer->LoadData(textMesh.TexCoords);
				pTextIndexBuffer->LoadData(textMesh.Indices);

				pGraphicDevice->Swap();
			}

			g_pTexture.Release();
		}
	}
	catch(CB::Exception::CException& Exception){
		CB::Log::Write(Exception, CB::Log::LogLevel::Fatal);
		CB::Message::Show(Exception, CB::Message::Icon::Error);
	}
	return 0;
}
void HookGui::HGWidgetShader::Render(VulkanWrapper::Context* _graphicContext, int _swapchainImageIndex)
{
	// Check if this shader is valid to be used
	if (!IsValid())
	{
		return;
	}

	// Update the instance data
	UpdateInstanceData(_graphicContext);

	// Begin the rendering process
	BeginRender(_graphicContext, _swapchainImageIndex);

	// Get the vertex buffers
	VulkanWrapper::Buffer* vertexBuffer = m_WidgetModel->GetVertexBuffer();
	VulkanWrapper::Buffer* indexBuffer = m_WidgetModel->GetIndexBuffer();

	// Set the buffers and offsets
	VkBuffer vertexBuffers[] = { vertexBuffer->GetRawBuffer() };
	VkBuffer instanceBuffers[] = { m_InstanceBuffer.GetRawBuffer() };
	VkDeviceSize vertexOffsets[] = { 0 };
	VkDeviceSize instaceOffsets[] = { 0 };

	// Bind them
	vkCmdBindVertexBuffers(m_CommandBuffer, 0, 1, vertexBuffers, vertexOffsets);
	vkCmdBindVertexBuffers(m_CommandBuffer, 1, 1, instanceBuffers, instaceOffsets);
	vkCmdBindIndexBuffer(m_CommandBuffer, indexBuffer->GetRawBuffer(), 0, VK_INDEX_TYPE_UINT32);

	// Set the initial texture identificator
	uint32_t currentTextureIdentificator = -1;

	// The total number of instances to be rendered
	uint32_t totalInstances = 0;

	// The first instance to be rendered
	uint32_t firstInstance = 0;

	// For each widget
	for (int i = 0; i < m_Renderables.size(); i++)
	{
		// Get the current widget
		HGWidget* widget = m_Renderables[i];

		// Get the widget image
		HGImage* widgetImage = widget->GetImage();

		// Get the image texture group
		VulkanWrapper::TextureGroup* widgetImageTextureGroup = widgetImage->GetTextureGroupReference();

		// Get the texture group identificator
		uint32_t textureIdentificator = widgetImageTextureGroup->GetTextureGroupIdentificator();

		// Check if we are using the same texture group
		if (currentTextureIdentificator != textureIdentificator)
		{
			// Update the texture identificator
			VkDescriptorSet descriptorSets[] = { widgetImageTextureGroup->GetDescriptorSet(), m_DescriptorSet };
			vkCmdBindDescriptorSets(m_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_PipelineLayout, 0, 2, descriptorSets, 0, nullptr);

			// If we have at last one instance
			if (totalInstances)
			{
				// Issue a draw call
				vkCmdDrawIndexed(m_CommandBuffer, m_WidgetModel->GetIndexCount(), totalInstances, 0, 0, firstInstance);

				// Set the new first instance
				firstInstance = i;

				// Zero the total instances
				totalInstances = 0;
			}
			
			// Set the new current texture identificator
			currentTextureIdentificator = textureIdentificator;
		}

		// Increment the total number of instances
		totalInstances++;
	}

	// Check if we have instances remaining
	if (totalInstances)
	{
		// Issue the last draw call
		vkCmdDrawIndexed(m_CommandBuffer, m_WidgetModel->GetIndexCount(), totalInstances, 0, 0, firstInstance);
	}

	// Clear the renderable array
	m_Renderables.clear();

	// End the rendering process
	EndRender();
}
예제 #26
0
void ParticleSystem::OnDestroy()
{
	EndRender();
}
예제 #27
0
 // Convenience method to render a single copy of a geometry.
 inline void RenderSimpleGeom(glm::mat4* mvpMat, SimpleGeom *sg) {
     BeginRender(sg->vbuf);
     Render(sg->ibuf, mvpMat);
     EndRender();
 }