ID3D11ShaderResourceView *D3D11_Image_View(const texid_t id) { if (!id || !id->ptr) return NULL; if (!id->ptr2) ID3D11Device_CreateShaderResourceView(pD3DDev11, (ID3D11Resource *)id->ptr, NULL, (ID3D11ShaderResourceView**)&id->ptr2); return id->ptr2; }
texid_t D3D11_GetShadowMap(int id) { texid_t tex = &shadowmap_texture[id]; if (!tex->ptr) { return r_nulltex; } if (!tex->ptr2) { D3D11_SHADER_RESOURCE_VIEW_DESC desc; desc.Format = shadowfmts[shadowfmt][0]; desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; desc.Texture2D.MostDetailedMip = 0; desc.Texture2D.MipLevels = -1; ID3D11Device_CreateShaderResourceView(pD3DDev11, (ID3D11Resource *)tex->ptr, &desc, (ID3D11ShaderResourceView**)&tex->ptr2); } return tex; }
sgui_ctx_wm* d3d11_wm_create( sgui_window* wnd ) { D3D11_SHADER_RESOURCE_VIEW_DESC rvdesc; D3D11_SAMPLER_DESC sampdesc; D3D11_SUBRESOURCE_DATA data; unsigned int width, height; D3D11_TEXTURE2D_DESC desc; sgui_d3d11_context* ctx; sgui_subwm_skin* skin; sgui_d3d11_wm* this; sgui_ctx_wm* super; HRESULT status; ctx = (sgui_d3d11_context*)sgui_window_get_context( wnd ); if( !ctx ) return NULL; this = calloc( 1, sizeof(sgui_d3d11_wm) ); super = (sgui_ctx_wm*)this; if( !this ) return NULL; memset( &desc, 0, sizeof(desc) ); memset( &data, 0, sizeof(data) ); memset( &rvdesc, 0, sizeof(rvdesc) ); memset( &sampdesc, 0, sizeof(sampdesc) ); skin = sgui_subwm_skin_get( ); skin->get_ctx_skin_texture_size( skin, &width, &height ); desc.Width = width; desc.Height = height; desc.MipLevels = 1; desc.ArraySize = 1; desc.SampleDesc.Count = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.Usage = D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; data.pSysMem = skin->get_ctx_skin_texture( skin ); data.SysMemPitch = width*4; rvdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; rvdesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; rvdesc.Texture2D.MipLevels = 1; sampdesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; sampdesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampdesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampdesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampdesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; status = ID3D11Device_CreateTexture2D( ctx->dev, &desc, &data, &this->skintex ); if( status!=S_OK || !this->skintex ) goto fail; status = ID3D11Device_CreateShaderResourceView( ctx->dev, (void*)this->skintex, &rvdesc, &this->view ); if( status!=S_OK || !this->view ) goto failtex; status = ID3D11Device_CreateSamplerState( ctx->dev, &sampdesc, &this->sampler ); if( status!=S_OK || !this->sampler ) goto failview; /* init */ super->wnd = wnd; super->draw_gui = d3d11_wm_draw_gui; super->destroy = d3d11_wm_destroy; return super; failview: ID3D11ShaderResourceView_Release( this->view ); failtex: ID3D11Texture2D_Release( this->skintex ); fail: free( this ); return NULL; }