本文整理汇总了C++中IDirect3DStateBlock9::Apply方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DStateBlock9::Apply方法的具体用法?C++ IDirect3DStateBlock9::Apply怎么用?C++ IDirect3DStateBlock9::Apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DStateBlock9
的用法示例。
在下文中一共展示了IDirect3DStateBlock9::Apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderStageBlend
// renderStageBlend - Blend between MGE distant land and Morrowind, rendering caustics first so it blends out
void DistantLand::renderStageBlend()
{
DECLARE_MWBRIDGE
IDirect3DStateBlock9 *stateSaved;
UINT passes;
if(isRenderCached)
return;
// Save state block manually since we can change FVF/decl
device->CreateStateBlock(D3DSBT_ALL, &stateSaved);
effect->Begin(&passes, D3DXFX_DONOTSAVESTATE);
// Render caustics
if(mwBridge->IsExterior() && Configuration.DL.WaterCaustics > 0)
{
D3DXMATRIX m;
IDirect3DTexture9 *tex = PostShaders::borrowBuffer(0);
D3DXMatrixTranslation(&m, eyePos.x, eyePos.y, mwBridge->WaterLevel());
effect->SetTexture(ehTex0, tex);
effect->SetTexture(ehTex1, texWater);
effect->SetTexture(ehTex3, texDepthFrame);
effect->SetMatrix(ehWorld, &m);
effect->SetFloat(ehAlphaRef, Configuration.DL.WaterCaustics);
effect->CommitChanges();
effect->BeginPass(PASS_RENDERCAUSTICS);
PostShaders::applyBlend();
effect->EndPass();
}
// Blend MW/MGE
if(isDistantCell() && (~Configuration.MGEFlags & NO_MW_MGE_BLEND))
{
effect->SetTexture(ehTex0, texDistantBlend);
effect->SetTexture(ehTex3, texDepthFrame);
effect->CommitChanges();
effect->BeginPass(PASS_BLENDMGE);
PostShaders::applyBlend();
effect->EndPass();
}
effect->End();
stateSaved->Apply();
stateSaved->Release();
}
示例2: RenderMeshes
void Overlay::RenderMeshes()
{
if(g_Globals.UsingOverlay && _Meshes.Length() > 0)
{
IDirect3DStateBlock9* pStateBlock = NULL;
_Device->CreateStateBlock( D3D9Base::D3DSBT_ALL, &pStateBlock );
const UINT MaxTextureSlots = 8;
for(UINT TextureIndex = 0; TextureIndex < MaxTextureSlots; TextureIndex++)
{
_Device->SetTexture(TextureIndex, NULL);
}
D3D9Base::D3DXMATRIXA16 NewTransformWorld, NewTransformView, NewTransformProjection;
NewTransformWorld = Matrix4ToD3DXMATRIX(Matrix4::Identity());
NewTransformView = Matrix4ToD3DXMATRIX(Matrix4::Identity());
NewTransformProjection = Matrix4ToD3DXMATRIX(_MeshTransform);
_Device->SetTransform(D3DTS_WORLD, &NewTransformWorld);
_Device->SetTransform(D3D9Base::D3DTS_VIEW, &NewTransformView);
_Device->SetTransform(D3D9Base::D3DTS_PROJECTION, &NewTransformProjection);
_Device->SetRenderState(D3D9Base::D3DRS_ALPHABLENDENABLE, FALSE);
//_Device->SetRenderState(D3D9Base::D3DRS_ZENABLE, D3D9Base::D3DZB_TRUE);
_Device->SetRenderState(D3D9Base::D3DRS_ZENABLE, D3D9Base::D3DZB_FALSE);
_Device->SetRenderState(D3D9Base::D3DRS_LIGHTING, FALSE);
_Device->SetRenderState(D3D9Base::D3DRS_ZFUNC, D3D9Base::D3DCMP_ALWAYS);
_Device->SetRenderState(D3D9Base::D3DRS_ALPHATESTENABLE, FALSE);
_Device->SetRenderState(D3D9Base::D3DRS_CULLMODE, D3D9Base::D3DCULL_NONE);
const DWORD D3DMeshFlags = D3DFVF_DIFFUSE | D3DFVF_NORMAL | D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEX1;
_Device->SetFVF(D3DMeshFlags);
_Device->SetVertexShader(NULL);
_Device->SetPixelShader(NULL);
for(UINT MeshIndex = 0; MeshIndex < _Meshes.Length(); MeshIndex++)
{
Mesh &CurMesh = *(_Meshes[MeshIndex]);
_Device->DrawIndexedPrimitiveUP(D3D9Base::D3DPT_TRIANGLELIST, 0, CurMesh.VertexCount(), CurMesh.FaceCount(), CurMesh.Indices(), D3D9Base::D3DFMT_INDEX32, CurMesh.Vertices(), sizeof(MeshVertex));
}
pStateBlock->Apply();
pStateBlock->Release();
}
}
示例3: renderShadow
// renderStage2 - Render shadows and depth texture for scenes 1+ (post-stencil redraw/alpha/1st person)
void DistantLand::renderStage2()
{
DECLARE_MWBRIDGE
IDirect3DStateBlock9 *stateSaved;
UINT passes;
///LOG::logline("Stage 2 prims: %d", recordMW.size());
// Early out if nothing is happening
if(recordMW.empty())
return;
if(!isRenderCached)
{
// Save state block manually since we can change FVF/decl
device->CreateStateBlock(D3DSBT_ALL, &stateSaved);
if(isDistantCell())
{
// Shadowing onto recorded renders
if((Configuration.MGEFlags & USE_SHADOWS) && mwBridge->CellHasWeather())
{
effect->Begin(&passes, D3DXFX_DONOTSAVESTATE);
effect->BeginPass(PASS_RENDERSHADOW);
renderShadow();
effect->EndPass();
effect->End();
}
}
// Depth texture from recorded renders
effectDepth->Begin(&passes, D3DXFX_DONOTSAVESTATE);
renderDepthAdditional();
effectDepth->End();
// Restore state
stateSaved->Apply();
stateSaved->Release();
}
recordMW.clear();
}
示例4: doPresent
static void doPresent(IDirect3DDevice9 *idd) {
DevMapType::iterator it = devMap.find(idd);
DevState *ds = it != devMap.end() ? it->second : NULL;
if (ds && ds->pSB) {
if (ds->dwMyThread != 0) {
ods("D3D9: doPresent from other thread");
}
Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId());
IDirect3DSurface9 *pTarget = NULL;
IDirect3DSurface9 *pRenderTarget = NULL;
idd->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pTarget);
idd->GetRenderTarget(0, &pRenderTarget);
// Present is called for each frame. Thus, we do not want to always log here.
#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT
ods("D3D9: doPresent BackB %p RenderT %p", pTarget, pRenderTarget);
#endif
IDirect3DStateBlock9* pStateBlock = NULL;
idd->CreateStateBlock(D3DSBT_ALL, &pStateBlock);
pStateBlock->Capture();
ds->pSB->Apply();
if (pTarget != pRenderTarget)
idd->SetRenderTarget(0, pTarget);
idd->BeginScene();
ds->draw();
idd->EndScene();
pStateBlock->Apply();
pStateBlock->Release();
pRenderTarget->Release();
pTarget->Release();
// ods("D3D9: Finished ref is %d %d", ds->myRefCount, ds->refCount);
}
}
示例5: doPresent
static void doPresent(IDirect3DDevice9 *idd) {
DevState *ds = devMap[idd];
if (ds && ds->pSB) {
DWORD dwOldThread = ds->dwMyThread;
if (dwOldThread)
ods("doPresent from other thread");
ds->dwMyThread = GetCurrentThreadId();
IDirect3DSurface9 *pTarget = NULL;
IDirect3DSurface9 *pRenderTarget = NULL;
idd->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pTarget);
idd->GetRenderTarget(0, &pRenderTarget);
ods("D3D9: doPresent Back %p RenderT %p",pTarget,pRenderTarget);
IDirect3DStateBlock9* pStateBlock = NULL;
idd->CreateStateBlock(D3DSBT_ALL, &pStateBlock);
pStateBlock->Capture();
ds->pSB->Apply();
if (pTarget != pRenderTarget)
idd->SetRenderTarget(0, pTarget);
idd->BeginScene();
ds->draw();
idd->EndScene();
pStateBlock->Apply();
pStateBlock->Release();
pRenderTarget->Release();
pTarget->Release();
// ods("Finished ref is %d %d", ds->myRefCount, ds->refCount);
ds->dwMyThread = dwOldThread;
}
}
示例6: OnRender
//--------------------------------------------------------------------------------
void System::OnRender(IDirect3DDevice9* pDevice)
{
//if(clock() - TheGameWorld->GetRendering() < 400)
{
IDirect3DStateBlock9* pStateBlock = NULL;
pDevice->CreateStateBlock(D3DSBT_ALL, &pStateBlock);
pStateBlock->Capture();
try
{
if(mUI && mPlatform)
{
Update();
mPlatform->getRenderManagerPtr()->drawOneFrame();
}
}
catch(...)
{
}
pStateBlock->Apply();
pStateBlock->Release();
}
}
示例7: renderStageWater
// renderStageWater - Render distant water without blend, for exceptional cases
void DistantLand::renderStageWater()
{
DECLARE_MWBRIDGE
IDirect3DStateBlock9 *stateSaved;
UINT passes;
if(isRenderCached)
return;
if(mwBridge->CellHasWater())
{
// Save state block manually since we can change FVF/decl
device->CreateStateBlock(D3DSBT_ALL, &stateSaved);
effect->Begin(&passes, D3DXFX_DONOTSAVESTATE);
// Draw water plane
bool u = mwBridge->IsUnderwater(eyePos.z);
bool i = !mwBridge->IsExterior();
if(u || i)
{
// Set up clip plane at fog end for certain environments to save fillrate
float clipAt = Configuration.DL.InteriorFogEnd * 8192.0;
D3DXPLANE clipPlane(0, 0, -clipAt, mwProj._33 * clipAt + mwProj._43);
device->SetClipPlane(0, clipPlane);
device->SetRenderState(D3DRS_CLIPPLANEENABLE, 1);
}
// Switch to appropriate shader and render
effect->BeginPass(u ? PASS_RENDERUNDERWATER : PASS_RENDERWATER);
renderWaterPlane();
effect->EndPass();
effect->End();
stateSaved->Apply();
stateSaved->Release();
}
}
示例8: sample_EndScene
HRESULT WINAPI sample_EndScene(IDirect3DDevice9* device){
Vert v[] = {
{100.0f,100.0f,0.0f,0.0f,0xFF00FF00},
{200.0f,100.0f,0.0f,0.0f,0xFF00FF00},
{200.0f,200.0f,0.0f,0.0f,0xFF00FF00},
{100.0f,200.0f,0.0f,0.0f,0xFF00FF00},
};
IDirect3DStateBlock9* stateBlock = NULL;
device->CreateStateBlock(D3DSBT_ALL, &stateBlock); // Stateblock saves all the rendersettings, as we are going to modify them in order to draw our stuff
device->SetRenderState(D3DRS_ALPHABLENDENABLE,1);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,v,sizeof(Vert));
stateBlock->Apply();
stateBlock->Release();
return endscene_og(device);
}
示例9: draw
void MGEhud::draw()
{
std::map<std::string, MGEhud::hud_id>::const_iterator i;
IDirect3DStateBlock9 *stateSaved;
device->CreateStateBlock(D3DSBT_ALL, &stateSaved);
D3DXVECTOR4 *vbase;
HRESULT hr = vbHUD->Lock(0, 0, (void**)&vbase, D3DLOCK_DISCARD);
if(hr != D3D_OK || vbase == 0)
return;
for(i = element_names.begin(); i != element_names.end(); ++i)
{
const Element *e = &elements[i->second];
if(e->enabled)
{
float x0 = e->x, x1 = e->x + e->xscale * e->w;
float y0 = e->y, y1 = e->y + e->yscale * e->h;
// Correct for D3D9 pixel offset
x0 -= 0.5; y0 -= 0.5; x1 -= 0.5; y1 -= 0.5;
D3DXVECTOR4 *v = vbase + 8 * i->second;
v[0] = D3DXVECTOR4(x0, y1, 0, 1);
v[1] = D3DXVECTOR4(0, 1, 0, 0);
v[2] = D3DXVECTOR4(x0, y0, 0, 1);
v[3] = D3DXVECTOR4(0, 0, 0, 0);
v[4] = D3DXVECTOR4(x1, y1, 0, 1);
v[5] = D3DXVECTOR4(1, 1, 0, 0);
v[6] = D3DXVECTOR4(x1, y0, 0, 1);
v[7] = D3DXVECTOR4(1, 0, 0, 0);
}
}
vbHUD->Unlock();
device->SetFVF(fvfHUD);
device->SetStreamSource(0, vbHUD, 0, 32);
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
for(i = element_names.begin(); i != element_names.end(); ++i)
{
const Element *e = &elements[i->second];
if(e->enabled)
{
ID3DXEffect *effect = e->effect ? e->effect : effectStandard;
D3DXHANDLE ehTex = effect->GetParameterByName(0, "tex");
UINT passes;
effect->SetTexture(ehTex, e->texture);
effect->Begin(&passes, D3DXFX_DONOTSAVESTATE);
effect->BeginPass(0);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4 * i->second, 2);
effect->EndPass();
effect->End();
}
}
stateSaved->Apply();
stateSaved->Release();
}
示例10:
STDMETHODIMP CDirect3DDevice8::ApplyStateBlock(THIS_ DWORD Token)
{
IDirect3DStateBlock9* pBlock = (IDirect3DStateBlock9*)Token;
return pBlock->Apply();
}
示例11: Provoke
//.........这里部分代码省略.........
sRenderViewport.Pos.y = 0;
sRenderViewport.Size.w = sTextureSize.w;
sRenderViewport.Size.h = sTextureSize.h;
// get and set scale and offset
if (m_psFOVPortLeft)
ovrHmd_GetRenderScaleAndOffset(*m_psFOVPortLeft, sTextureSize, sRenderViewport, UVScaleOffset);
else
ovrHmd_GetRenderScaleAndOffset(m_sDefaultFOVPortLeft, sTextureSize, sRenderViewport, UVScaleOffset);
pcDevice->SetVertexShaderConstantF( 0, ( FLOAT* )&UVScaleOffset[0], 1 );
pcDevice->SetVertexShaderConstantF( 2, ( FLOAT* )&UVScaleOffset[1], 1 );
pcDevice->SetStreamSource( 0, m_pcDistortionVertexBufferLeft,0, sizeof(ovrDistortionVertex) );
pcDevice->SetIndices( m_pcDistortionIndexBufferLeft);
// draw
pcDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0, m_sVertexBufferDescLeft.Size / sizeof(ovrDistortionVertex) , 0, m_sIndexBufferDescLeft.Size / 6 );
}
else
{
pcDevice->SetSamplerState(1, D3DSAMP_SRGBTEXTURE, 0);
pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
pcDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
pcDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
pcDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
// side by side render
pcDevice->SetVertexShader(NULL);
pcDevice->SetPixelShader(m_pcSideBySidePixelShader);
pcDevice->SetVertexDeclaration( NULL );
pcDevice->SetFVF(D3DFVF_TEXVERTEX);
// set textures
if (m_pcTextureLeft)
pcDevice->SetTexture( 0, m_pcTextureLeft );
else if (m_pcTextureLeftTest)
pcDevice->SetTexture( 0, m_pcTextureLeftTest );
else pcDevice->SetTexture( 0, 0);
if (m_pcTextureRight)
pcDevice->SetTexture( 1, m_pcTextureRight );
else if (m_pcTextureRightTest)
pcDevice->SetTexture( 1, m_pcTextureRightTest );
else pcDevice->SetTexture( 1, 0);
// set stream and draw
pcDevice->SetStreamSource( 0, m_pcVertexBufferDefault,0, sizeof(TEXVERTEX) );
pcDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
}
// RIGHT EYE:
if (m_bBuffersConnected)
{
// set texture
if (m_pcTextureRight)
pcDevice->SetTexture( 0, m_pcTextureRight );
else if (m_pcTextureRightTest)
pcDevice->SetTexture( 0, m_pcTextureRightTest );
else pcDevice->SetTexture( 0, 0);
// get texture size
if (m_pcTextureRight)
m_pcTextureRight->GetLevelDesc(0, &sSurfaceDesc);
else if (m_pcTextureRightTest)
m_pcTextureRightTest->GetLevelDesc(0, &sSurfaceDesc);
else ZeroMemory(&sSurfaceDesc, sizeof(D3DSURFACE_DESC));
sTextureSize.w = (int)sSurfaceDesc.Width;
sTextureSize.h = (int)sSurfaceDesc.Height;
// get and set scale and offset
if (m_psFOVPortRight)
ovrHmd_GetRenderScaleAndOffset(*m_psFOVPortRight, sTextureSize, sRenderViewport, UVScaleOffset);
else
ovrHmd_GetRenderScaleAndOffset(m_sDefaultFOVPortRight, sTextureSize, sRenderViewport, UVScaleOffset);
pcDevice->SetVertexShaderConstantF( 0, ( FLOAT* )&UVScaleOffset[0], 1 );
pcDevice->SetVertexShaderConstantF( 2, ( FLOAT* )&UVScaleOffset[1], 1 );
// set stream source, indices, draw
pcDevice->SetStreamSource( 0, m_pcDistortionVertexBufferRight,0, sizeof(ovrDistortionVertex) );
pcDevice->SetIndices( m_pcDistortionIndexBufferRight);
// draw
pcDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0, m_sVertexBufferDescRight.Size / sizeof(ovrDistortionVertex) , 0, m_sIndexBufferDescRight.Size / 6 );
}
pcDevice->EndScene();
// apply and release state block
if (pStateBlock)
{
pStateBlock->Apply();
pStateBlock->Release();
}
// release device if provided by swapchain
if (bReleaseDevice) pcDevice->Release();
return nullptr;
}
示例12: createCleanState
void DevState::createCleanState() {
DWORD dwOldThread = dwMyThread;
if (dwOldThread) {
ods("CreateCleanState from other thread.");
}
dwMyThread = GetCurrentThreadId();
if (pSB)
pSB->Release();
pSB = NULL;
IDirect3DStateBlock9* pStateBlock = NULL;
dev->CreateStateBlock(D3DSBT_ALL, &pStateBlock);
if (! pStateBlock)
return;
pStateBlock->Capture();
dev->CreateStateBlock(D3DSBT_ALL, &pSB);
if (! pSB) {
pStateBlock->Release();
return;
}
D3DVIEWPORT9 vp;
dev->GetViewport(&vp);
dev->SetVertexShader(NULL);
dev->SetPixelShader(NULL);
dev->SetFVF(D3DFVF_TLVERTEX);
dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
dev->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // 0x16
dev->SetRenderState(D3DRS_WRAP0, FALSE); // 0x80
dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
dev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
dev->SetRenderState(D3DRS_ZENABLE, FALSE);
dev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
dev->SetRenderState(D3DRS_COLORVERTEX, FALSE);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
dev->SetRenderState(D3DRS_LIGHTING, FALSE);
pSB->Capture();
pStateBlock->Apply();
pStateBlock->Release();
dwMyThread = dwOldThread;
}
示例13:
void D3D9statemanager::setSamplerStateBlock( DWORD stage, Texture::ClampMode clampmode, Texture::FilterMode filtermode )
{
int hash = stage << 24 | clampmode << 16 | filtermode;
HRESULT hr;
Dict<int,IDirect3DStateBlock9*>::const_iterator it = m_states.find(hash);
if (it != m_states.end()) {
if (m_stageSamplerStates[stage] != it->second) {
V(it->second->Apply());
m_stageSamplerStates[stage] = it->second;
}
return;
}
IDirect3DStateBlock9* state = 0;
d3d9Device->BeginStateBlock();
switch (clampmode) {
case Texture::CM_Clamp:
case Texture::CM_ClampToEdge:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
break;
case Texture::CM_ClampToBorder:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSW, D3DTADDRESS_BORDER);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_BORDERCOLOR, 0);
break;
case Texture::CM_Repeat:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);
}
switch (filtermode) {
case Texture::FM_Nearest:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_POINT);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
break;
case Texture::FM_Linear:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
break;
case Texture::FM_Bilinear:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
break;
case Texture::FM_Trilinear:
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
d3d9StateManager->SetSamplerState(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
break;
}
d3d9Device->EndStateBlock(&state);
m_states[hash] = state;
state->Apply();
m_stageSamplerStates[stage] = state;
}
示例14: GetTickCount
void CDirect3DEvents9::OnPresent ( IDirect3DDevice9 *pDevice )
{
// Start a new scene. This isn't ideal and is not really recommended by MSDN.
// I tried disabling EndScene from GTA and just end it after this code ourselves
// before present, but that caused graphical issues randomly with the sky.
pDevice->BeginScene ();
// Notify core
CCore::GetSingleton ().DoPostFramePulse ();
// Are we allowed to draw the gui?
if ( CCore::GetSingleton ().CanDrawGUI () )
{
// Create a state block.
IDirect3DStateBlock9 * pDeviceState = NULL;
pDevice->CreateStateBlock ( D3DSBT_ALL, &pDeviceState );
// Draw pre-GUI primitives
CGraphics::GetSingleton ().DrawPreGUIQueue ();
// Draw the GUI
CLocalGUI::GetSingleton().Draw ();
// Draw post-GUI primitives
CGraphics::GetSingleton ().DrawPostGUIQueue ();
// Redraw the mouse cursor so it will always be over other elements
CLocalGUI::GetSingleton().DrawMouseCursor();
// Restore the render states
if ( pDeviceState )
{
pDeviceState->Apply ( );
pDeviceState->Release ( );
}
}
// End the scene that we started.
pDevice->EndScene ();
// Make a screenshot if needed
if ( CCore::GetSingleton().bScreenShot ) {
RECT ScreenSize;
D3DLOCKED_RECT LockedRect;
IDirect3DSurface9 *pSurface, *pLockSurface;
// Define a screen rectangle
ScreenSize.top = ScreenSize.left = 0;
ScreenSize.right = CDirect3DData::GetSingleton ().GetViewportWidth ();
ScreenSize.bottom = CDirect3DData::GetSingleton ().GetViewportHeight ();
pDevice->GetRenderTarget ( 0, &pSurface );
// Create a new render target
if ( pDevice->CreateRenderTarget ( ScreenSize.right, ScreenSize.bottom, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &pLockSurface, NULL ) != D3D_OK ) {
CCore::GetSingleton ().GetConsole ()->Printf("Couldn't create a new render target.");
} else {
unsigned long ulBeginTime = GetTickCount ();
// Copy data from surface to surface
if ( pDevice->StretchRect ( pSurface, &ScreenSize, pLockSurface, &ScreenSize, D3DTEXF_NONE ) != D3D_OK ) {
CCore::GetSingleton ().GetConsole ()->Printf("Couldn't copy the surface.");
}
// Lock the surface
if ( pLockSurface->LockRect ( &LockedRect, NULL, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK ) != D3D_OK ) {
CCore::GetSingleton ().GetConsole ()->Printf("Couldn't lock the surface.");
}
// Call the pre-screenshot function
SString strFileName = CScreenShot::PreScreenShot ();
unsigned long ulScreenHeight = ScreenSize.bottom - ScreenSize.top;
unsigned long ulScreenWidth = ScreenSize.right - ScreenSize.left;
// Create rhe screen data buffer
BYTE** ppScreenData = NULL;
ppScreenData = new BYTE* [ ulScreenHeight ];
for ( unsigned short y = 0; y < ulScreenHeight; y++ ) {
ppScreenData[y] = new BYTE [ ulScreenWidth * 4 ];
}
// Copy the surface data into a row-based buffer for libpng
#define BYTESPERPIXEL 4
unsigned long ulLineWidth = ulScreenWidth * 4;
for ( unsigned int i = 0; i < ulScreenHeight; i++ ) {
memcpy ( ppScreenData[i], (BYTE*) LockedRect.pBits + i* LockedRect.Pitch, ulLineWidth );
for ( unsigned int j = 3; j < ulLineWidth; j += BYTESPERPIXEL ) {
ppScreenData[i][j] = 0xFF;
}
}
// Unlock and release the surface
pLockSurface->UnlockRect ();
pLockSurface->Release ();
// Save to png (strip the output alpha channel and read as BGR)
FILE *file = fopen (strFileName, "wb");
png_struct* png_ptr = png_create_write_struct ( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
png_info* info_ptr = png_create_info_struct ( png_ptr );
//.........这里部分代码省略.........
示例15: ImageWriter
void RSManagerDX9::initResources(bool downsampling, unsigned rw, unsigned rh,
unsigned numBBs, D3DFORMAT bbFormat, D3DMULTISAMPLE_TYPE multiSampleType, unsigned multiSampleQuality,
D3DSWAPEFFECT swapEff, bool autoDepthStencil, D3DFORMAT depthStencilFormat) {
if(inited) releaseResources();
SDLOG(0, "RenderstateManager resource initialization started\n");
this->downsampling = downsampling;
renderWidth = rw;
renderHeight = rh;
numBackBuffers = numBBs;
if(bbFormat != D3DFMT_UNKNOWN) backbufferFormat = bbFormat;
swapEffect = swapEff == D3DSWAPEFFECT_COPY ? SWAP_COPY : (swapEff == D3DSWAPEFFECT_DISCARD ? SWAP_DISCARD : SWAP_FLIP);
if(swapEffect == SWAP_FLIP) numBackBuffers++; // account for the "front buffer" in the swap chain
console.initialize(d3ddev, downsampling ? Settings::get().getPresentWidth() : rw, downsampling ? Settings::get().getPresentHeight() : rh);
Console::setLatest(&console);
imgWriter.reset(new ImageWriter(d3ddev, max(rw, max(Settings::get().getRenderWidth(), Settings::get().getPresentWidth())), max(rh, max(Settings::get().getRenderHeight(), Settings::get().getPresentHeight()))));
// performance measurement
console.add(frameTimeText);
perfMonitor.reset(new D3DPerfMonitor(d3ddev, 60));
console.add(traceText);
// store current state temporarily
IDirect3DStateBlock9 *startState;
d3ddev->CreateStateBlock(D3DSBT_ALL, &startState);
// create and capture default state block
d3ddev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
d3ddev->SetRenderState(D3DRS_STENCILENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
d3ddev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
d3ddev->SetRenderState(D3DRS_CLIPPING, FALSE);
d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
d3ddev->SetRenderState(D3DRS_FOGENABLE, FALSE);
d3ddev->CreateStateBlock(D3DSBT_ALL, &initStateBlock);
if(downsampling) {
scaler.reset(new Scaler(d3ddev, rw, rh, Settings::get().getPresentWidth(), Settings::get().getPresentHeight()));
// generate backbuffers
SDLOG(2, "Generating backbuffers:\n")
for(unsigned i = 0; i < numBackBuffers; ++i) {
backBuffers.push_back(rtMan->createTexture(rw, rh, backbufferFormat, multiSampleType, multiSampleQuality));
SDLOG(2, "Backbuffer %u: %p\n", i, backBuffers[i]);
}
// set back buffer 0 as initial rendertarget
d3ddev->SetRenderTarget(0, backBuffers[0]->getSurf());
// generate additional buffer to emulate flip if required
if(swapEffect == SWAP_FLIP && Settings::get().getEmulateFlipBehaviour()) {
extraBuffer = rtMan->createSurface(rw, rh, backbufferFormat);
SDLOG(2, "Extra backbuffer: %p\n", extraBuffer);
}
// if required, determine depth/stencil surf type and create
if(autoDepthStencil) {
d3ddev->CreateDepthStencilSurface(rw, rh, depthStencilFormat, multiSampleType, multiSampleQuality, FALSE, &depthStencilSurf, NULL);
SDLOG(2, "Generated depth stencil surface - format: %s\n", D3DFormatToString(depthStencilFormat));
// set our depth stencil surface
d3ddev->SetDepthStencilSurface(depthStencilSurf);
}
}
plugin = GamePlugin::getPlugin(d3ddev, *this);
plugin->initialize(rw, rh, bbFormat, depthStencilFormat);
// restore initial state
startState->Apply();
startState->Release();
SDLOG(0, "RenderstateManager resource initialization completed\n");
inited = true;
}