当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECT3DSURFACE9::LockRect方法代码示例

本文整理汇总了C++中LPDIRECT3DSURFACE9::LockRect方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DSURFACE9::LockRect方法的具体用法?C++ LPDIRECT3DSURFACE9::LockRect怎么用?C++ LPDIRECT3DSURFACE9::LockRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECT3DSURFACE9的用法示例。


在下文中一共展示了LPDIRECT3DSURFACE9::LockRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: surface_save

int surface_save(int id, string filename)
{
  draw_batch_flush(batch_flush_deferred);

  get_surfacev(surface,id,-1);
  string ext = enigma::image_get_format(filename);

  LPDIRECT3DSURFACE9 pDestBuffer;
  D3DSURFACE_DESC desc;
  surface.surf->GetDesc(&desc);

  d3ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pDestBuffer, NULL );
  d3ddev->GetRenderTargetData(surface.surf, pDestBuffer);

  D3DLOCKED_RECT rect;

  pDestBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY);
  unsigned char* bitmap = static_cast<unsigned char*>(rect.pBits);
  pDestBuffer->UnlockRect();

  int ret = enigma::image_save(filename, bitmap, desc.Width, desc.Height, desc.Width, desc.Height, false);

  pDestBuffer->Release();

  return ret;
}
开发者ID:enigma-dev,项目名称:enigma-dev,代码行数:26,代码来源:DX9surface.cpp

示例2: TextureRC

	LPDIRECT3DTEXTURE9 DX9RenderSystem::GetTextureCache( Texture* tex )
	{
		TextureRC*& rc = (TextureRC*&)tex->mCache;
		if( !rc )
			rc = new TextureRC( );

		if( tex->IsDirty( ) )
		{
			if( mCacheCount >= DX9MAXFRAMECACHE )
				return 0;
			mCacheCount++;

			if( FAILED(D3DXCreateTexture( mDevice, tex->GetWidth( ), tex->GetHeight( ), 1, D3DUSAGE_DYNAMIC, (D3DFORMAT)tex->GetFormat( ), D3DPOOL_DEFAULT, &rc->mData )) )
			{
				printf( "Failed to create Texture Cache :: Couldn't create surface\n" );
				return 0;
			}

			LPDIRECT3DSURFACE9 surf;
			rc->mData->GetSurfaceLevel( 0, &surf );
			D3DLOCKED_RECT rect;
			surf->LockRect( &rect, 0, 0 );
			char* data = (char*)rect.pBits;
			memcpy( data, tex->GetBuffer( ), tex->GetBufferSize( ) );
			surf->UnlockRect( );

			D3DXSaveTextureToFile( "c:\\texdebug.png", D3DXIFF_PNG, rc->mData, 0 );

			tex->SetDirty( false );
		}
		return rc->mData;
	};
开发者ID:brett19,项目名称:Halia,代码行数:32,代码来源:DX9RenderSystem.cpp

示例3: DbgLog

__forceinline bool CDecDXVA2::CopyFrame(LAVFrame *pFrame)
{
  HRESULT hr;
  LPDIRECT3DSURFACE9 pSurface = (LPDIRECT3DSURFACE9)pFrame->data[3];
  pFrame->format = LAVPixFmt_NV12;

  D3DSURFACE_DESC surfaceDesc;
  pSurface->GetDesc(&surfaceDesc);

  D3DLOCKED_RECT LockedRect;
  hr = pSurface->LockRect(&LockedRect, NULL, D3DLOCK_READONLY);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"pSurface->LockRect failed (hr: %X)", hr));
    return false;
  }

  // Free AVFrame based buffers again
  FreeLAVFrameBuffers(pFrame);
  // Allocate memory buffers
  AllocLAVFrameBuffers(pFrame, LockedRect.Pitch);
  // Copy surface onto memory buffers
  CopyFrameNV12((BYTE *)LockedRect.pBits, pFrame->data[0], pFrame->data[1], surfaceDesc.Height, pFrame->height, LockedRect.Pitch);

  pSurface->UnlockRect();

  return true;
}
开发者ID:betaking,项目名称:LAVFilters,代码行数:27,代码来源:dxva2dec.cpp

示例4: LoadFromFile

//==============================================================
// <CImage>이미지를 로드하기:
// 큰 표면을 작성하여 이미지를 로드해,
// 이것을 256x256 픽셀씩 분할하여 텍스쳐 위에 복사함.
// UpdateSurface나 StretchRect는 사용할 수 없으므로
// (D3DPOOL_DEFAULT의 텍스쳐에는 복사할 수 있으나
//  이 클래스에서는 D3DPOOL_MANAGED을 사용하기 때문에)
// LockRect와 memcpy를 사용하여 복사함.
void CImage::LoadFromFile(wstring file_name) {
	LPDIRECT3DSURFACE9 surface;
	D3DLOCKED_RECT slr;
	if (SUCCEEDED(Device->CreateOffscreenPlainSurface(
			XCount*256, YCount*256, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, 
			&surface, NULL))
	) {
		if (SUCCEEDED(D3DXLoadSurfaceFromFile(
				surface, NULL, NULL, file_name.c_str(), NULL, 
				D3DX_FILTER_NONE, 0, NULL)) &&
			SUCCEEDED(surface->LockRect(
				&slr, NULL, D3DLOCK_READONLY))
		) {
			for (int yc=0, i=0; yc<YCount; yc++) {
				for (int xc=0; xc<XCount; xc++, i++) {
					if (!Textures[i]) continue;
					D3DLOCKED_RECT tlr;
					if (SUCCEEDED(Textures[i]->LockRect(0, &tlr, NULL, 0))) {
						int x=xc*256, y=yc*256;
						for (int line=0; line<256; line++) {
							memcpy(
								(char*)tlr.pBits+tlr.Pitch*line, 
								(char*)slr.pBits+x*4+slr.Pitch*(y+line), 
								256*4);
						}
						Textures[i]->UnlockRect(0);
					}
				}
			}
			surface->UnlockRect();
		}
		surface->Release();
	}
}
开发者ID:codebachi,项目名称:ProjectDirectX,代码行数:42,代码来源:Image.cpp

示例5: InitGraphics

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void InitGraphics(int width, int height )
{
	InitWindow(width, height);

	D3DPRESENT_PARAMETERS d3dp;
	ZeroMemory(&d3dp, sizeof(d3dp));
	d3dp.BackBufferWidth = width;
	d3dp.BackBufferHeight = height;
	d3dp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dp.BackBufferCount = 1;      
	d3dp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dp.Windowed = TRUE;
	d3dp.hDeviceWindow = (HWND)GetHandle();
	d3dp.EnableAutoDepthStencil = TRUE;
    d3dp.AutoDepthStencilFormat = D3DFMT_D16;

#if __PerformanceCheckMode
	d3dp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
#endif

	g_d3d = Direct3DCreate9(D3D_SDK_VERSION);
	
	g_d3d->CreateDevice( 
		D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		(HWND) GetHandle(),
		D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&d3dp,
		&g_d3d_device );

	
	{// 市松模様の背景画像を作る
		g_d3d_device->CreateOffscreenPlainSurface( width, height, 
			D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &g_d3d_clearing_image, NULL );
		D3DLOCKED_RECT lockedRect;
		g_d3d_clearing_image->LockRect( &lockedRect, NULL, 0 );
		CreateCheckeredPattern( width, height, (uint32_t*)lockedRect.pBits );
		g_d3d_clearing_image->UnlockRect();
	}

	g_renderer = ::EffekseerRendererDX9::Renderer::Create( g_d3d_device, 2000 );
	g_renderer->SetProjectionMatrix( ::Effekseer::Matrix44().PerspectiveFovRH( 90.0f / 180.0f * 3.14f, (float)width / (float)height, 1.0f, 50.0f ) );
	g_renderer->SetDistortingCallback( new DistortingCallback( 
		(EffekseerRendererDX9::Renderer*)g_renderer, g_d3d_device, width, height ) );
	
	g_manager->SetSpriteRenderer( g_renderer->CreateSpriteRenderer() );
	g_manager->SetRibbonRenderer( g_renderer->CreateRibbonRenderer() );
	g_manager->SetRingRenderer( g_renderer->CreateRingRenderer() );
	g_manager->SetModelRenderer( g_renderer->CreateModelRenderer() );
	g_manager->SetTrackRenderer( g_renderer->CreateTrackRenderer() );

	g_manager->SetCoordinateSystem( ::Effekseer::CoordinateSystem::RH );

	g_manager->SetTextureLoader( g_renderer->CreateTextureLoader() );
	g_manager->SetModelLoader( g_renderer->CreateModelLoader() );
}
开发者ID:AndrewFM,项目名称:Effekseer,代码行数:59,代码来源:graphics_dx9.cpp

示例6: sizeof

//---------------------------------
IP3DTexture* CP3DRenderer::TakeScreenShotTexture ()
{
	LPDIRECT3DSURFACE9 ScreenShotSurface = NULL;
	if (FAILED(g_pD3DDevice->GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, &ScreenShotSurface)))
		return NULL;

	// vytvor texturu
	CP3DTexture* pTex = new CP3DTexture();
	pTex->Create(m_nWidth, m_nHeight, 1, TF_RGB8, false);

	P3DLOCKED_RECT pRect;
	pRect.pBits = NULL;
	// ziskej data
	ScreenShotSurface->LockRect((D3DLOCKED_RECT*)&pRect, NULL, 0);
	if (!pRect.pBits) goto quitHand;

	// ziskej cilova data
	P3DLOCKED_RECT pRectCil;
	pTex->GetSurfaceData(0, &pRectCil);

	// zkopiruj data
	if(pRectCil.Pitch==pRect.Pitch) // pokud se shoduji Pitch, je mozno pouzit rychle memcpy
		memcpy(pRectCil.pBits, pRect.pBits, sizeof(char)*m_nWidth*m_nHeight*4);
	else // pokud se neshoduji Pitch, musi se to udelat timto slozitym zpusobem
	{
		unsigned char* pSurface = static_cast<unsigned char*>(pRect.pBits);
		unsigned char* pTarSurface = static_cast<unsigned char*>(pRectCil.pBits);
		for (unsigned long r = 0; r < (unsigned int)m_nHeight; r++)
		{
			unsigned long dwIndexTar = r * pRectCil.Pitch;
			unsigned long dwIndex = r * pRect.Pitch;
			for (unsigned long c = 0; c < (unsigned int)m_nWidth; c++)
			{
				pTarSurface[dwIndexTar + c*4 + 0] = pSurface[dwIndex + c*4 + 0];
				pTarSurface[dwIndexTar + c*4 + 1] = pSurface[dwIndex + c*4 + 1];
				pTarSurface[dwIndexTar + c*4 + 2] = pSurface[dwIndex + c*4 + 2];
			}
		}
	}

	// uzavri zdroj i cil
	ScreenShotSurface->UnlockRect();
	pTex->SaveSurfaceData();

	SAFE_RELEASE (ScreenShotSurface) // surface uz neni potreba

		return (IP3DTexture*)pTex; // vrat hotovou texturu

quitHand:
	if(pTex) delete pTex;
	return NULL;
}
开发者ID:k3a,项目名称:Panther3D-1,代码行数:53,代码来源:renderer.cpp

示例7: CreateTextureFromSurface

HRESULT VertexObject::CreateTextureFromSurface(LPDIRECT3DSURFACE9 pSurface, RECT* pSrcRect, RECT* pDestRect, LPDIRECT3DTEXTURE9* ppTexture)
{
	int width, height;
	RECT Src;
	D3DSURFACE_DESC surfDesc;
	pSurface->GetDesc(&surfDesc);

	if( !pSrcRect )
	{
		width = surfDesc.Width;
		height = surfDesc.Height;
		Src.left = Src.top = 0;
		Src.right = width;
		Src.bottom = height;
	}
	else
	{
		width = pSrcRect->right - pSrcRect->left; // + 1;
		height = pSrcRect->bottom - pSrcRect->top; // + 1;
		Src = *pSrcRect;
	}

	D3DXCreateTexture(DDevice, width, height, 
	1, 0, surfDesc.Format, D3DPOOL_DEFAULT, ppTexture) ;

	// Retrieve the surface image of the texture.
	LPDIRECT3DSURFACE9 pTexSurface;
	LPDIRECT3DTEXTURE9 pTexture = *ppTexture;
	pTexture->GetLevelDesc(0, &surfDesc);
	pTexture->GetSurfaceLevel(0, &pTexSurface);

	// Create a clean surface to clear the texture with.
	LPDIRECT3DSURFACE9 pCleanSurface;
	D3DLOCKED_RECT lockRect;
	DDevice->CreateOffscreenPlainSurface(
	surfDesc.Width, surfDesc.Height, surfDesc.Format, D3DPOOL_DEFAULT, &pCleanSurface, NULL);
	pCleanSurface->LockRect(&lockRect, NULL, 0) ;
	memset((BYTE*)lockRect.pBits, 0, surfDesc.Height * lockRect.Pitch);
	pCleanSurface->UnlockRect() ;

	DDevice->UpdateSurface(pCleanSurface, NULL, pTexSurface, NULL);
	pCleanSurface->Release();

	// Copy the image to the texture.
	POINT destPoint = { 0, 0 };
	DDevice->UpdateSurface(pSurface, &Src, pTexSurface, &destPoint);
	pTexSurface->Release();

	return S_OK;
}
开发者ID:vdoom,项目名称:GAM,代码行数:50,代码来源:VertexObject.cpp

示例8:

	virtual const char* lock_framebuffer( void *& buffer, unsigned & pitch )
	{
		if ( retry_count && !restore_objects() ) return "Lock failed";

		lptex->GetLevelDesc(0, &d3dsd);
		if ( lptex->GetSurfaceLevel(0, &lpsurface) != D3D_OK )
			return "Lock failed";

		if ( lpsurface->LockRect(&d3dlr, 0, flags.lock) != D3D_OK )
			return "Lock failed";
		buffer = d3dlr.pBits;
		pitch = d3dlr.Pitch;

		return buffer != 0 ? 0 : "Lock failed";
	}
开发者ID:kode54,项目名称:QuickNES_Windows,代码行数:15,代码来源:display_d3d9.cpp

示例9: Blit

bool EC_WidgetCanvas::Blit(const QImage &source, Ogre::TexturePtr destination)
{
#if defined(DIRECTX_ENABLED) && defined(WIN32)
    Ogre::HardwarePixelBufferSharedPtr pb = destination->getBuffer();
    Ogre::D3D9HardwarePixelBuffer *pixelBuffer = dynamic_cast<Ogre::D3D9HardwarePixelBuffer*>(pb.get());
    if (!pixelBuffer)
        return false;

    LPDIRECT3DSURFACE9 surface = pixelBuffer->getSurface(Ogre::D3D9RenderSystem::getActiveD3D9Device());
    if (surface)
    {
        D3DSURFACE_DESC desc;
        HRESULT hr = surface->GetDesc(&desc);
        if (SUCCEEDED(hr))
        {
            D3DLOCKED_RECT lock;
            HRESULT hr = surface->LockRect(&lock, 0, 0);
            if (SUCCEEDED(hr))
            {
                const int bytesPerPixel = 4; ///\todo Count from Ogre::PixelFormat!
                const int sourceStride = bytesPerPixel * source.width();
                if (lock.Pitch == sourceStride)
                    memcpy(lock.pBits, source.bits(), sourceStride * source.height());
                else
                    for(int y = 0; y < source.height(); ++y)
                        memcpy((u8*)lock.pBits + lock.Pitch * y, source.bits() + sourceStride * y, sourceStride);
                surface->UnlockRect();
            }
        }
    }
#else
    if (!destination->getBuffer().isNull())
    {
        Ogre::Box update_box(0, 0, source.width(), source.height());
        Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)source.bits());
        destination->getBuffer()->blitFromMemory(pixel_box, update_box);
    }
#endif

    return true;
}
开发者ID:360degrees-fi,项目名称:tundra,代码行数:41,代码来源:EC_WidgetCanvas.cpp

示例10: LoadVolumeSliceFromSurface

HRESULT CDxtexDoc::LoadVolumeSliceFromSurface(LPDIRECT3DVOLUME9 pVolume, UINT iSlice, LPDIRECT3DSURFACE9 psurf)
{
    HRESULT hr;
    D3DSURFACE_DESC sd;
    D3DVOLUME_DESC vd;
    D3DLOCKED_RECT lr;
    D3DBOX boxSrc;
    D3DBOX boxDest;

    psurf->GetDesc(&sd);
    pVolume->GetDesc(&vd);

    boxSrc.Left = 0;
    boxSrc.Right = sd.Width;
    boxSrc.Top = 0;
    boxSrc.Bottom = sd.Height;
    boxSrc.Front = 0;
    boxSrc.Back = 1;

    boxDest.Left = 0;
    boxDest.Right = vd.Width;
    boxDest.Top = 0;
    boxDest.Bottom = vd.Height;
    boxDest.Front = iSlice;
    boxDest.Back = iSlice + 1;

    hr = psurf->LockRect(&lr, NULL, 0);
    if (FAILED(hr))
        return hr;

    hr = D3DXLoadVolumeFromMemory(pVolume, NULL, &boxDest, lr.pBits, sd.Format, lr.Pitch, 
        0, NULL, &boxSrc, D3DX_DEFAULT, 0);

    psurf->UnlockRect();

    return hr;
}
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:37,代码来源:dxtexdoc.cpp

示例11: surface_getpixel_alpha

int surface_getpixel_alpha(int id, int x, int y)
{
  get_surfacev(surface,id,-1);
  if (x < 0) x = 0;
  if (y < 0) y = 0;
  if (x > surface->width || y > surface->height) return 0;

  d3dmgr->EndShapesBatching();
  LPDIRECT3DSURFACE9 pBuffer = surface->surf;
  d3dmgr->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
  D3DSURFACE_DESC desc;
  pBackBuffer->GetDesc(&desc);

  D3DLOCKED_RECT rect;

  pBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY);
  unsigned char* bitmap = static_cast<unsigned char*>(rect.pBits);
  unsigned offset = y * rect.Pitch + x * 4;
  int ret = bitmap[offset];
  pBuffer->UnlockRect();
  delete[] bitmap;

  return ret;
}
开发者ID:JustForkMyLifeUpFam,项目名称:enigma-dev,代码行数:24,代码来源:DX9surface.cpp

示例12: render

    // process and render media data
    int render()
    {
        try
        {
            if (m_shutdown)
                return 0;

            // capture user input once
            MODE mode = (m_mode == MODE_GPU_NV12) ? MODE_GPU_RGBA : m_mode;

            HRESULT r;
            LPDIRECT3DSURFACE9 pSurface;

            r = get_surface(&pSurface);
            if (FAILED(r))
            {
                return -1;
            }

            m_timer.start();

            switch (mode)
            {
                case MODE_CPU:
                {
                    // process video frame on CPU
                    D3DLOCKED_RECT memDesc = { 0, NULL };
                    RECT rc = { 0, 0, m_width, m_height };

                    r = pSurface->LockRect(&memDesc, &rc, 0);
                    if (FAILED(r))
                    {
                        return -1;
                    }

                    cv::Mat m(m_height, m_width, CV_8UC4, memDesc.pBits, memDesc.Pitch);

                    if (m_demo_processing)
                    {
                        // blur D3D9 surface with OpenCV on CPU
                        cv::blur(m, m, cv::Size(15, 15), cv::Point(-7, -7));
                    }

                    r = pSurface->UnlockRect();
                    if (FAILED(r))
                    {
                        return -1;
                    }

                    break;
                }

                case MODE_GPU_RGBA:
                {
                    // process video frame on GPU
                    cv::UMat u;

                    cv::directx::convertFromDirect3DSurface9(pSurface, u);

                    if (m_demo_processing)
                    {
                        // blur D3D9 surface with OpenCV on GPU with OpenCL
                        cv::blur(u, u, cv::Size(15, 15), cv::Point(-7, -7));
                    }

                    cv::directx::convertToDirect3DSurface9(u, pSurface);

                    break;
                }

            } // switch

            m_timer.stop();

            print_info(pSurface, mode, m_timer.time(Timer::UNITS::MSEC), m_oclDevName);

            // traditional DX render pipeline:
            //   BitBlt surface to backBuffer and flip backBuffer to frontBuffer
            r = m_pD3D9Dev->StretchRect(pSurface, NULL, m_pBackBuffer, NULL, D3DTEXF_NONE);
            if (FAILED(r))
            {
                return -1;
            }

            // present the back buffer contents to the display
            r = m_pD3D9Dev->Present(NULL, NULL, NULL, NULL);
            if (FAILED(r))
            {
                return -1;
            }
        }  // try

        catch (cv::Exception& e)
        {
            std::cerr << "Exception: " << e.what() << std::endl;
            return 10;
        }

        return 0;
//.........这里部分代码省略.........
开发者ID:Jendker,项目名称:opencv,代码行数:101,代码来源:d3d9_interop.cpp

示例13: float

HRESULT KG3DSelector::OnRender()
{
	HRESULT hRetCode = E_FAIL;
	HRESULT hResult = E_FAIL;
	D3DLOCKED_RECT Rect;
	LPDIRECT3DSURFACE9 pResultColor = NULL;
	LPDIRECT3DSURFACE9 pStencilRT = NULL;
	D3DVIEWPORT9 vp;
	D3DVIEWPORT9 vpNew;
	KG3DRenderState RenderState;
	DWORD dwSelectIndex = 0xff;
	g_pd3dDevice->GetViewport(&vp);
		
	vpNew = vp;
	vpNew.X /= m_nScale;
	vpNew.Y /= m_nScale;
	vpNew.Width /= m_nScale;
	vpNew.Height /= m_nScale;
	
	m_dwIndex = 0;//Stencil Index清零
	KG_PROCESS_SUCCESS(!m_vecModels.size());
		
	hResult = g_pd3dDevice->GetRenderTarget(0, &m_pRTSave);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->GetDepthStencilSurface(&m_pDepthSave);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = m_pStencilRT->GetSurfaceLevel(0, &pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetRenderTarget(0, pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetDepthStencilSurface(m_pStencilDepth);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 1L);
	KG_COM_PROCESS_ERROR(hResult);
	
	g_pd3dDevice->SetViewport(&vpNew);

	RenderModelList();
	
	if (0)
	{
		D3DXSaveTextureToFile("d:\\test.tga", D3DXIFF_TGA, m_pStencilRT, NULL);
	}

	hResult = g_pd3dDevice->SetTexture(0, m_pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	g_pd3dDevice->SetTexture(1, NULL);

	hResult = g_pd3dDevice->SetDepthStencilSurface(NULL);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetRenderTarget(0, m_pRT);
	KG_COM_PROCESS_ERROR(hResult);
	
	RenderState.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

	float fU = float(m_MousePoint.x) / m_nWidth ;
	float fV = float(m_MousePoint.y) / m_nHeight;

	ScreenRect[0].vec2UV = D3DXVECTOR2(fU, fV);
	ScreenRect[1].vec2UV = D3DXVECTOR2(fU, fV);
	ScreenRect[2].vec2UV = D3DXVECTOR2(fU, fV);
	ScreenRect[3].vec2UV = D3DXVECTOR2(fU, fV);

	hResult = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0f, 1L);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetFVF(SelectorVertex::dwFVF);
	KG_COM_PROCESS_ERROR(hResult);

	RenderState.SetRenderState(D3DRS_FOGENABLE, FALSE);
	RenderState.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
	RenderState.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
	RenderState.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	RenderState.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

	hResult = g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, ScreenRect, sizeof(SelectorVertex));
	KG_COM_PROCESS_ERROR(hResult);

	hResult = m_pResult->GetSurfaceLevel(0, &pResultColor);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->GetRenderTargetData(m_pRT, pResultColor);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = pResultColor->LockRect(&Rect, NULL, 0);
	KG_COM_PROCESS_ERROR(hResult);

	BYTE *pBit = (BYTE*)Rect.pBits;
	dwSelectIndex = *(pBit + 2);

	pResultColor->UnlockRect();
	KG_COM_PROCESS_ERROR(hResult);

//.........这里部分代码省略.........
开发者ID:1suming,项目名称:pap2,代码行数:101,代码来源:KG3DSelector.cpp

示例14: D3DUtil_SetDeviceCursor

//-----------------------------------------------------------------------------
// Name: D3DUtil_SetDeviceCursor
// Desc: Gives the D3D device a cursor with image and hotspot from hCursor.
//-----------------------------------------------------------------------------
HRESULT D3DUtil_SetDeviceCursor( LPDIRECT3DDEVICE9 pd3dDevice, HCURSOR hCursor,
                                 BOOL bAddWatermark )
{
    HRESULT hr = E_FAIL;
    ICONINFO iconinfo;
    BOOL bBWCursor;
    LPDIRECT3DSURFACE9 pCursorSurface = NULL;
    HDC hdcColor = NULL;
    HDC hdcMask = NULL;
    HDC hdcScreen = NULL;
    BITMAP bm;
    DWORD dwWidth;
    DWORD dwHeightSrc;
    DWORD dwHeightDest;
    COLORREF crColor;
    COLORREF crMask;
    UINT x;
    UINT y;
    BITMAPINFO bmi;
    COLORREF* pcrArrayColor = NULL;
    COLORREF* pcrArrayMask = NULL;
    DWORD* pBitmap;
    HGDIOBJ hgdiobjOld;

    ZeroMemory( &iconinfo, sizeof(iconinfo) );
    if( !GetIconInfo( hCursor, &iconinfo ) )
        goto End;

    if (0 == GetObject((HGDIOBJ)iconinfo.hbmMask, sizeof(BITMAP), (LPVOID)&bm))
        goto End;
    dwWidth = bm.bmWidth;
    dwHeightSrc = bm.bmHeight;

    if( iconinfo.hbmColor == NULL )
    {
        bBWCursor = TRUE;
        dwHeightDest = dwHeightSrc / 2;
    }
    else 
    {
        bBWCursor = FALSE;
        dwHeightDest = dwHeightSrc;
    }

    // Create a surface for the fullscreen cursor
    if( FAILED( hr = pd3dDevice->CreateOffscreenPlainSurface( dwWidth, dwHeightDest, 
        D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pCursorSurface, 0 ) ) )
    {
        goto End;
    }

    pcrArrayMask = new DWORD[dwWidth * dwHeightSrc];

    ZeroMemory(&bmi, sizeof(bmi));
    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
    bmi.bmiHeader.biWidth = dwWidth;
    bmi.bmiHeader.biHeight = dwHeightSrc;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;

    hdcScreen = GetDC( NULL );
    hdcMask = CreateCompatibleDC( hdcScreen );
    if( hdcMask == NULL )
    {
        hr = E_FAIL;
        goto End;
    }
    hgdiobjOld = SelectObject(hdcMask, iconinfo.hbmMask);
    GetDIBits(hdcMask, iconinfo.hbmMask, 0, dwHeightSrc, 
        pcrArrayMask, &bmi, DIB_RGB_COLORS);
    SelectObject(hdcMask, hgdiobjOld);

    if (!bBWCursor)
    {
        pcrArrayColor = new DWORD[dwWidth * dwHeightDest];
        hdcColor = CreateCompatibleDC( hdcScreen );
        if( hdcColor == NULL )
        {
            hr = E_FAIL;
            goto End;
        }
        SelectObject(hdcColor, iconinfo.hbmColor);
        GetDIBits(hdcColor, iconinfo.hbmColor, 0, dwHeightDest, 
            pcrArrayColor, &bmi, DIB_RGB_COLORS);
    }

    // Transfer cursor image into the surface
    D3DLOCKED_RECT lr;
    pCursorSurface->LockRect( &lr, NULL, 0 );
    pBitmap = (DWORD*)lr.pBits;
    for( y = 0; y < dwHeightDest; y++ )
    {
        for( x = 0; x < dwWidth; x++ )
        {
            if (bBWCursor)
//.........这里部分代码省略.........
开发者ID:arkiny,项目名称:Direct3D,代码行数:101,代码来源:d3dutil.cpp

示例15: defined

/// Load a texture from a proper DDSFile instance.
bool GFXD3D9TextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds)
{
   PROFILE_SCOPE(GFXD3D9TextureManager_loadTextureDDS);

   GFXD3D9TextureObject *texture = static_cast<GFXD3D9TextureObject*>(aTexture);

   // Fill the texture...
   for( int i = 0; i < aTexture->mMipLevels; i++ )
   {
      PROFILE_SCOPE(GFXD3DTexMan_loadSurface);

      LPDIRECT3DSURFACE9 surf = NULL;
      D3D9Assert(texture->get2DTex()->GetSurfaceLevel( i, &surf ), "Failed to get surface");

#if defined(TORQUE_OS_XENON)
      XGTEXTURE_DESC surfDesc;
      dMemset(&surfDesc, 0, sizeof(XGTEXTURE_DESC));
      XGGetSurfaceDesc(surf, &surfDesc);

      RECT srcRect;
      srcRect.top = srcRect.left = 0;
      srcRect.bottom = dds->getHeight(i);
      srcRect.right = dds->getWidth(i);

      D3DXLoadSurfaceFromMemory(surf, NULL, NULL, dds->mSurfaces[0]->mMips[i],
         (D3DFORMAT)MAKELINFMT(GFXD3D9TextureFormat[dds->mFormat]), dds->getSurfacePitch(i), 
         NULL, &srcRect, false, 0, 0, D3DX_FILTER_NONE, 0);
#else

      GFXD3D9Device* dev = static_cast<GFXD3D9Device *>(GFX);

      if (dev->isD3D9Ex())
      {
         RECT r;
         r.top = r.left = 0;
         r.bottom = dds->getHeight(i);
         r.right = dds->getWidth(i);
         D3DXLoadSurfaceFromMemory(surf, NULL, NULL, dds->mSurfaces[0]->mMips[i], GFXD3D9TextureFormat[dds->mFormat], dds->getSurfacePitch(i), NULL, &r, D3DX_DEFAULT, 0);
      }
      else
      {
         D3DLOCKED_RECT lockedRect;
         D3D9Assert( surf->LockRect( &lockedRect, NULL, 0 ), "Failed to lock surface level for load" );

         AssertFatal( dds->mSurfaces.size() > 0, "Assumption failed. DDSFile has no surfaces." );

         if ( dds->getSurfacePitch( i ) != lockedRect.Pitch )
         {
            // Do a row-by-row copy.
            U32 srcPitch = dds->getSurfacePitch( i );
            U32 srcHeight = dds->getHeight();
            U8* srcBytes = dds->mSurfaces[0]->mMips[i];
            U8* dstBytes = (U8*)lockedRect.pBits;
            for (U32 i = 0; i<srcHeight; i++)          
            {
               dMemcpy( dstBytes, srcBytes, srcPitch );
               dstBytes += lockedRect.Pitch;
               srcBytes += srcPitch;
            }           
            surf->UnlockRect();
            surf->Release();

            return true;
         }

         dMemcpy( lockedRect.pBits, dds->mSurfaces[0]->mMips[i], dds->getSurfaceSize(i) );

         surf->UnlockRect();
      }
#endif

      surf->Release();
   }

   return true;
}
开发者ID:Adhdcrazzy,项目名称:Torque3D,代码行数:77,代码来源:gfxD3D9TextureManager.cpp


注:本文中的LPDIRECT3DSURFACE9::LockRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。