//---------------------------------------------------------------------
    D3D9HardwareIndexBuffer::D3D9HardwareIndexBuffer(HardwareIndexBuffer::IndexType idxType, 
        size_t numIndexes, HardwareBuffer::Usage usage, LPDIRECT3DDEVICE9 pDev, 
        bool useSystemMemory, bool useShadowBuffer)
        : HardwareIndexBuffer(idxType, numIndexes, usage, useSystemMemory, useShadowBuffer)
    {
#if OGRE_D3D_MANAGE_BUFFERS
		mD3DPool = useSystemMemory? D3DPOOL_SYSTEMMEM : 
			// If not system mem, use managed pool UNLESS buffer is discardable
			// if discardable, keeping the software backing is expensive
			(usage & HardwareBuffer::HBU_DISCARDABLE)? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
#else
		mD3DPool = useSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
#endif
        // Create the Index buffer
        HRESULT hr = pDev->CreateIndexBuffer(
            static_cast<UINT>(mSizeInBytes),
            D3D9Mappings::get(mUsage),
            D3D9Mappings::get(mIndexType),
			mD3DPool,
            &mlpD3DBuffer,
            NULL
            );
            
        if (FAILED(hr))
        {
			String msg = DXGetErrorDescription9(hr);
            OGRE_EXCEPT(hr, "Cannot create D3D9 Index buffer: " + msg, 
                "D3D9HardwareIndexBuffer::D3D9HardwareIndexBuffer");
        }

    }
	//---------------------------------------------------------------------
	bool D3D9HardwareIndexBuffer::recreateIfDefaultPool(LPDIRECT3DDEVICE9 pDev)
	{
		if (mD3DPool == D3DPOOL_DEFAULT)
		{
			// Create the Index buffer
			HRESULT hr = pDev->CreateIndexBuffer(
				static_cast<UINT>(mSizeInBytes),
				D3D9Mappings::get(mUsage),
				D3D9Mappings::get(mIndexType),
				mD3DPool,
				&mlpD3DBuffer,
				NULL
				);

			if (FAILED(hr))
			{
				String msg = DXGetErrorDescription9(hr);
				OGRE_EXCEPT(hr, "Cannot create D3D9 Index buffer: " + msg, 
					"D3D9HardwareIndexBuffer::D3D9HardwareIndexBuffer");
			}

			return true;
		}
		return false;
	}
Пример #3
0
//--------------------------------------------------------------------------------------------------------------
//解锁纹理
void D3D9CubeTexture::UnlockRect( CubeFace eFace, UINT nLevel )
{
    HRESULT result = reinterpret_cast< IDirect3DCubeTexture9* >( mpD3D9Texture )->UnlockRect(
                         (D3DCUBEMAP_FACES)eFace, nLevel );

    if( FAILED( result ) )
        Except( Exception::ERR_INVALIDPARAMS, (String)"解锁 Direct3D 9 立方纹理错误。\nD3D9 错误描述:" +
                DXGetErrorDescription9(result) );
}
  void EnableDrawing (HGLRC *hRC)
  {
    WindowResizedCallback = &WindowResized;
    
    d3dmgr = new ContextManager();
    HRESULT hr;
    
    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information
    d3dobj = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface
    D3DFORMAT format = D3DFMT_A8R8G8B8; //For simplicity we'll hard-code this for now.
    
    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    int ww = window_get_width(),
        wh = window_get_height();
		d3dpp.BackBufferWidth = ww <= 0 ? 1 : ww;
		d3dpp.BackBufferHeight = wh <= 0 ? 1 : wh;
    d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; // 0 Levels of multi-sampling
    d3dpp.MultiSampleQuality = 0;                //No multi-sampling
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;  // Throw away previous frames, we don't need them
    d3dpp.hDeviceWindow = hWnd;  // This is our main (and only) window
    d3dpp.Flags = NULL;            // No flags to set
    d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;   //Present the frame immediately
    d3dpp.BackBufferCount = 1;  //We only need a single back buffer
    d3dpp.BackBufferFormat = format;      //Display format
    d3dpp.EnableAutoDepthStencil = TRUE; // Automatic depth stencil buffer
    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; //32-bit zbuffer 24bits for depth 8 for stencil buffer
    // create a device class using this information and information from the d3dpp stuct
    DWORD behaviors = D3DCREATE_MIXED_VERTEXPROCESSING;
    if (forceSoftwareVertexProcessing) {
      behaviors = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
    }
    hr = d3dobj->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      behaviors,
                      &d3dpp,
                      &d3dmgr->device);
    if (FAILED(hr)) {
      MessageBox(hWnd,
               "Failed to create Direct3D 9.0 Device",
         DXGetErrorDescription9(hr), //DXGetErrorString9(hr)
               MB_ICONERROR | MB_OK);
         return; // should probably force the game closed
    }
		
		d3dmgr->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE); 
		
		enigma_user::display_aa = 0;
		for (int i = 16; i > 1; i--) {
			if (SUCCEEDED(d3dobj->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, format, TRUE, (D3DMULTISAMPLE_TYPE)((int)D3DMULTISAMPLE_NONE + i), NULL))) {
				enigma_user::display_aa += i;
			}
		}
		
  }
Пример #5
0
//--------------------------------------------------------------------------------------------------------------
//初始化键盘输入设备
void DI8InputSystem::InitializeKeyboard( HWND hWnd, bool bExclusive )
{
    //创建键盘设备
    HRESULT result = mpDirectInput8->CreateDevice( GUID_SysKeyboard, &mpDI8Keyboard, NULL );
    if( FAILED( result ) )
        Except( Exception::ERR_INTERNAL_ERROR, (String)"创建 DirectInput8 键盘设备错误!"
                "\nDX 错误描述:" + DXGetErrorDescription9( result ) );

    //设置键盘数据格式
    result = mpDI8Keyboard->SetDataFormat( &c_dfDIKeyboard );
    if( FAILED( result ) )
        Except( Exception::ERR_INTERNAL_ERROR, (String)"设置 DirectInput8 键盘设备数据格式错误!"
                "\nDX 错误描述:" + DXGetErrorDescription9( result ) );

    //设置键盘协作等级
    DWORD flag = bExclusive ? ( DISCL_FOREGROUND | DISCL_EXCLUSIVE ) : ( DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );

    result = mpDI8Keyboard->SetCooperativeLevel( hWnd, flag );
    if( FAILED( result ) )
        Except( Exception::ERR_INTERNAL_ERROR, (String)"设置 DirectInput8 键盘设备协作等级错误!"
                "\nDX 错误描述:" + DXGetErrorDescription9( result ) );

    //设置缓存模式键盘
    DIPROPDWORD dipdw;
    dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    dipdw.diph.dwObj        = 0;
    dipdw.diph.dwHow        = DIPH_DEVICE;
    dipdw.dwData            = DI8_KEY_BUF_SIZE;

    result = mpDI8Keyboard->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
    if( FAILED( result ) )
        Except( Exception::ERR_INTERNAL_ERROR, (String)"设置 DirectInput8 键盘设备数据缓存模式错误!"
                "\nDX 错误描述:" + DXGetErrorDescription9( result ) );

    //获取键盘
    mpDI8Keyboard->Acquire();

    mbEnableKeyboard = true;
}
Пример #6
0
void LcD3D_GetDxError(HRESULT hr, char* pBufferPointer)
{
	char* s = (char*) malloc(2048);

	if(pBufferPointer)
	{
		sprintf(s
			,	"File:%s\n"
				"Error Line:%d\n"
				"Error Msg: %s\n"
				"Error Desc:%s\n"
				"Error Pointer: %s\n"
				,	__FILE__
				,	__LINE__
				,	DXGetErrorString9(hr)
				,	DXGetErrorDescription9(hr)
				,	pBufferPointer );
	}

	else
	{
		sprintf(s
			,	"File:%s\n"
				"Error Line:%d\n"
				"Error Msg: %s\n"
				"Error Desc:%s\n"
				,	__FILE__
				,	__LINE__
				,	DXGetErrorString9(hr)
				,	DXGetErrorDescription9(hr));

	}

	OutputDebugString( s );
	MessageBox(0, s, "Err", MB_OK | MB_ICONERROR);
	free(s);
}
Пример #7
0
/**************************************************************************
	Error: msg
	Code: hr
	Description: desc(hr)
**************************************************************************/
void cLog::Error(HRESULT hr, char *msg)
{
	FILE *f;
	char s[256];

	ZeroMemory(s,sizeof(s));

	sprintf(s,"Error: %s\n",msg);
	sprintf(s,"%sCode: %s\n",s,(char *)DXGetErrorString9(hr));
	sprintf(s,"%sDescription: %s\n",s,DXGetErrorDescription9(hr));
	
	f=fopen("log.txt","a+");
	fwrite(s,sizeof(char),strlen(s),f);
	fclose(f);
}
Пример #8
0
//--------------------------------------------------------------------------------------------------------------
//更新键盘输入
void DI8InputSystem::UpdateKeyboard()
{
    if( !mbEnableKeyboard )
        return;

    static DIDEVICEOBJECTDATA didod[DI8_KEY_BUF_SIZE];
    DWORD dwElements = DI8_KEY_BUF_SIZE;

    //清空上一帧事件变量
    memset( mbKeyDown, 0, sizeof(bool)*KEY_BUF_SIZE*2 );

Acquire:
    HRESULT result = mpDI8Keyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), didod, &dwElements, 0 );
    if( FAILED( result ) )
    {
        result = mpDI8Keyboard->Acquire();
        while( result == DIERR_INPUTLOST )
            result = mpDI8Keyboard->Acquire();

        if( SUCCEEDED( result ) )
            goto Acquire;

        Except( Exception::ERR_INTERNAL_ERROR, (String)"获取 DirectInput8 键盘设备出错!"
                "\nDX 错误描述:" + DXGetErrorDescription9( result ) );
    }

    //处理所有缓存数据
    for( DWORD i=0; i<dwElements; ++i )
    {
        //键盘按键编号
        DWORD key = didod[i].dwOfs;

        //如果按下了某键
        if( didod[i].dwData & 0x80 )
        {
            mbKeyState[key] = true;
            mbKeyDown[key] = true;
            mbKeyUp[key] = false;
        }
        //如果放开了某键
        else
        {
            mbKeyState[key] = false;
            mbKeyUp[key] = true;
            mbKeyDown[key] = false;
        }
    }
}
Пример #9
0
//--------------------------------------------------------------------------------------------------------------
//锁定纹理
void D3D9CubeTexture::LockRect( CubeFace eFace, void** ppBuf, UINT* pPitch, RECT* pLockRect, UINT nLevel, bool bDiscardLock )
{
    //选择锁定方法
    DWORD flag = bDiscardLock ? D3DLOCK_DISCARD : D3DLOCK_NOSYSLOCK;

    //锁定纹理
    D3DLOCKED_RECT d3dLockRect;
    HRESULT result = reinterpret_cast< IDirect3DCubeTexture9* >( mpD3D9Texture )->LockRect(
                         (D3DCUBEMAP_FACES)eFace, nLevel, &d3dLockRect, pLockRect, flag );

    if( FAILED( result ) )
        Except( Exception::ERR_INVALIDPARAMS, (String)"锁定 Direct3D 9 立方纹理错误。\nD3D9 错误描述:" +
                DXGetErrorDescription9(result) );

    *ppBuf = d3dLockRect.pBits;
    *pPitch = d3dLockRect.Pitch;
}
Пример #10
0
//--------------------------------------------------------------------------------------------------------------
D3D9CubeTexture::D3D9CubeTexture( UINT nEdgeLength, PixelFormat ePixelFormat, UINT nNumLevel, TextureUsage Type )
    : CubeTexture		( nEdgeLength, ePixelFormat, nNumLevel, Type )
{
    mBaseTexture.mpBaseTexture = reinterpret_cast< BaseTexture* >( this );

    HRESULT result = E_FAIL;

    //根据纹理用途获取纹理内存管理方式和 D3D 纹理用途标识
    DWORD dwUsage = _GetPoolModeAndUsage();

    //创建纹理
    result = D3D9RenderSystem::mpD3D9Device->CreateCubeTexture( mEdgeLength, mNumLevel,
             dwUsage, D3D9TypeGet::GetPixelFormat( mPixelFormat ),
             D3D9TypeGet::GetPoolMode( mPoolMode ), (IDirect3DCubeTexture9**)&mpD3D9Texture, NULL );
    if( FAILED( result ) )
        Except( Exception::ERR_RENDER_API_ERROR, (String)"使用 Direct3D 9 设备创建立方纹理错误。"
                "\nD3D9 错误描述" + DXGetErrorDescription9(result) );
}
Пример #11
0
	void D3D9Device::drawIndexedPrimitives(
		const video::PrimitivesType type,
		video::Vertexstream& vertexstream,
		video::Indexstream& indexstream,
		const ion_uint32 indexOffset,
		const ion_uint32 numElements)
	{
		vertexstream.bind();
		indexstream.bind();
		HRESULT hr=m_pD3DDev9->DrawIndexedPrimitive(
			d3dprimitivetype(type),0,0,vertexstream.capacity(),indexOffset,numElements);

		if (FAILED(hr)) {
			base::log("D3D9Device::drawIndexedPrimitives()",base::Error);
			base::logstream() << DXGetErrorString9(hr) << " " << DXGetErrorDescription9(hr) << "\n";
			base::logstream() << "Index stream capacity: " << indexstream.capacity() << "\n";
			base::logstream() << "Vertex stream capacity: " << vertexstream.capacity() << "\n";
			base::logstream() << "Index offset: " << indexOffset << "\n";
			base::logstream() << "Num elements: " << numElements << "\n";
		}
	}
Пример #12
0
	//--------------------------------------------------------------------------------------------------------------
	//创建顶点声明
	void D3D9VertexDeclaration::CreateVertexDeclaration()
	{
		static D3DVERTEXELEMENT9 D3DElement[nMaxElementNum];
		D3DVERTEXELEMENT9* pD3DElement = D3DElement;

		if( mNumElement > nMaxElementNum )
			Except( Exception::ERR_INVALIDPARAMS, "顶点声明所包含的顶点元素数量超过了最大值。" );

		//将顶点元素复制到 D3D9 顶点元素结构中
		VertexElement* pElement = mVertexElements.Begin();
		for( UINT i=0; i<mNumElement; ++i )
		{
			pD3DElement->Stream		= pElement->nStream;
			pD3DElement->Offset		= pElement->nOffset;
			pD3DElement->Type		= (BYTE)pElement->Type;
			pD3DElement->Method		= (BYTE)pElement->Method;
			pD3DElement->Usage		= (BYTE)pElement->Usage;
			pD3DElement->UsageIndex	= pElement->UsageIndex;

			++pD3DElement;
			++pElement;
		}

		//设置结尾顶点元素
		pD3DElement->Stream		= 0xFF;
		pD3DElement->Offset		= 0;
		pD3DElement->Type		= D3DDECLTYPE_UNUSED;
		pD3DElement->Method		= 0;
		pD3DElement->Usage		= 0;
		pD3DElement->UsageIndex	= 0;

		HRESULT result = D3D9RenderSystem::mpD3D9Device->CreateVertexDeclaration( D3DElement,
			&mpD3D9VertexDeclaration );
		if( FAILED( result ) )
			Except( Exception::ERR_RENDER_API_ERROR, (String)"创建 D3D9 顶点声明对象失败。"
			"\nD3D9 错误描述:" + DXGetErrorDescription9( result ) );
	}
Пример #13
0
//--------------------------------------------------------------------------------------------------------------
//更新鼠标输入
void DI8InputSystem::UpdateMouse()
{
    if( !mbEnableKeyboard )
        return;

    static DIMOUSESTATE2 mouseState;
    static DIDEVICEOBJECTDATA didod[DI8_MOUSE_BUF_SIZE];
    DWORD dwElements = DI8_MOUSE_BUF_SIZE;
    DWORD dwTime = 0;
    bool bIsPressed = false;

    //清空上一帧事件变量
    memset( mbMouseDown, 0, sizeof(bool)*9 );

    mMouseRelX = 0;
    mMouseRelY = 0;
    mMouseRelZ = 0;

Acquire:
    HRESULT result = mpDI8Mouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), didod, &dwElements, 0 );
    if( FAILED( result ) )
    {
        result = mpDI8Mouse->Acquire();
        while( result == DIERR_INPUTLOST )
            result = mpDI8Mouse->Acquire();

        if( SUCCEEDED( result ) )
            goto Acquire;

        Except( Exception::ERR_INTERNAL_ERROR, (String)"获取 DirectInput8 鼠标设备出错!"
                "\nDX 错误描述:" + DXGetErrorDescription9( result ) );
    }

    //处理所有缓存数据
    for( DWORD i=0; i<dwElements; ++i )
    {
        //消息产生时间
        dwTime = didod[i].dwTimeStamp;

        //是否为按键消息
        bIsPressed = ( didod[i].dwData & 0x80 ) ? true : false;

        switch( didod[i].dwOfs )
        {
        //左键消息
        case DIMOFS_BUTTON0:
            mbMouseState[0] = bIsPressed;
            mbMouseDown[0] = bIsPressed;
            mbMouseUp[0] = !bIsPressed;

            //如果按下
            if( bIsPressed )
            {
                //如果这次按键的时间与上次按键的时间间隔小于双击时间
                if( dwTime - mMouseLastDownTime[0] < mMouseDBClickTime[0] )
                {
                    mbMouseDBClick[0] = true;
                }
                else
                {
                    mMouseLastDownTime[0] = dwTime;
                }
            }
            break;

        //右键消息
        case DIMOFS_BUTTON1:
            mbMouseState[1] = bIsPressed;
            mbMouseDown[1] = bIsPressed;
            mbMouseUp[1] = !bIsPressed;

            //如果按下
            if( bIsPressed )
            {
                //如果这次按键的时间与上次按键的时间间隔小于双击时间
                if( dwTime - mMouseLastDownTime[1] < mMouseDBClickTime[1] )
                {
                    mbMouseDBClick[1] = true;
                }
                else
                {
                    mMouseLastDownTime[1] = dwTime;
                }
            }
            break;

        //中键消息
        case DIMOFS_BUTTON2:
            mbMouseState[2] = bIsPressed;
            mbMouseDown[2] = bIsPressed;
            mbMouseUp[2] = !bIsPressed;

            //如果按下
            if( bIsPressed )
            {
                //如果这次按键的时间与上次按键的时间间隔小于双击时间
                if( dwTime - mMouseLastDownTime[2] < mMouseDBClickTime[2] )
                {
                    mbMouseDBClick[2] = true;
                }
                else
                {
                    mMouseLastDownTime[2] = dwTime;
                }
            }
            break;

        //坐标移动消息
        case DIMOFS_X:
            mMouseRelX += (int)( (long)didod[i].dwData * mMouseSpeed / 65 );
            break;
        case DIMOFS_Y:
            mMouseRelY += (int)( (long)didod[i].dwData * mMouseSpeed / 65 );
            break;
        case DIMOFS_Z:
            mMouseRelZ += (int)( (long)didod[i].dwData * mMouseSpeed / 65 );
            break;

        default:
            break;
        }
    }

    //计算鼠标位置
    mMouseX += mMouseRelX;
    mMouseY += mMouseRelY;
    mMouseZ += mMouseRelZ;

    FixPosByMouseRect( &mMouseX, &mMouseY, &mMouseZ );
}
Пример #14
0
	ETOOLS_API const char*  WINAPI DX_GetErrorDescription9(HRESULT hr)
	{
		return DXGetErrorDescription9(hr);
	}