void DX9VB::create(int sizeInBytes, int stride, HDResourceMgr *pMgr)
{
    ASSERT(sizeInBytes > 0);
    ASSERT(stride > 0);
    ASSERT(pMgr);

    destroy();

    //
    DX9ResourceMgr* pDX9Mgr = (DX9ResourceMgr*)pMgr;
    IDirect3DDevice9* pDev = pDX9Mgr->getDX9Device();
    HRESULT hr;

    hr = pDev->CreateVertexBuffer(sizeInBytes,
                                  D3DUSAGE_WRITEONLY,	// usage
                                  0,	// FVF
                                  D3DPOOL_MANAGED,
                                  &m_pVB, NULL);

    if(FAILED(hr))
    {
        LOG("vertex buffer create failed, size = %d\r\n", sizeInBytes);
        throw HDAPIException("vertex buffer create failed.");
    }

    //
    m_sizeInBytes = sizeInBytes;
    m_stride = stride;
}
Beispiel #2
0
IDirect3DVertexBuffer9* MythRenderD3D9::CreateVertexBuffer(IDirect3DTexture9* texture)
{
    D3D9Locker locker(this);
    IDirect3DDevice9* dev = locker.Acquire();
    if (!dev)
        return NULL;

    if (texture && !m_textures.contains(texture))
        return false;

    IDirect3DVertexBuffer9* temp_vbuf = NULL;
    HRESULT hr = dev->CreateVertexBuffer(
        sizeof(TEXTUREVERTEX)*4, D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
        D3DFVF_TEXTUREVERTEX,    D3DPOOL_DEFAULT,
        &temp_vbuf,             NULL);

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

    m_vertexbuffers[temp_vbuf] = MythD3DVertexBuffer(texture);
    return temp_vbuf;
}
bool VertexBuffer::Create()
{
    Release();

    if (!vertexCount_ || !elementMask_)
        return true;

    if (graphics_)
    {
        if (graphics_->IsDeviceLost())
        {
            URHO3D_LOGWARNING("Vertex buffer creation while device is lost");
            return true;
        }

        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
        HRESULT hr = device->CreateVertexBuffer(
            vertexCount_ * vertexSize_,
            usage_,
            0,
            (D3DPOOL)pool_,
            (IDirect3DVertexBuffer9**)&object_,
            0);
        if (FAILED(hr))
        {
            URHO3D_SAFE_RELEASE(object_);
            URHO3D_LOGD3DERROR("Could not create vertex buffer", hr);
            return false;
        }
    }

    return true;
}
Beispiel #4
0
bool VertexBuffer::Create()
{
    Release();
    
    if (!vertexCount_ || !elementMask_)
        return true;
    
    if (graphics_)
    {
        if (graphics_->IsDeviceLost())
        {
            LOGWARNING("Vertex buffer creation while device is lost");
            return true;
        }
        
        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
        if (!device || FAILED(device->CreateVertexBuffer(
            vertexCount_ * vertexSize_,
            usage_,
            0,
            (D3DPOOL)pool_,
            (IDirect3DVertexBuffer9**)&object_,
            0)))
        {
            LOGERROR("Could not create vertex buffer");
            return false;
        }
    }
    
    return true;
}
Beispiel #5
0
bool CSprite::_CreateBuffer()
{
	const int iVertexCount = 6;
	const UINT bufferSize = sizeof(SFaceVertex) * iVertexCount;
	HRESULT hr;

	CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
	IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice();
	
	hr = pDevice->CreateVertexBuffer(bufferSize, 0, SFaceVertex::_fvf, D3DPOOL_DEFAULT, &m_pVertexBuffer, NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for image rectangle", hr);
		return false;
	}

	SFaceVertex *pVertices = NULL;
	hr = m_pVertexBuffer->Lock(0, bufferSize, (void**)&pVertices, 0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock image rectangle vertex buffer", hr);
		return false;
	}

	_FillRectVertices(pVertices);

	hr = m_pVertexBuffer->Unlock();
	if(FAILED(hr))
	{
		LogErrorHr("Failed to unlock image rectangle vertex buffer", hr);
		return false;
	}

	return true;
}
Beispiel #6
0
  bool GPUContextDX9::initialize()
  {
    _window = DX9Window::create();
    if( _window == NULL )
    {
      DX9WARN << "Could not create offscreen window.";
      return false;
    }

    HWND windowHandle = _window->getWindowHandle();

    _direct3D = Direct3DCreate9( D3D_SDK_VERSION );
    if( _direct3D == NULL )
    {
      DX9WARN << "Could not create Direct3D interface.";
      return false;
    }

    D3DPRESENT_PARAMETERS deviceDesc;
    ZeroMemory( &deviceDesc, sizeof(deviceDesc) );

    deviceDesc.Windowed = TRUE;
    deviceDesc.SwapEffect = D3DSWAPEFFECT_DISCARD;
    deviceDesc.BackBufferFormat = D3DFMT_UNKNOWN;
    deviceDesc.EnableAutoDepthStencil = FALSE;
    deviceDesc.AutoDepthStencilFormat = D3DFMT_D24S8;

    HRESULT result = _direct3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle,
      D3DCREATE_HARDWARE_VERTEXPROCESSING, &deviceDesc, &_device );
    if( FAILED(result) )
    {
      DX9WARN << "Could not create Direct3D device.";
      return false;
    }

    // create vertex buffer
    static const int kMaxVertexCount = 64;

    result = _device->CreateVertexBuffer(
      kMaxVertexCount*sizeof(DX9Vertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &_vertexBuffer, NULL );
    DX9AssertResult( result, "CreateVertexBuffer failed" );

    result = _device->CreateVertexDeclaration( kDX9VertexElements, &_vertexDecl );
    DX9AssertResult( result, "CreateVertexDeclaration failed" );


    // TIM: set up initial state
    result = _device->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
    GPUAssert( !FAILED(result), "SetRenderState failed" );

    _passthroughVertexShader = createVertexShader( kPassthroughVertexShaderSource );
    _passthroughPixelShader = createPixelShader( kPassthroughPixelShaderSource );

    for( size_t i = 0; i < kMaximumOutputCount; i++ )
      _boundOutputs[i] = NULL;
    for( size_t t = 0; t < kMaximumSamplerCount; t++ )
      _boundTextures[t] = NULL;

    return true;
  }
Beispiel #7
0
gl::Error Blit9::initialize()
{
    if (mGeometryLoaded)
    {
        return gl::Error(GL_NO_ERROR);
    }

    static const float quad[] =
    {
        -1, -1,
        -1,  1,
         1, -1,
         1,  1
    };

    IDirect3DDevice9 *device = mRenderer->getDevice();

    HRESULT result = device->CreateVertexBuffer(sizeof(quad), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mQuadVertexBuffer, NULL);

    if (FAILED(result))
    {
        ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
        return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal blit vertex shader, result: 0x%X.", result);
    }

    void *lockPtr = NULL;
    result = mQuadVertexBuffer->Lock(0, 0, &lockPtr, 0);

    if (FAILED(result) || lockPtr == NULL)
    {
        ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
        SafeRelease(mQuadVertexBuffer);
        return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal blit vertex shader, result: 0x%X.", result);
    }

    memcpy(lockPtr, quad, sizeof(quad));
    mQuadVertexBuffer->Unlock();

    static const D3DVERTEXELEMENT9 elements[] =
    {
        { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
        D3DDECL_END()
    };

    result = device->CreateVertexDeclaration(elements, &mQuadVertexDeclaration);

    if (FAILED(result))
    {
        ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
        SafeRelease(mQuadVertexBuffer);
        return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal blit vertex declaration, result: 0x%X.", result);
    }

    mGeometryLoaded = true;
    return gl::Error(GL_NO_ERROR);
}
//----------------------------------------------------------------------------
PdrVertexBuffer::PdrVertexBuffer (Renderer* renderer,
    const VertexBuffer* vbuffer)
{
    IDirect3DDevice9* device = renderer->mData->mDevice;

    UINT numBytes = (UINT)vbuffer->GetNumBytes();
    DWORD usage = gDX9BufferUsage[vbuffer->GetUsage()];
    HRESULT hr = device->CreateVertexBuffer(numBytes, usage, 0,
        D3DPOOL_DEFAULT, &mBuffer, 0);
    WM5_UNUSED(hr);
    assertion(hr == D3D_OK, "Failed to create vertex buffer: %s\n",
        DXGetErrorString(hr));

    void* data = Lock(Buffer::BL_WRITE_ONLY);
    memcpy(data, vbuffer->GetData(), vbuffer->GetNumBytes());
    Unlock();
}
Beispiel #9
0
void Blit::initGeometry()
{
    static const float quad[] =
    {
        -1, -1,
        -1,  1,
        1, -1,
        1,  1
    };

    IDirect3DDevice9 *device = getDevice();

    HRESULT result = device->CreateVertexBuffer(sizeof(quad), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mQuadVertexBuffer, NULL);

    if (FAILED(result))
    {
        ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
        return error(GL_OUT_OF_MEMORY);
    }

    void *lockPtr = NULL;
    result = mQuadVertexBuffer->Lock(0, 0, &lockPtr, 0);

    if (FAILED(result) || lockPtr == NULL)
    {
        ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
        return error(GL_OUT_OF_MEMORY);
    }

    memcpy(lockPtr, quad, sizeof(quad));
    mQuadVertexBuffer->Unlock();

    static const D3DVERTEXELEMENT9 elements[] =
    {
        { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
        D3DDECL_END()
    };

    result = device->CreateVertexDeclaration(elements, &mQuadVertexDeclaration);

    if (FAILED(result))
    {
        ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
        return error(GL_OUT_OF_MEMORY);
    }
}
Beispiel #10
0
f2dGraphics2DImpl::f2dGraphics2DImpl(f2dRenderDeviceImpl* pParent, fuInt VertexBufferCount, fuInt IndexBufferCount)
	: f2dGraphicsImpl(pParent),
	m_pVB(NULL), m_pIB(NULL),
	m_VBMaxCount(VertexBufferCount), m_IBMaxCount(IndexBufferCount),
	m_VBUsedCount(0), m_IBUsedCount(0), m_VBAlloced(0), m_IBAlloced(0),
	m_pVBData(NULL), m_pIBData(NULL),
	m_ColorBlendType(F2DGRAPH2DBLENDTYPE_ADD)
{
	// 设置默认的投影矩阵
	SetProjTransform(fcyMatrix4::GetOrthoOffCenterLH(
		0.f, 
		(float)pParent->GetBufferWidth(), 
		(float)pParent->GetBufferHeight(), 
		0.f, 0.f, 100.f
		));

	// 创建缓存
	HRESULT tHR;
	IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle();

	if(FAILED(tHR = pDev->CreateVertexBuffer(
		m_VBMaxCount * sizeof(f2dGraphics2DVertex),
		D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		FVF,
		D3DPOOL_DEFAULT,
		&m_pVB,
		NULL)))
	{
		throw fcyWin32COMException("f2dGraphics2DImpl::f2dGraphics2DImpl", "IDirect3DDevice9::CreateVertexBuffer Failed.", tHR);
	}
	if(FAILED(tHR = pDev->CreateIndexBuffer(
		m_IBMaxCount * sizeof(fuShort),
		D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16,
		D3DPOOL_DEFAULT, 
		&m_pIB,
		NULL)))
	{
		FCYSAFEKILL(m_pVB);
		throw fcyWin32COMException("f2dGraphics2DImpl::f2dGraphics2DImpl", "IDirect3DDevice9::CreateIndexBuffer Failed.", tHR);
	}

	// 注册监听器
	m_pParent->AttachListener(this);
}
Beispiel #11
0
void f2dGraphics2DImpl::OnRenderDeviceReset()
{
	IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle();

	pDev->CreateVertexBuffer(
		m_VBMaxCount * sizeof(f2dGraphics2DVertex),
		D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		FVF,
		D3DPOOL_DEFAULT,
		&m_pVB,
		NULL);
	pDev->CreateIndexBuffer(
		m_IBMaxCount * sizeof(fuShort), 
		D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16, 
		D3DPOOL_DEFAULT,
		&m_pIB,
		NULL);
}
Beispiel #12
0
sge::d3d9::vertex::d3d_buffer_unique_ptr
sge::d3d9::devicefuncs::create_vertex_buffer(
	IDirect3DDevice9 &_device,
	sge::renderer::size_type const _size,
	D3DPOOL const _pool,
	sge::d3d9::usage const _usage
)
{
	IDirect3DVertexBuffer9 *ret;

	if(
		_device.CreateVertexBuffer(
			fcppt::cast::size<
				UINT
			>(
				_size
				
			),
			_usage.get(),
			0, // no FVF
			_pool,
			&ret,
			nullptr
		)
		!= D3D_OK
	)
		throw 
			sge::renderer::exception{
				FCPPT_TEXT("Cannot create vertex buffer!")
			};

	return
		sge::d3d9::vertex::d3d_buffer_unique_ptr(
			ret
		);
}
bool VertexBuffer::Create()
{
    Release();

    if (!vertexCount_ || elements_.Empty())
        return true;

    if (graphics_)
    {
        if (graphics_->IsDeviceLost())
        {
            ATOMIC_LOGWARNING("Vertex buffer creation while device is lost");
            return true;
        }

        unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
        unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;

        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
        HRESULT hr = device->CreateVertexBuffer(
            vertexCount_ * vertexSize_,
            d3dUsage,
            0,
            (D3DPOOL)pool,
            (IDirect3DVertexBuffer9**)&object_.ptr_,
            0);
        if (FAILED(hr))
        {
            ATOMIC_SAFE_RELEASE(object_.ptr_);
            ATOMIC_LOGD3DERROR("Could not create vertex buffer", hr);
            return false;
        }
    }

    return true;
}
Beispiel #14
0
bool CBasicObjects::_FillBoxVBNormal()
{
	HRESULT hr;
	const int iTriangleCount = 2 * 6;
	SNormalVertex boxCorners[2][2][2];
	SNormalVertex boxTriangles[iTriangleCount * 3];

	memset(boxCorners, 0, sizeof(boxCorners));
	memset(boxTriangles, 0, sizeof(boxTriangles));

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

	int iX, iY, iZ;

	// fill corners
	for(iX = 0; iX < 2; iX++)
	{
		for(iY = 0; iY < 2; iY++)
		{
			for(iZ = 0; iZ < 2; iZ++)
			{
				boxCorners[iX][iY][iZ].x = (float)iX;
				boxCorners[iX][iY][iZ].y = (float)iY;
				boxCorners[iX][iY][iZ].z = (float)iZ;
			}
		}
	}

	SNormalVertex * pBoxPoint = boxTriangles;

	// fill triangles
	// bottom
	*pBoxPoint = boxCorners[0][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
	_SetPrevFaceNormals(pBoxPoint, 0.0f, 0.0f, -1.0f);

	// back
	*pBoxPoint = boxCorners[0][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
	_SetPrevFaceNormals(pBoxPoint, 0.0f, -1.0f, 0.0f);

	// left
	*pBoxPoint = boxCorners[0][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
	_SetPrevFaceNormals(pBoxPoint, -1.0f, 0.0f, 0.0f);

	// front
	*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
	_SetPrevFaceNormals(pBoxPoint, 0.0f, 1.0f, 0.0f);

	// right
	*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
	_SetPrevFaceNormals(pBoxPoint, 1.0f, 0.0f, 0.0f);

	// top
	*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
	*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
	_SetPrevFaceNormals(pBoxPoint, 0.0f, 0.0f, 1.0f);

	if(m_pNormalBox != NULL)
	{
		LogError("Expected normal box VB to be NULL");
		return false;
	}

	hr = pDevice->CreateVertexBuffer(sizeof(boxTriangles), 0, SNormalVertex::_fvf, D3DPOOL_DEFAULT, &m_pNormalBox,
		NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for normal box", hr);
		return false;
	}

	VOID * pDevBox = NULL;
	hr = m_pNormalBox->Lock(0, sizeof(boxTriangles), (void**)&pDevBox, 0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for normal box", hr);
		return false;
	}

	memcpy(pDevBox, boxTriangles, sizeof(boxTriangles));
	hr = m_pNormalBox->Unlock();
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for normal box", hr);
		return false;
	}

	return true;
}
Beispiel #15
0
void NX::Sphere::CreateTriangles() {
	int nV = (m_iStacks - 1) * (m_iSlices + 1) + 2, r, c;
	int nI = (m_iStacks - 2) * (m_iSlices + 1) * 2 + (m_iSlices + 2) * 2;
	float rr = kfPiOver2, rc, dr = kfPi / m_iStacks, dc = kf2Pi / m_iSlices;
	float sr, cr, sc, cc;
	IDirect3DDevice9 *pDevice = glb_GetD3DDevice();
	m_pVertexs = new Vertex[nV];
	{//calculate vertex data 
		Vertex *pVertex = m_pVertexs;
		*pVertex++ = { 0.f, m_fRadius, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f };
		for (r = 1; r < m_iStacks; ++r) {
			rr -= dr;
			rc = 0.f;
			cr = std::cosf(rr), sr = std::sinf(rr);
			for (c = 0; c <= m_iSlices; ++c) {
				sc = std::sinf(rc);
				cc = std::cosf(rc);
				*pVertex++ = { m_fRadius * cr * cc, m_fRadius * sr, m_fRadius * cr * sc, c * 1.f / m_iSlices, r * 1.f / m_iStacks,  cr * cc, sr, cr * sc };
				rc += dc;
			}
		}
		*pVertex = { 0.f, -m_fRadius, 0.f, 0.f, 1.f, 0.f, -1.f, 0.f };
		pDevice->CreateVertexBuffer(sizeof(Vertex) * nV, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_pVertexBuffer, nullptr);

		void *pBase = nullptr;
		m_pVertexBuffer->Lock(0, 0, &pBase, D3DLOCK_DISCARD);
		memcpy(pBase, m_pVertexs, sizeof(Vertex) * nV);
		m_pVertexBuffer->Unlock();
	}


	{//vertex desc
		D3DVERTEXELEMENT9 VertexDesc[] = {
			{ 0, CLS_MEM_OFFSET(Vertex, x), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
			{ 0, CLS_MEM_OFFSET(Vertex, u), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
			{ 0, CLS_MEM_OFFSET(Vertex,nx), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 },
			D3DDECL_END(),
		};
		pDevice->CreateVertexDeclaration(VertexDesc, &m_pVertexDesc);
	}

	{//calculate index data
		pDevice->CreateIndexBuffer(nI * sizeof(int), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &m_pIndexBuffer, nullptr);
		int *pBase = nullptr;
		m_pIndexBuffer->Lock(0, 0, (void**)&pBase, D3DLOCK_DISCARD);
		for (int i = 0; i <= m_iSlices + 1; ++i) {//first stack, triangle_fan
			*pBase++ = i;
		}
		int a = 1;
		for (int i = 1; i < m_iStacks - 1; ++i) {//inner stacks, triangle_list
			for (int j = 0; j <= m_iSlices; ++j) {
				*pBase++ = a;
				*pBase++ = a + m_iSlices + 1;
				++a;
			}
		}

		*pBase++ = (m_iStacks - 1) * (m_iSlices + 1) + 1;
		for (int i = 0; i <= m_iSlices; ++i) {
			*pBase++ = (m_iStacks - 2) * (m_iSlices + 1) + 1 + i;
		}

		m_pIndexBuffer->Unlock();
	}
}
Beispiel #16
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 #17
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;
}
    void CFullscreenTriangleDrawer::CreateDX9Resources()
    {
        HRESULT hr = S_OK;

        float VertexData[] =
        {
            -1.0f,  1.0f, 0.0f, 0.0f, 0.0f,
            3.0f,  1.0f, 0.0f, 2.0f, 0.0f,
            -1.0f, -3.0f, 0.0f, 0.0f, 2.0f,
        };

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

        // Vertex buffer
        hr = pDevice->CreateVertexBuffer( sizeof( VertexData ), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_pVertexBuffer, NULL );
        CRY_ASSERT( SUCCEEDED( hr ) );

        float* pVertexBuffer = NULL;
        hr = m_pVertexBuffer->Lock( 0, 0, ( void** )&pVertexBuffer, 0 );
        CRY_ASSERT( SUCCEEDED( hr ) );
        memcpy( pVertexBuffer, VertexData, sizeof( VertexData ) );
        m_pVertexBuffer->Unlock();

        // Vertex declaration
        D3DVERTEXELEMENT9 VertexElements[] =
        {
            {0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
            {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
            D3DDECL_END()
        };
        hr = pDevice->CreateVertexDeclaration( VertexElements, &m_pVertexDeclaration );
        CRY_ASSERT( SUCCEEDED( hr ) );

        // Vertex shader

        /*
        // FSTriangle.vs
        // fxc /O2 /T vs_2_0 /E VSMain
        float Width : register(c0);
        float Height : register(c1);

        struct VertexPT
        {
            float4 PositionL : POSITION0;
            float2 TexCoord  : TEXCOORD0;
        };

        VertexPT VSMain(VertexPT vsIn)
        {
            vsIn.PositionL += float4(-0.5 / Width, 0.5 / Height, 0, 0);
            return vsIn;
        }
        */

        const char CompiledVS[] =
        {
            0x00, 0x02, 0xfe, 0xff, 0xfe, 0xff, 0x28, 0x00, 0x43, 0x54, 0x41, 0x42,
            0x1c, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff,
            0x02, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00,
            0x62, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,
            0x01, 0x00, 0x06, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x5c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
            0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x65, 0x69, 0x67,
            0x68, 0x74, 0x00, 0xab, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00,
            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x69, 0x64, 0x74,
            0x68, 0x00, 0x76, 0x73, 0x5f, 0x32, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63,
            0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48,
            0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43,
            0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, 0x32, 0x39,
            0x2e, 0x39, 0x35, 0x32, 0x2e, 0x33, 0x31, 0x31, 0x31, 0x00, 0xab, 0xab,
            0x51, 0x00, 0x00, 0x05, 0x02, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x00, 0xbf,
            0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90,
            0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0x90,
            0x06, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0xa0,
            0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80,
            0x02, 0x00, 0x00, 0xa0, 0x06, 0x00, 0x00, 0x02, 0x01, 0x00, 0x01, 0x80,
            0x01, 0x00, 0x00, 0xa0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x80,
            0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x55, 0xa0, 0x01, 0x00, 0x00, 0x02,
            0x00, 0x00, 0x0c, 0x80, 0x02, 0x00, 0xaa, 0xa0, 0x02, 0x00, 0x00, 0x03,
            0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90,
            0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x03, 0xe0, 0x01, 0x00, 0xe4, 0x90,
            0xff, 0xff, 0x00, 0x00,
        };

        hr = pDevice->CreateVertexShader( ( DWORD* )CompiledVS, &m_pVertexShader9 );
        CRY_ASSERT( SUCCEEDED( hr ) );

        // Pixel shader

        /*
        // FSTriangle.ps
        // fxc /O2 /T ps_2_0 /E PSMain
        texture Texture : register(s0);

        sampler PointSampler = sampler_state
        {
            Texture = <Texture>;
            MinFilter = Point;
            MagFilter = Point;
            MipFilter = Point;
            MaxAnisotropy = 1;
            AddressU  = CLAMP;
            AddressV  = CLAMP;
        };

        struct VertexPT
        {
            float4 PositionL : POSITION0;
            float2 TexCoord  : TEXCOORD0;
        };

        float4 PSMain(VertexPT psIn) : COLOR
        {
            return tex2D(PointSampler, psIn.TexCoord);
        }

        */

        const char CompiledPS[] =
        {
            0x00, 0x02, 0xff, 0xff, 0xfe, 0xff, 0x23, 0x00, 0x43, 0x54, 0x41, 0x42,
            0x1c, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff,
            0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00,
            0x50, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
            0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x50, 0x6f, 0x69, 0x6e, 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72,
            0x00, 0xab, 0xab, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00,
            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x32,
            0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74,
            0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68,
            0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65,
            0x72, 0x20, 0x39, 0x2e, 0x32, 0x39, 0x2e, 0x39, 0x35, 0x32, 0x2e, 0x33,
            0x31, 0x31, 0x31, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80,
            0x00, 0x00, 0x03, 0xb0, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90,
            0x00, 0x08, 0x0f, 0xa0, 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80,
            0x00, 0x00, 0xe4, 0xb0, 0x00, 0x08, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02,
            0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0xff, 0xff, 0x00, 0x00,
        };
        hr = pDevice->CreatePixelShader( ( DWORD* )CompiledPS, &m_pPixelShader9 );
        CRY_ASSERT( SUCCEEDED( hr ) );

        hr = pDevice->CreateStateBlock( D3DSBT_ALL, &m_pStateBlock );
        CRY_ASSERT( SUCCEEDED( hr ) );
    }
void CShowPoints9::SetMesh(LPD3DXMESH pNewMesh, LPD3DXSKININFO pNewSkin)
{
    HRESULT hr = S_OK;

    NumPoints = 0;
    
    UnskinnedVB.resize(0);
    SAFE_RELEASE(SkinnedVB);
    SAFE_RELEASE(Skin);

    if(pNewMesh == NULL)
        return;

    IDirect3DDevice9* device = DXUTGetD3D9Device();

    {//EFFECT
     V( device->CreateVertexDeclaration( Elements, &Declaration ) );

     ID3DXBuffer* pErrors = NULL;
     V( SASCreateEffectFromResource(
             device, 
             NULL, MAKEINTRESOURCE(IDR_SHOWLINES9FX), MAKEINTRESOURCE(RT_RCDATA),
             NULL, 
             NULL, 
             0,
             NULL, 
             &Effect, 
             &pErrors));
    if(pErrors)
         DXVGetApp().OutputA( (const char*)pErrors->GetBufferPointer() );
    SAFE_RELEASE(pErrors);

    }//EFFECT



    D3DVERTEXELEMENT9 declIn[ MAX_FVF_DECL_SIZE ];
    V( pNewMesh->GetDeclaration(declIn) );

    int iPos= -1;
    int iNorm= -1;
    for( int i = 0 ; 
        declIn[i].Stream != 255 && i < MAX_FVF_DECL_SIZE;
        i++)
    {
        if(declIn[i].Usage == D3DDECLUSAGE_POSITION && declIn[i].UsageIndex == 0)
            iPos = i;
        if(declIn[i].Usage == D3DDECLUSAGE_NORMAL && declIn[i].UsageIndex == 0)
            iNorm = i;
    }

    if(iPos == -1 || iNorm == -1)
        return;

    if( (( declIn[iPos].Type & (D3DDECLTYPE_FLOAT3|D3DDECLTYPE_FLOAT4)) == 0  ) ||
        (( declIn[iNorm].Type & (D3DDECLTYPE_FLOAT3|D3DDECLTYPE_FLOAT4)) == 0  ) )
        return;

    NumPoints = pNewMesh->GetNumVertices();

    int MeshStride = pNewMesh->GetNumBytesPerVertex();


    if(pNewSkin)
    {
        V( pNewSkin->Clone( &Skin ) ); 
        V( Skin->SetDeclaration(Elements) );
    }


    //GET VERTEX DATA

    BYTE* pSrcVB= NULL;
    V(  pNewMesh->LockVertexBuffer( D3DLOCK_READONLY, (LPVOID*)&pSrcVB ) );
    UnskinnedVB.resize(pNewMesh->GetNumVertices());
    for( DWORD iVert = 0; iVert < pNewMesh->GetNumVertices(); iVert++)
    {
        Vertex& v0 = UnskinnedVB[iVert];

        v0.Position = *(D3DXVECTOR3*) (pSrcVB+(MeshStride*iVert)+declIn[iPos].Offset);
    }
    V( pNewMesh->UnlockVertexBuffer() );

    V( device->CreateVertexBuffer( NumPoints*Stride , D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &SkinnedVB, NULL) );
    //Fill in with initial values so unskinned meshes do not have to do this every render.
    pSrcVB=(BYTE*)(void*)&UnskinnedVB.front();
    BYTE* pDstVB=NULL;
    V( SkinnedVB->Lock(0, 0, (void**)&pDstVB, 0 ) );
    {
        memcpy( pDstVB, pSrcVB, Stride*pNewMesh->GetNumVertices() );
    }
    V( SkinnedVB->Unlock() );
}
Beispiel #20
0
bool CBasicObjects::_FillRectVB()
{
	HRESULT hr;
	DWORD dwColor = 0xff00ff00;

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

	SFaceVertex corners[3 * 2];
	memset(corners, 0, sizeof(corners));

	SFaceVertex baseCorners[4];
	memset(baseCorners, 0, sizeof(baseCorners));

	// lower left
	baseCorners[0].x = 0.0f;
	baseCorners[0].y = 0.0f;
	baseCorners[0].z = 0.0f;
	baseCorners[0].tu = 0.0f;
	baseCorners[0].tv = 1.0f;

	// upper left
	baseCorners[1].x = 0.0f;
	baseCorners[1].y = 1.0f;
	baseCorners[1].z = 0.0f;
	baseCorners[1].tu = 0.0f;
	baseCorners[1].tv = 0.0f;

	// upper left
	baseCorners[2].x = 1.0f;
	baseCorners[2].y = 1.0f;
	baseCorners[2].z = 0.0f;
	baseCorners[2].tu = 1.0f;
	baseCorners[2].tv = 0.0f;

	// lower right
	baseCorners[3].x = 1.0f;
	baseCorners[3].y = 0.0f;
	baseCorners[3].z = 0.0f;
	baseCorners[3].tu = 1.0f;
	baseCorners[3].tv = 1.0f;

	corners[0] = baseCorners[0];
	corners[1] = baseCorners[1];
	corners[2] = baseCorners[2];
	corners[3] = baseCorners[2];
	corners[4] = baseCorners[3];
	corners[5] = baseCorners[0];

	if(m_pRectVB != NULL)
	{
		LogError("Expected rect VB to be NULL");
		return false;
	}

	hr = pDevice->CreateVertexBuffer(sizeof(corners), 0, SFaceVertex::_fvf, D3DPOOL_DEFAULT, &m_pRectVB, NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for rect", hr);
		return false;
	}

	VOID * pDevRect = NULL;
	hr = m_pRectVB->Lock(0, sizeof(corners), (void**)&pDevRect, 0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock vertex buffer for rect", hr);
		return false;
	}

	memcpy(pDevRect, corners, sizeof(corners));

	hr = m_pRectVB->Unlock();
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock vertex buffer for rect", hr);
		return false;
	}

	return true;
}
Beispiel #21
0
bool CBasicObjects::_FillPolesVB()
{
	HRESULT hr;
	const int iPoleCount = (g_iGridSize + 1) * (g_iGridSize + 1);
	DWORD dwColor = 0xff00ff00;

	SLineVertex lines[2 * iPoleCount];
	memset(lines, 0, sizeof(lines));

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

	float fCoorMax = ((float)g_iGridSize) / 2.0f;

	for(int iX = 0; iX <= g_iGridSize; iX++)
	{
		for(int iY = 0; iY <= g_iGridSize; iY++)
		{
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 0].x = -fCoorMax + (float)iX;
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 0].y = -fCoorMax + (float)iY;
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 0].z = 0.0f;
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 0].color = dwColor;

			lines[2 * (iX + iY * (g_iGridSize + 1)) + 1].x = -fCoorMax + (float)iX;
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 1].y = -fCoorMax + (float)iY;
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 1].z = 1.0f;
			lines[2 * (iX + iY * (g_iGridSize + 1)) + 1].color = dwColor;
		}
	}

	if(m_pPolesVB != NULL)
	{
		LogError("Expected Box VB to be NULL");
		return false;
	}

	hr = pDevice->CreateVertexBuffer(sizeof(lines), 0, SLineVertex::_fvf, D3DPOOL_DEFAULT, &m_pPolesVB, NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for poles", hr);
		return false;
	}

	VOID * pDevPoles = NULL;
	hr = m_pPolesVB->Lock(0, sizeof(lines), (void**)&pDevPoles, 0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock vertex buffer for poles", hr);
		return false;
	}

	memcpy(pDevPoles, lines, sizeof(lines));

	hr = m_pPolesVB->Unlock();
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock vertex buffer for poles", hr);
		return false;
	}

	return true;
}
Beispiel #22
0
bool CBasicObjects::_FillGridVB()
{
	HRESULT hr;

	SLineVertex lines[(g_iGridSize + 1) * 2 * 2];
	memset(lines, 0, sizeof(lines));
	const float fGridStart = ((float)g_iGridSize) / 2.0f;
	const float fGridSize = (float)g_iGridSize;

	DWORD dwGridColor = 0xff0000ff;

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

	for(int iGridLineIndex = 0; iGridLineIndex <= g_iGridSize; iGridLineIndex++)
	{
		// parallel to y axis
		lines[4 * iGridLineIndex + 0].x = -fGridStart + (float)(iGridLineIndex);
		lines[4 * iGridLineIndex + 0].y = -fGridStart;
		lines[4 * iGridLineIndex + 0].color = dwGridColor;

		lines[4 * iGridLineIndex + 1].x = -fGridStart + (float)(iGridLineIndex);
		lines[4 * iGridLineIndex + 1].y =  fGridStart;
		lines[4 * iGridLineIndex + 1].color = dwGridColor;

		// parallel to x axis
		lines[4 * iGridLineIndex + 2].x = -fGridStart;
		lines[4 * iGridLineIndex + 2].y = -fGridStart + (float)(iGridLineIndex);
		lines[4 * iGridLineIndex + 2].color = dwGridColor;

		lines[4 * iGridLineIndex + 3].x =  fGridStart;
		lines[4 * iGridLineIndex + 3].y = -fGridStart + (float)(iGridLineIndex);
		lines[4 * iGridLineIndex + 3].color = dwGridColor;
	}

	if(m_pGridVB != NULL)
	{
		LogError("Expected Box VB to be NULL");
		return false;
	}

	hr = pDevice->CreateVertexBuffer(sizeof(lines), 0, SLineVertex::_fvf, D3DPOOL_DEFAULT, &m_pGridVB, NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create vertex buffer for grid", hr);
		return false;
	}

	VOID * pDevGrid = NULL;
	hr = m_pGridVB->Lock(0, sizeof(lines), (void**)&pDevGrid, 0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock vertex buffer for grid", hr);
		return false;
	}

	memcpy(pDevGrid, lines, sizeof(lines));
	hr = m_pGridVB->Unlock();
	if(FAILED(hr))
	{
		LogErrorHr("Failed to unlock vertex buffer for grid", hr);
		return false;
	}

	return true;
}