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


C++ LPDIRECT3DDEVICE9::CreateDepthStencilSurface方法代码示例

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


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

示例1: Draw

void Render::Draw(IDirect3DSurface9* renderTarget, D3DXMATRIX* view, D3DXMATRIX* projection)
{
    // Get or create device
    LPDIRECT3DDEVICE9 device = GetDevice();
    if (device == NULL) return;

    // Load shaders if it is required
//    if (!EnsureShaders()) return;

    // Prepare depth surface
    D3DSURFACE_DESC renderTargetDescription;
    renderTarget->GetDesc(&renderTargetDescription);
    D3DSURFACE_DESC depthSurfaceDescription;
    if (depthSurface != NULL) depthSurface->GetDesc(&depthSurfaceDescription);
    if (depthSurface == NULL || depthSurfaceDescription.Width != renderTargetDescription.Width || depthSurfaceDescription.Height != renderTargetDescription.Height)
    {
        if (depthSurface != NULL) depthSurface->Release();
        device->CreateDepthStencilSurface(renderTargetDescription.Width, renderTargetDescription.Height, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, FALSE, &depthSurface, NULL);
        if (depthSurface == NULL) return;
    }

    device->SetRenderTarget(0, renderTarget);
    device->SetDepthStencilSurface(depthSurface);
    device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);

    if (lowPolySphere == NULL)
    {
        // Create spheres
        lowPolySphere = CreateSphere(2);
        middlePolySphere = CreateSphere(3);
        highPolySphere = CreateSphere(5);
        // Create cylinders
        lowPolyCylinder = CreateCylinder(3);
        middlePolyCylinder = CreateCylinder(12);
        highPolyCylinder = CreateCylinder(24);
    }



    // FIXME: light dir must be slightly different!
    D3DVECTOR lightDirection;
    lightDirection.x = view->_13;
    lightDirection.y = view->_23;
    lightDirection.z = view->_33;
    D3DVECTOR viewDirection;
    viewDirection.x = view->_13;
    viewDirection.y = view->_23;
    viewDirection.z = view->_33;
    elementMaterials[0].SetViewLightDirection(&viewDirection, &lightDirection);

    // Rendering
    device->BeginScene();


    DrawAtoms(view, projection);
    DrawBonds(view, projection);
    DrawResidues(view, projection);

    device->EndScene();
}
开发者ID:AnthonyNystrom,项目名称:NuGenBioChemDX,代码行数:60,代码来源:Render.cpp

示例2: InitStateDX9

void InitStateDX9(void)
{
	// 取得Direct3D 9裝置
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();

	// 關閉打光
	device->SetRenderState(D3DRS_LIGHTING, FALSE);
	// 使用trilinear
	device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
	//
	device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	//
	device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE);

	device->GetRenderTarget(0, &g_pMainFrameBuffer);
	device->GetDepthStencilSurface(&g_pMainDepthBuffer);

	int width, height;
	GutGetWindowSize(width, height);

	g_iFrameBufferWidth = width * 2;
	g_iFrameBufferHeight = height * 2;

	device->CreateTexture(g_iFrameBufferWidth, g_iFrameBufferHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_pTexture, NULL);
	device->CreateDepthStencilSurface(g_iFrameBufferWidth, g_iFrameBufferHeight, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &g_pDepthStencil, NULL);
	g_pTexture->GetSurfaceLevel(0, &g_pFrameBuffer);
}
开发者ID:chenbk85,项目名称:3dlearn,代码行数:29,代码来源:render_dx9.cpp

示例3: InitResourceDX9

bool InitResourceDX9(void)
{
	// 取得Direct3D 9裝置
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// 設定視角轉換矩陣
	g_projection_matrix = GutMatrixPerspectiveRH_DirectX(g_fFOV, 1.0f, 0.1f, 100.0f);
	device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX *) &g_projection_matrix);

	// 關閉打光
	device->SetRenderState(D3DRS_LIGHTING, FALSE);
	// 改變三角形正面的面向
	device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

	device->CreateTexture(512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_pTexture, NULL);
	device->CreateDepthStencilSurface(512, 512, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &g_pDepthStencil, NULL);

	CGutModel::SetTexturePath("../../textures/");
	g_Model_DX9.ConvertToDX9Model(&g_Model);

	device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	device->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	device->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);

	return true;
}
开发者ID:as2120,项目名称:ZNginx,代码行数:31,代码来源:render_dx9.cpp

示例4:

HRESULT HookIDirect3DDevice9::CreateDepthStencilSurface(LPVOID _this,
														UINT Width,
														UINT Height,
														D3DFORMAT Format,
														D3DMULTISAMPLE_TYPE MultiSample,
														DWORD MultisampleQuality,
														BOOL Discard,
														IDirect3DSurface9** ppSurface,
														HANDLE* pSharedHandle)
{
	LOG_API();
	return pD3Dev->CreateDepthStencilSurface(Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle);
}
开发者ID:StephDiRaimondo,项目名称:xb_monitor,代码行数:13,代码来源:D3DWrapper.cpp

示例5:

// レンダリングターゲット用テクスチャ作成
const LPDIRECT3DTEXTURE9 CTexture::CreateRenderTarget( LPDIRECT3DDEVICE9 lpdevice, UINT width, UINT height, D3DFORMAT format )
{
	// 開放しておく
	this->~CTexture();

	// 指定されたサイズでテクスチャ作成
	D3DXCreateTexture(
		lpdevice,
		width,
		height,
		1,
		D3DUSAGE_RENDERTARGET,
		format,
		D3DPOOL_DEFAULT,
		&m_lpTex );

	// 深度バッファ作成
	lpdevice->CreateDepthStencilSurface( 
		width,
		height,
		D3DFMT_D16,
		D3DMULTISAMPLE_NONE,
		0,
		TRUE,
		&m_lpZbuffer,
		NULL );

	if( m_lpTex )
	{
		// テクスチャからレンダリングターゲット用サーフェス作成
		m_lpTex->GetSurfaceLevel( 0, &m_lpSurface );

		m_lpTex->GetLevelDesc( 0, &m_Desc );
	
	}else{

		return NULL;
	}
	
	return m_lpTex;
}
开发者ID:akinobufujii,项目名称:BubbleFight,代码行数:42,代码来源:Textures.cpp

示例6: InitialiseDirectX

bool InitialiseDirectX()
{
    const D3DFORMAT backBufferFormat = D3DFMT_D16;
    const D3DFORMAT textureFormat = D3DFMT_A8R8G8B8;

    if(FAILED(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
    {
        ShowMessageBox("Direct3D interface creation has failed");
        return false;
    }

    // Build present params
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    D3DMULTISAMPLE_TYPE antiAliasingLvl;
    bool antiAliasing = false;
    if(SUCCEEDED(d3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, 
        D3DDEVTYPE_HAL, textureFormat, true, D3DMULTISAMPLE_2_SAMPLES, nullptr)))
    {
        d3dpp.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
        antiAliasingLvl = D3DMULTISAMPLE_2_SAMPLES;
        antiAliasing = true;
    }

    d3dpp.hDeviceWindow = hWnd;
    d3dpp.Windowed = true;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = textureFormat;
    d3dpp.BackBufferWidth = WINDOW_WIDTH; 
    d3dpp.BackBufferHeight = WINDOW_HEIGHT;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = backBufferFormat; 

    if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, 
        D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3ddev)))
    {
        ShowMessageBox("Direct3D interface creation has failed");
        return false;
    }

    // Create Z-buffer
    if(FAILED(d3ddev->CreateDepthStencilSurface(WINDOW_WIDTH, WINDOW_HEIGHT, backBufferFormat,
        antiAliasing ? antiAliasingLvl : D3DMULTISAMPLE_NONE, NULL, TRUE, &backBuffer, NULL)))
    {
        ShowMessageBox("Z-buffer creation has failed");
        return false;
    }
    d3ddev->SetRenderTarget(0,backBuffer);

    // Set render states
    d3ddev->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, antiAliasing);

    // Check shader capabilities
    D3DCAPS9 caps;
    d3ddev->GetDeviceCaps(&caps);

    // Check for vertex shader version 2.0 support.
    if(caps.VertexShaderVersion < D3DVS_VERSION(2, 0)) 
    {
        ShowMessageBox("Shader model 2.0 or higher is required");
        return false;
    }

    return true;
}
开发者ID:huaminglee,项目名称:cloth-simulator,代码行数:66,代码来源:winmain.cpp

示例7: createDrawableIntoColorTextureWithDepth

void TextureGPU::createDrawableIntoColorTextureWithDepth(PrimitiveTypes::UInt32 w, PrimitiveTypes::UInt32 h, ESamplerState sampler, bool use32BitRedForDepth /* = false*/)
{
	StringOps::writeToString("createDrawableIntoColorTextureWithDepth", m_name, 256);
	m_samplerState = sampler;

#	if APIABSTRACTION_D3D9
	D3D9Renderer *pD3D9Renderer = static_cast<D3D9Renderer *>(m_pContext->getGPUScreen());
	LPDIRECT3DDEVICE9 pDevice = pD3D9Renderer->m_pD3D9Device;
	
	m_viewport.X = 0;
	m_viewport.Y = 0;
	m_viewport.Width = w;
	m_viewport.Height = h;
	m_viewport.MinZ = 0.0f;
	m_viewport.MaxZ = 1.0f;
#if APIABSTRACTION_X360
	HRESULT hr = D3DXCreateTexture(pDevice, 
		w, 
		h, 
		1, 
		D3DUSAGE_RENDERTARGET, 
		use32BitRedForDepth ? D3DFMT_R32F : D3DFMT_A8R8G8B8,
		D3DPOOL_DEFAULT, 
		&this->m_pTexture );
#else
	HRESULT hr = pDevice->CreateTexture(
		w, 
		h, 
		1, 
		D3DUSAGE_RENDERTARGET, 
		use32BitRedForDepth ? D3DFMT_R32F : D3DFMT_A8R8G8B8,
		D3DPOOL_DEFAULT, 
		&this->m_pTexture,
		NULL);
#endif

	D3DSURFACE_DESC desc;
	m_pTexture->GetSurfaceLevel( 0, &m_pSurface );
	m_pSurface->GetDesc( &desc );

#ifdef _XBOX
	//create depth stencil surface to use with this texture
	hr = pDevice->CreateDepthStencilSurface(
		w,
		h,
		D3DFMT_D24S8,
		D3DMULTISAMPLE_NONE,
		0,     // multi sample quality
		TRUE,  // Set this flag to TRUE to enable z-buffer discarding, and FALSE otherwise.
		//If this flag is set, the contents of the depth stencil buffer will be invalid
		// after calling either IDirect3DDevice9::Present or IDirect3DDevice9::SetDepthStencilSurface with a different depth surface.
		&m_pEDRamDSRenderTargetSurface,
		NULL);

	assert(SUCCEEDED(hr));

	hr = pDevice->CreateRenderTarget(
		desc.Width, desc.Height,
		( D3DFORMAT )MAKESRGBFMT( desc.Format ),
		D3DMULTISAMPLE_NONE, 0, 0,
		&m_pEDRamColorRenderTargetSurface, NULL );
#else
#if D3D9_USE_RENDER_TO_SURFACE
	hr = D3DXCreateRenderToSurface(pDevice, 
		desc.Width, 
		desc.Height, 
		desc.Format, 
		TRUE, 
		D3DFMT_D16, 
		&m_pRenderToSurface );
#else
	//create depth stencil surface to use with this texture
	hr = pDevice->CreateDepthStencilSurface(
		w,
		h,
		D3DFMT_D24S8,
		D3DMULTISAMPLE_NONE,
		0,     // multi sample quality
		TRUE,  // Set this flag to TRUE to enable z-buffer discarding, and FALSE otherwise.
		//If this flag is set, the contents of the depth stencil buffer will be invalid
		// after calling either IDirect3DDevice9::Present or IDirect3DDevice9::SetDepthStencilSurface with a different depth surface.
		&m_pDSSurface,
		NULL);
#endif
#endif

	assert(SUCCEEDED(hr));

#elif APIABSTRACTION_OGL

	SamplerState &ss = SamplerStateManager::getInstance()->getSamplerState(m_samplerState);

	GLuint texture;
	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);
    IRenderer::checkForErrors("glTexImage2D");
    
    #if PE_PLAT_IS_IOS
        PEWARN("We are creating depth texture as 32 bit, because I could not get 16 bit depth working. If you figure it out, change it to 16 bit for better perf (hopefully!)");
    #endif
//.........这里部分代码省略.........
开发者ID:AlexSincennes,项目名称:522AIProject,代码行数:101,代码来源:Texture_DrawableIntoColorTextureWithDepth.cpp

示例8: restore

void TextureCacheEntry::restore()
{

	// compute usage
	DWORD usage = D3DUSAGE_AUTOGENMIPMAP;
	D3DPOOL pool = D3DPOOL_MANAGED;
  UINT levels = 0;

	if (renderTarget) 
	{
		usage = usage | D3DUSAGE_RENDERTARGET;
		pool = D3DPOOL_DEFAULT;
    levels = 1;   
	}

	// Allocate D3D texture
	HRESULT result = pD3DDevice->CreateTexture(
		xSize,			// width
		ySize,			// height
		levels,			// number of miplevels - zero for automatic mip-map generation
		usage,	// usage - autogen mipmaps and maybe rendertarget
		D3DFMT_A8R8G8B8,	// pixel format - we will only use 32-bit
		pool,	// memory pool - we'll let D3D manage the textures so we don't have to "restore."
		&d3dTexture,		// return pointer to texture interface object here
		NULL // this parameter must be NULL
	);

	// Check for failure.  We won't handle errors gracefully.

	if (FAILED(result)) {
		ABORT("Can't allocate %dx%d 32-bit texture", xSize, ySize);
	}



  // Create a depth stencil if requested
  if (depthStencil)
  {
    // acceptable formats in order of preference
    D3DFORMAT formats[] = {D3DFMT_D32, D3DFMT_D16};

    for (int a = 0; a < 2; a++)
    {  
      result = 
      pD3DDevice->CreateDepthStencilSurface(
        xSize,
        ySize,
        formats[1],
        D3DMULTISAMPLE_NONE,
        NULL,
        true,
        &d3dDepthBuffer,
        NULL
        );

      // leave if a buffer was successfully created
      if (SUCCEEDED(result)) break;
      
    }
    if (FAILED(result)) // if a depth buffer could not be created
    {
      ABORT("Can't create a depth buffer", xSize, ySize);
    }
  }



}
开发者ID:carussell,项目名称:nvvg,代码行数:68,代码来源:TextureCacheEntry.cpp


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