HRESULT RSManager::redirectDrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) { if(hudStarted && hideHud) { IDirect3DBaseTexture9 *t; d3ddev->GetTexture(0, &t); bool hide = isTextureText(t); hide = hide || isTextureButtonsEffects(t); hide = hide || isTextureHudEffectIcons(t); t->Release(); if(hide) return D3D_OK; } if(pausedHudRT) { IDirect3DBaseTexture9 *t; d3ddev->GetTexture(0, &t); bool isText = isTextureText(t); SDLOG(4, "On HUD, PAUSED, redirectDrawPrimitiveUP texture: %s\n", getTextureName(t)); t->Release(); //// Print vertices //SDLOG(0, "Vertices: \n"); //INT16 *values = (INT16*)pVertexStreamZeroData; //for(size_t i=0; i<PrimitiveCount+2; ++i) { // SDLOG(0, "%8hd, ", values[i]); // if((i+1)%2 == 0) SDLOG(0, "; "); // if((i+1)%8 == 0) SDLOG(0, "\n"); //} if(isText && PrimitiveCount >= 12) resumeHudRendering(); } bool subbed = false; if(onHudRT) { IDirect3DBaseTexture9 *t; d3ddev->GetTexture(0, &t); bool isText = isTextureText(t); bool isSub = isTextureText00(t); SDLOG(4, "On HUD, redirectDrawPrimitiveUP texture: %s\n", getTextureName(t)); t->Release(); //if(isText && PrimitiveCount <= 10) pauseHudRendering(); if(isSub) { pauseHudRendering(); subbed = true; } } HRESULT hr = d3ddev->DrawPrimitiveUP(PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride); if(subbed) resumeHudRendering(); //if(onHudRT) { // if(takeScreenshot) dumpSurface("HUD_PrimUP", rgbaBuffer1Surf); //} return hr; }
void CState::Restore() { // viewport m_D3DDev->SetViewport(&m_Vp); // render states m_D3DDev->SetRenderState(D3DRS_ZENABLE, m_Z); m_D3DDev->SetRenderState(D3DRS_CULLMODE, m_CullMode); m_D3DDev->SetRenderState(D3DRS_ALPHATESTENABLE, m_AlphaTest); m_D3DDev->SetRenderState(D3DRS_ALPHABLENDENABLE, m_AlphaBlend); m_D3DDev->SetRenderState(D3DRS_BLENDOP, m_BlendOp); m_D3DDev->SetRenderState(D3DRS_SRCBLEND, m_SrcBlend); m_D3DDev->SetRenderState(D3DRS_DESTBLEND, m_DstBlend); m_D3DDev->SetRenderState(D3DRS_CLIPPLANEENABLE, m_ClipPlane); m_D3DDev->SetRenderState(D3DRS_FILLMODE, m_FillMode); m_D3DDev->SetRenderState(D3DRS_LASTPIXEL, m_LastPixel); m_D3DDev->SetRenderState(D3DRS_FOGENABLE, m_Fog); m_D3DDev->SetRenderState(D3DRS_STENCILENABLE, m_Stencil); m_D3DDev->SetRenderState(D3DRS_COLORWRITEENABLE, m_ColorWrite); m_D3DDev->SetRenderState(D3DRS_SCISSORTESTENABLE, m_Scissor); if( m_Caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND ) m_D3DDev->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, m_SeparateAlphaBlend); //if( m_Caps.LineCaps & D3DLINECAPS_ANTIALIAS ) m_D3DDev->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, m_AntiAliasedLine); // primitive m_D3DDev->SetFVF(m_FVF); m_D3DDev->SetStreamSource(0, m_StreamData, m_StreamOffset, m_StreamStride); if( m_StreamData ) m_StreamData->Release(); m_D3DDev->SetVertexShader(m_VertexShader); if( m_VertexShader ) m_VertexShader->Release(); // texture m_D3DDev->SetTexture(0, m_Tex); if( m_Tex ) m_Tex->Release(); m_D3DDev->SetPixelShader(m_PixelShader); if( m_PixelShader ) m_PixelShader->Release(); // texture stage states m_D3DDev->SetTextureStageState(0, D3DTSS_COLOROP, m_ColorOp); m_D3DDev->SetTextureStageState(0, D3DTSS_COLORARG1, m_ColorArg1); m_D3DDev->SetTextureStageState(0, D3DTSS_COLORARG2, m_ColorArg2); m_D3DDev->SetTextureStageState(0, D3DTSS_ALPHAOP, m_AlphaOp); m_D3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, m_AlphaArg1); m_D3DDev->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, m_TexCoordIndex); m_D3DDev->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, m_TexTransfFlags); m_D3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, m_AddressU); m_D3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, m_AddressV); m_D3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, m_MagFilter); m_D3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, m_MinFilter); m_D3DDev->SetSamplerState(0, D3DSAMP_MIPFILTER, m_MipFilter); }
/// \param textureName Name of texture you want to set in the effect file. /// \param index Texture index to set. This is pulled from the DirectX device. void Effect::setTextureFromDevice(const std::string &textureName, int index) { if (!m_pEffect) return; IDirect3DBaseTexture9* pTexture; // get texture from device pD3DDevice->GetTexture(index,&pTexture); // pass texture to effect file m_pEffect->SetTexture(textureName.c_str(), pTexture); pTexture->Release(); return; }
void TextureDX9::Disable(const unsigned int texUnit) const { IDirect3DDevice9* device = RendererDX9::GetInstance()->GetDevice(); HRESULT hr; #ifdef _DEBUG IDirect3DBaseTexture9* activeTex = nullptr; hr = device->GetTexture(texUnit, &activeTex); assert(SUCCEEDED(hr)); assert(activeTex == m_pTexture); unsigned int refCount = 1; refCount = activeTex->Release(); assert(refCount == 1); #endif hr = device->SetTexture(texUnit, 0); assert(SUCCEEDED(hr)); }
//---------------------------------------------------------------------------- void PdrTextureCube::Disable (Renderer* renderer, int textureUnit) { IDirect3DDevice9* device = renderer->mData->mDevice; HRESULT hr; PX2_UNUSED(hr); #ifdef PX2_PDR_DEBUG // 检测需要被取消激活的数据,是否匹配。 IDirect3DBaseTexture9 *activeTexture = 0; hr = device->GetTexture(textureUnit, &activeTexture); assertion(hr == D3D_OK, "Failed to get cube texture, unit %d: %s\n", textureUnit, DXGetErrorString(hr)); assertion(activeTexture == mTexture, "Mismatched textures\n"); activeTexture->Release(); #endif hr = device->SetTexture(textureUnit, 0); assertion(hr == D3D_OK, "Failed to disable cube texture, unit %d: %s\n", textureUnit, DXGetErrorString(hr)); }
//---------------------------------------------------------------------------- void PdrTexture3D::Disable (Renderer* renderer, int textureUnit) { IDirect3DDevice9* device = renderer->mData->mDevice; HRESULT hr; WM5_UNUSED(hr); #ifdef WM5_PDR_DEBUG // Verify that the active texture is the one making the disable request. IDirect3DBaseTexture9 *activeTexture = 0; hr = device->GetTexture(textureUnit, &activeTexture); assertion(hr == D3D_OK, "Failed to get 3D texture, unit %d: %s\n", textureUnit, DXGetErrorString(hr)); assertion(activeTexture == mTexture, "Mismatched textures\n"); activeTexture->Release(); #endif // Disable the texture by clearing the state. hr = device->SetTexture(textureUnit, 0); assertion(hr == D3D_OK, "Failed to disable 3D texture, unit %d: %s\n", textureUnit, DXGetErrorString(hr)); }
void RageDisplay_D3D::SendCurrentMatrices() { RageMatrix m; RageMatrixMultiply( &m, GetCentering(), GetProjectionTop() ); /* Convert to OpenGL-style "pixel-centered" coords */ RageMatrix m2 = GetCenteringMatrix( -0.5f, -0.5f, 0, 0 ); RageMatrix projection; RageMatrixMultiply( &projection, &m2, &m ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX*)&projection ); g_pd3dDevice->SetTransform( D3DTS_VIEW, (D3DMATRIX*)GetViewTop() ); g_pd3dDevice->SetTransform( D3DTS_WORLD, (D3DMATRIX*)GetWorldTop() ); for( unsigned tu = 0; tu < 2; tu++ ) { // Optimization opportunity: Turn off texture transform if not using texture coords. g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); // If no texture is set for this texture unit, don't bother setting it up. IDirect3DBaseTexture9* pTexture = NULL; g_pd3dDevice->GetTexture( tu, &pTexture ); if( pTexture == NULL ) continue; pTexture->Release(); if( g_bSphereMapping[tu] ) { static const RageMatrix tex = RageMatrix ( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 1.0f ); g_pd3dDevice->SetTransform( (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+tu), (D3DMATRIX*)&tex ); // Tell D3D to use transformed reflection vectors as texture co-ordinate 0 // and then transform this coordinate by the specified texture matrix. g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR ); } else { /* * Direct3D is expecting a 3x3 matrix loaded into the 4x4 in order to transform * the 2-component texture coordinates. We currently only use translate and scale, * and ignore the z component entirely, so convert the texture matrix from * 4x4 to 3x3 by dropping z. */ const RageMatrix &tex1 = *GetTextureTop(); const RageMatrix tex2 = RageMatrix ( tex1.m[0][0], tex1.m[0][1], tex1.m[0][3], 0, tex1.m[1][0], tex1.m[1][1], tex1.m[1][3], 0, tex1.m[3][0], tex1.m[3][1], tex1.m[3][3], 0, 0, 0, 0, 0 ); g_pd3dDevice->SetTransform( D3DTRANSFORMSTATETYPE(D3DTS_TEXTURE0+tu), (D3DMATRIX*)&tex2 ); g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU ); } } }
HRESULT RSManager::redirectDrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) { //if(onHudRT) { // SDLOG(0, "HUD render: primitive type: %d, MinIndex: %u, NumVertices: %u, PrimitiveCount: %u, IndexDataFormat: %s\n", PrimitiveType, MinIndex, NumVertices, PrimitiveCount, D3DFormatToString(IndexDataFormat)); // // Print vertex decl type // IDirect3DVertexDeclaration9* vDecl; // d3ddev->GetVertexDeclaration(&vDecl); // D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]; // UINT numElements; // vDecl->GetDeclaration(decl, &numElements); // for(size_t i=0; i<numElements; ++i) { // SDLOG(0, "element %u -- stream: %d, offset: %d, type: %s, usage: %s\n", i, decl->Stream, decl->Offset, D3DDeclTypeToString((D3DDECLTYPE)decl->Type), D3DDeclUsageToString((D3DDECLUSAGE)decl->Usage)); // } // vDecl->Release(); // // // Print indices // //SDLOG(0, "Indices: \n"); // //INT16 *indices = (INT16*)pIndexData; // //for(size_t i=0; i<PrimitiveCount+2; ++i) { // // SDLOG(0, "%8hd, ", indices[i]); // //} // //SDLOG(0, "\n"); // // Print vertices // SDLOG(0, "Vertices: \n"); // INT16 *values = (INT16*)pVertexStreamZeroData; // for(size_t i=0; i<NumVertices*4*2; ++i) { // SDLOG(0, "%8hd, ", values[i]); // if((i+1)%2 == 0) SDLOG(0, "; "); // if((i+1)%8 == 0) SDLOG(0, "\n"); // } // //return d3ddev->DrawIndexedPrimitiveUP(PrimitiveType, MinIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, hudVertices, VertexStreamZeroStride); //} if(hudStarted && hideHud) { return D3D_OK; } bool isTargetIndicator = false; if(pausedHudRT) { IDirect3DBaseTexture9 *t; d3ddev->GetTexture(0, &t); // check for target indicator if(isTextureHudHealthbar(t)) { INT16 *vertices = (INT16*)pVertexStreamZeroData; if(vertices[3] > -2000) { resumeHudRendering(); } } else { resumeHudRendering(); } t->Release(); } if(onHudRT) { IDirect3DBaseTexture9 *t; d3ddev->GetTexture(0, &t); SDLOG(4, "On HUD, redirectDrawIndexedPrimitiveUP texture: %s\n", getTextureName(t)); if((hddp < 5 && isTextureHudHealthbar(t)) || (hddp >= 5 && hddp < 7 && isTextureCategoryIconsHumanityCount(t)) || (hddp>=7 && !isTextureCategoryIconsHumanityCount(t))) hddp++; // check for target indicator if(isTextureHudHealthbar(t)) { INT16 *vertices = (INT16*)pVertexStreamZeroData; if(vertices[3] < -2000) { isTargetIndicator = true; pauseHudRendering(); } } t->Release(); if(hddp == 8) { finishHudRendering(); } else if(!isTargetIndicator) { //d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA); //d3ddev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD); //d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); //d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT); } } HRESULT hr = d3ddev->DrawIndexedPrimitiveUP(PrimitiveType, MinIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); //if(onHudRT) { // if(takeScreenshot) dumpSurface("HUD_IndexPrimUP", rgbaBuffer1Surf); //} return hr; }