Beispiel #1
0
void
sge::d3d9::devicefuncs::draw_primitive(
	IDirect3DDevice9 &_device,
	sge::renderer::vertex::first const _first_vertex,
	sge::renderer::vertex::count const _num_vertices,
	sge::renderer::primitive_type const _primitive_type
)
{
	if(
		_device.DrawPrimitive(
			sge::d3d9::convert::primitive_type(
				_primitive_type
			),
			static_cast<
				UINT
			>(
				_first_vertex.get()
			),
			static_cast<
				UINT
			>(
				sge::renderer::vertex::to_primitive_count(
					_num_vertices,
					_primitive_type
				).get()
			)
		)
		!= D3D_OK
	)
		throw sge::renderer::exception(
			FCPPT_TEXT("DrawPrimitive() failed!")
		);
}
Beispiel #2
0
bool CBasicObjects::RenderBoxNormal()
{
	HRESULT hr;

	IDirect3DDevice9 * pDevice = CGraphicsManager::GetInstance()->GetDevice();

	hr = pDevice->SetStreamSource(0, m_pNormalBox, 0, sizeof(SNormalVertex));
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set stream source to box normal vb", hr);
		return false;
	}

	hr = pDevice->SetFVF(SNormalVertex::_fvf);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set FVF for box normal vb", hr);
		return false;
	}

	hr = pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2 * 6);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to draw box normal", hr);
		return false;
	}

	return true;
}
void CShowPoints9::Draw(const D3DXMATRIX& WorldMatrix)
{
    HRESULT hr = S_OK;

    if(!SkinnedVB)
        return;

    IDirect3DDevice9* device = DXUTGetD3D9Device();


    V( Effect->SetMatrix( "World", &WorldMatrix) );
    V( Effect->SetMatrix( "View", DXVGetCamera().GetViewMatrix() ));
    V( Effect->SetMatrix( "Projection", DXVGetCamera().GetProjMatrix() ));
    V( Effect->SetVector( "Color", &D3DXVECTOR4(1.0f,1.0f,0.0f,1.0f)) );

    V( Effect->SetTechnique( Effect->GetTechnique(0)) );

    UINT numPasses;
    V( Effect->Begin( &numPasses, 0 ));

    for( UINT iPass = 0; iPass < numPasses; iPass++ )
    {
        V( Effect->BeginPass( iPass ) );

        V( device->SetVertexDeclaration( Declaration ) );
        V( device->SetStreamSource(0, SkinnedVB, 0 , Stride ) );

        V( device->DrawPrimitive( D3DPT_POINTLIST, 0, NumPoints) );

        V( Effect->EndPass() );
    }
    V( Effect->End() );
}
Beispiel #4
0
bool CBasicObjects::RenderRect()
{
	HRESULT hr;
	const int iCornerCount = 6;

	IDirect3DDevice9 * pDevice = CGraphicsManager::GetInstance()->GetDevice();

	hr = pDevice->SetStreamSource(0, m_pRectVB, 0, sizeof(SFaceVertex));
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set stream source to rect vb", hr);
		return false;
	}

	hr = pDevice->SetFVF(SFaceVertex::_fvf);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set FVF for rect", hr);
		return false;
	}

	hr = pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, iCornerCount);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to draw rect", hr);
		return false;
	}

	return true;
}
Beispiel #5
0
bool CBasicObjects::RenderPoles()
{
	HRESULT hr;
	const int iPoleCount = (g_iGridSize + 1) * (g_iGridSize + 1);

	IDirect3DDevice9 * pDevice = CGraphicsManager::GetInstance()->GetDevice();

	hr = pDevice->SetStreamSource(0, m_pPolesVB, 0, sizeof(SLineVertex));
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set stream source to grid vb", hr);
		return false;
	}

	hr = pDevice->SetFVF(SLineVertex::_fvf);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set stream source to grid vb", hr);
		return false;
	}

	hr = pDevice->DrawPrimitive(D3DPT_LINELIST, 0, iPoleCount);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set stream source to grid vb", hr);
		return false;
	}

	return false;
}
    void CFullscreenTriangleDrawer::DrawDX9( IDirect3DTexture9* texture )
    {
        float width = ( float )gEnv->pRenderer->GetWidth();
        float height = ( float )gEnv->pRenderer->GetHeight();

        IDirect3DDevice9* pDevice = static_cast<IDirect3DDevice9*>( gD3DDevice );

        m_pStateBlock->Capture();

        pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
        pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
        pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

        pDevice->SetVertexDeclaration( m_pVertexDeclaration );
        pDevice->SetStreamSource( 0, m_pVertexBuffer, 0, 5 * sizeof( float ) );

        pDevice->SetVertexShader( m_pVertexShader9 );
        pDevice->SetVertexShaderConstantF( 0, &width, 1 );
        pDevice->SetVertexShaderConstantF( 1, &height, 1 );

        pDevice->SetPixelShader( m_pPixelShader9 );
        pDevice->SetTexture( 0, texture );

        pDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 3 );

        m_pStateBlock->Apply();
    }
Beispiel #7
0
			Air::U1 System::DrawOpt( const DrawOption& opt )
			{
				IDirect3DDevice9*	pDev		=	GetGlobal().m_pDevice;
				D3DPRIMITIVETYPE	drawType	=	(D3DPRIMITIVETYPE)opt.m_DrawType;

				if(opt.m_uiInstanceCount!=0){
					SetStreamSourceFreq(	0,	D3DSTREAMSOURCE_INDEXEDDATA		| opt.m_uiInstanceCount);
					SetStreamSourceFreq(	1,	D3DSTREAMSOURCE_INSTANCEDATA	| 1ul );
				}

				switch(opt.m_DrawFuncType){
					case	Draw::FUNC_TYPE_DP:{
						pDev->DrawPrimitive(drawType,
											opt.m_uiBaseVertexIndex,
											opt.m_uiFaceCount);
						break;}
					case	Draw::FUNC_TYPE_DIP:{
						pDev->DrawIndexedPrimitive(drawType,
													opt.m_uiBaseVertexIndex,
													0,
													opt.m_uiVertexCount,
													opt.m_uiStartIndex,
													opt.m_uiFaceCount);
						break;}
				}
				if(opt.m_uiInstanceCount!=0){
					SetStreamSourceFreq(0,1);
					SetStreamSourceFreq(1,1);
				}
				return	true;
			}
Beispiel #8
0
void Render()
{
	IDirect3DDevice9 *dev = GetDevice();
	if (dev)
	{
		dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(50, 50, 200), 1.0f, 0);
		dev->BeginScene();

		for (int i = 0; i < length; ++i)
		{
			int value = segments[i];
			int x = value % size;
			int y = value / size;

			if (map[value])
			{
				D3DXMATRIX translation;
				D3DXMatrixTranslation(&translation, -1 + (x * width), -1 + (y * height), 0);
				dev->SetTransform(D3DTS_WORLD, &translation);

				dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
			}
		}


		{
			int value = target;
			int x = value % size;
			int y = value / size;

			D3DXMATRIX translation;
			D3DXMatrixTranslation(&translation, -1 + (x * width), -1 + (y * height), 0);
			dev->SetTransform(D3DTS_WORLD, &translation);

			dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
		}

		dev->EndScene();
		dev->Present(NULL, NULL, NULL, NULL);
	}
	else
	{
		Sleep(500);
		Beep(440, 100);
	}
}
Beispiel #9
0
  void GPUContextDX9::drawRectangle(
    const GPURegion& inOutputRegion, 
    const GPUInterpolant* inInterpolants, 
    unsigned int inInterpolantCount )
  {
    HRESULT result;

//    result = _device->Clear( 0, NULL, D3DCLEAR_TARGET, 0, 0.0, 0 );
//    DX9AssertResult( result, "Clear failed" );

    DX9Vertex* vertices;
    result = _vertexBuffer->Lock( 0, 0, (void**)&vertices, D3DLOCK_DISCARD );
    DX9AssertResult( result, "VB::Lock failed" );

    DX9Assert( inInterpolantCount <= 8,
      "Can't have more than 8 texture coordinate interpolators" );

    DX9Vertex vertex;
    for( size_t i = 0; i < 3; i++ )
    {
      float4 position = inOutputRegion.vertices[i];

      // TIM: bad
      vertex.position.x = position.x;
      vertex.position.y = position.y;
      vertex.position.z = 0.5f;
      vertex.position.w = 1.0f;

      for( size_t t = 0; t < inInterpolantCount; t++ )
        vertex.texcoords[t] = inInterpolants[t].vertices[i];

      *vertices++ = vertex;
    }
    result = _vertexBuffer->Unlock();
    DX9AssertResult( result, "VB::Unlock failed" );

    result = _device->SetVertexDeclaration( _vertexDecl );
    DX9AssertResult( result, "SetVertexDeclaration failed" );

    result = _device->SetStreamSource( 0, _vertexBuffer, 0, sizeof(DX9Vertex) );
    DX9AssertResult( result, "SetStreamSource failed" );

    for( size_t t = 0; t < kMaximumSamplerCount; t++ )
    {
      if( _boundTextures[t] )
        _boundTextures[t]->validateCachedData();
    }

    result = _device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
    DX9AssertResult( result, "DrawPrimitive failed" );

    for( size_t j = 0; j < kMaximumOutputCount; j++ )
    {
      if( _boundOutputs[j] )
        _boundOutputs[j]->markCachedDataChanged();
    }
  }
Beispiel #10
0
void Blit9::render()
{
    IDirect3DDevice9 *device = mRenderer->getDevice();

    HRESULT hr = device->SetStreamSource(0, mQuadVertexBuffer, 0, 2 * sizeof(float));
    hr = device->SetVertexDeclaration(mQuadVertexDeclaration);

    mRenderer->startScene();
    hr = device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
Beispiel #11
0
void Blit::render()
{
    egl::Display *display = getDisplay();
    IDirect3DDevice9 *device = getDevice();

    HRESULT hr = device->SetStreamSource(0, mQuadVertexBuffer, 0, 2 * sizeof(float));
    hr = device->SetVertexDeclaration(mQuadVertexDeclaration);

    display->startScene();
    hr = device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
Beispiel #12
0
bool MythRenderD3D9::DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer)
{
    if (!m_vertexbuffers.contains(vertexbuffer))
        return false;

    D3D9Locker locker(this);
    IDirect3DDevice9* dev = locker.Acquire();
    if (!dev)
        return false;

    IDirect3DTexture9 *texture = m_vertexbuffers[vertexbuffer].m_texture;

    if (texture && !SetTexture(dev, texture))
        return false;

    EnableBlending(dev, true);
    SetTextureVertices(dev, true);
    MultiTexturing(dev, false);

    HRESULT hr = dev->SetStreamSource(0, vertexbuffer,
                                              0, sizeof(TEXTUREVERTEX));
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "SetStreamSource() failed");
        return false;
    }

    hr = dev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "DrawPrimitive() failed");
        return false;
    }

    return true;
}
Beispiel #13
0
void MythRenderD3D9::DrawRect(const QRect &rect, const QColor &color, int alpha)
{
    D3D9Locker locker(this);
    IDirect3DDevice9* dev = locker.Acquire();
    if (!dev)
        return;

    if (!m_rect_vertexbuffer)
    {
        HRESULT hr = dev->CreateVertexBuffer(
                sizeof(VERTEX)*4,     D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
                D3DFVF_VERTEX,        D3DPOOL_DEFAULT,
                &m_rect_vertexbuffer, NULL);

        if (FAILED(hr))
        {
            VERBOSE(VB_IMPORTANT, D3DERR + "Failed to create vertex buffer");
            return;
        }
    }

    EnableBlending(dev, true);
    SetTextureVertices(dev, false);
    MultiTexturing(dev, false);
    SetTexture(dev, NULL, 0);

    int alphamod = (int)(color.alpha() * (alpha / 255.0));
    D3DCOLOR clr = D3DCOLOR_ARGB(alphamod, color.red(),
                                 color.green(), color.blue());
    VERTEX *p_vertices;
    HRESULT hr = m_rect_vertexbuffer->Lock(0, 0, (VOID **)(&p_vertices),
                                           D3DLOCK_DISCARD);
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "Failed to lock vertex buffer.");
        return;
    }

    p_vertices[0].x       = (float)rect.left();
    p_vertices[0].y       = (float)rect.top();
    p_vertices[0].z       = 0.0f;
    p_vertices[0].diffuse = clr;
    p_vertices[0].rhw     = 1.0f;
    p_vertices[1].x       = (float)(rect.left() + rect.width());
    p_vertices[1].y       = (float)rect.top();
    p_vertices[1].z       = 0.0f;
    p_vertices[1].diffuse = clr;
    p_vertices[1].rhw     = 1.0f;
    p_vertices[2].x       = (float)(rect.left() + rect.width());
    p_vertices[2].y       = (float)(rect.top() + rect.height());
    p_vertices[2].z       = 0.0f;
    p_vertices[2].diffuse = clr;
    p_vertices[2].rhw     = 1.0f;
    p_vertices[3].x       = (float)rect.left();
    p_vertices[3].y       = (float)(rect.top() + rect.height());
    p_vertices[3].z       = 0.0f;
    p_vertices[3].diffuse = clr;
    p_vertices[3].rhw     = 1.0f;

    hr = m_rect_vertexbuffer->Unlock();
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "Failed to unlock vertex buffer");
        return;
    }

    hr = dev->SetStreamSource(0, m_rect_vertexbuffer,
                                      0, sizeof(VERTEX));
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "SetStreamSource() failed");
        return;
    }

    hr = dev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "DrawPrimitive() failed");
        return;
    }
}
Beispiel #14
0
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
	Application app("Okienko");

	// Inicjalizacja Direct3D
	IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);

	// Parametry urzadzenia
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferHeight = app.get_height();
	d3dpp.BackBufferWidth = app.get_width();
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;

	// Tworzenie urzadzenia
	IDirect3DDevice9* dev;
	d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, app.window_handle(),
		D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &dev);

	app.init_font(dev, "Courier New");

	dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);	// Brak obcinania scian
    dev->SetRenderState(D3DRS_LIGHTING, false);			// Brak swiatla

	// Inicjalizacja kamery
//	D3DXVECTOR3 eye(0, 5, -10);
    D3DXVECTOR3 target(0, 0, 0);
    D3DXVECTOR3 up(0, 1, 0);
    D3DXMATRIXA16 view;

    D3DXMATRIX mProjection;
	D3DXMatrixPerspectiveFovLH(&mProjection, D3DX_PI * 0.5f,  app.get_width()/(float)app.get_height(), 1, 50);
    dev->SetTransform(D3DTS_PROJECTION, &mProjection);

	// Model pudelka
	Vertex box[] = {
	//	  X   Y   Z  Color
		{ 1,  1,  1, D3DCOLOR_XRGB(255, 255, 255)},
		{-1,  1,  1, D3DCOLOR_XRGB(0, 255, 255)},
		{-1,  1, -1, D3DCOLOR_XRGB(0, 255, 0)},
		{ 1,  1, -1, D3DCOLOR_XRGB(255, 255, 0)},

		{ 1, -1,  1, D3DCOLOR_XRGB(255, 0, 255)},
		{-1, -1,  1, D3DCOLOR_XRGB(0, 0, 255)},
		{-1, -1, -1, D3DCOLOR_XRGB(0, 0, 0)},
		{ 1, -1, -1, D3DCOLOR_XRGB(255, 0, 0)},

		box[0], box[4], box[1], box[5], box[2], box[6], box[3], box[7], box[0], box[4]
	};

	int box_size = (16 + 2) * sizeof(Vertex);

	// Tworzenie bufora wierzcholkow
	IDirect3DVertexBuffer9* box_buffer;
	dev->CreateVertexBuffer(box_size, 0, Vertex_Format, D3DPOOL_MANAGED, &box_buffer, NULL);

	VOID* pVoid;
	box_buffer->Lock(0, box_size, (void**)&pVoid, 0);
	memcpy(pVoid, box, box_size);
	box_buffer->Unlock();

	dev->SetFVF(Vertex_Format);
	dev->SetStreamSource(0, box_buffer, 0, sizeof(Vertex));

	float radius = 3;
	while(app.running()){
		float alfa = app.get_alfa();
		float beta = app.get_beta();
		// Aktualizujemy kamere
		D3DXVECTOR3 eye(
			radius * cos(alfa) * sin(beta),
			radius * cos(beta),
			radius * sin(alfa) * sin(beta)
		);

		D3DXMatrixLookAtLH(&view, &eye, &target, &up);
		dev->SetTransform(D3DTS_VIEW, &view);

		// Rysujemy pudeleczko
		dev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
		dev->BeginScene();

		for(int i = 0; i < 2; i++) dev->DrawPrimitive(D3DPT_TRIANGLEFAN, i*4, 2);
		dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 8);

		app.print(10, 10, "Mysz X = %d", app.get_mouse_x());
		app.print(10, 24, "Mysz Y = %d", app.get_mouse_y());

		dev->EndScene();
		dev->Present(NULL, NULL, NULL, NULL);
	}

	// Zwalniamy zasoby
	box_buffer->Release();
	dev->Release();
	d3d->Release();
	return 0;
}
Beispiel #15
0
bool CSprite::Render(const SFloatPoint & _pos) const
{
	HRESULT hr;

	CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
	IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice();
	D3DXMATRIX matWorld, matTranslation;

	hr = pDevice->GetTransform(D3DTS_WORLD, &matWorld);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to get world transform", hr);
		return false;
	}

	D3DXMatrixTranslation(&matTranslation, _pos.m_fX, _pos.m_fY, 0.0f);
	hr = pDevice->MultiplyTransform(D3DTS_WORLD, &matTranslation);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to multiply world transform", hr);
		return false;
	}

	hr = pDevice->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(SFaceVertex));
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set stream source", hr);
		return false;
	}

	hr = pDevice->SetFVF(SFaceVertex::_fvf);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set FVF", hr);
		return false;
	}

	hr = pDevice->SetTexture(0, m_pTexture);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to set texture", hr);
		return false;
	}

	hr = pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to draw primitive", hr);
		return false;
	}

	hr = pDevice->SetTexture(0, NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to reset texture", hr);
		return false;
	}

	hr = pDevice->SetTransform(D3DTS_WORLD, &matWorld);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to restore world transform", hr);
		return false;
	}

	return true;
}