// Code from http://msdn.microsoft.com/en-us/library/bb205131(VS.85).aspx#Creating_Empty_Textures ID3D10Texture2D* iD3D10MakeTexture(ID3D10Device *Device, void *Data, ILuint Width, ILuint Height, DXGI_FORMAT Format, ILuint Levels) { ID3D10Texture2D *Texture = NULL; D3D10_TEXTURE2D_DESC Desc; D3D10_SUBRESOURCE_DATA InitialData; Levels; Desc.Width = Width; Desc.Height = Height; Desc.MipLevels = 1; //@TODO: Change for mipmaps. Desc.ArraySize = 1; //@TODO: Change for mipmaps. Desc.Format = Format; Desc.SampleDesc.Count = 1; Desc.Usage = D3D10_USAGE_DEFAULT; Desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; Desc.CPUAccessFlags = 0; // Only need to put the data in initially. InitialData.pSysMem = Data; InitialData.SysMemPitch = 0; InitialData.SysMemSlicePitch = 0; if (FAILED(ID3D10Device_CreateTexture2D(Device, &Desc, &InitialData, &Texture))) return NULL; return Texture; }
static void test_create_texture2d(ID3D10Device *device) { D3D10_TEXTURE2D_DESC desc; ID3D10Texture2D *texture; IDXGISurface *surface; HRESULT hr; desc.Width = 512; desc.Height = 512; desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D10_USAGE_DEFAULT; desc.BindFlags = D3D10_BIND_RENDER_TARGET; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface); ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n"); if (SUCCEEDED(hr)) IDXGISurface_Release(surface); ID3D10Texture2D_Release(texture); desc.MipLevels = 0; hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface); ok(FAILED(hr), "Texture should not implement IDXGISurface\n"); if (SUCCEEDED(hr)) IDXGISurface_Release(surface); ID3D10Texture2D_Release(texture); desc.MipLevels = 1; desc.ArraySize = 2; hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface); ok(FAILED(hr), "Texture should not implement IDXGISurface\n"); if (SUCCEEDED(hr)) IDXGISurface_Release(surface); ID3D10Texture2D_Release(texture); }
static void test_create_rendertarget_view(ID3D10Device *device) { D3D10_RENDER_TARGET_VIEW_DESC rtv_desc; D3D10_TEXTURE2D_DESC texture_desc; D3D10_BUFFER_DESC buffer_desc; ID3D10RenderTargetView *rtview; ID3D10Texture2D *texture; ID3D10Buffer *buffer; HRESULT hr; buffer_desc.ByteWidth = 1024; buffer_desc.Usage = D3D10_USAGE_DEFAULT; buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET; buffer_desc.CPUAccessFlags = 0; buffer_desc.MiscFlags = 0; hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer); ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr); rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER; U(rtv_desc).Buffer.ElementOffset = 0; U(rtv_desc).Buffer.ElementWidth = 64; hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview); ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr); ID3D10RenderTargetView_Release(rtview); ID3D10Buffer_Release(buffer); texture_desc.Width = 512; texture_desc.Height = 512; texture_desc.MipLevels = 1; texture_desc.ArraySize = 1; texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; texture_desc.SampleDesc.Count = 1; texture_desc.SampleDesc.Quality = 0; texture_desc.Usage = D3D10_USAGE_DEFAULT; texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET; texture_desc.CPUAccessFlags = 0; texture_desc.MiscFlags = 0; hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); /* For texture resources it's allowed to specify NULL as desc */ hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview); ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr); ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc); ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format); ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D, "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension); ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice); ID3D10RenderTargetView_Release(rtview); ID3D10Texture2D_Release(texture); }
HRESULT d2d_bitmap_init_memory(struct d2d_bitmap *bitmap, struct d2d_d3d_render_target *render_target, D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc) { D3D10_SUBRESOURCE_DATA resource_data; D3D10_TEXTURE2D_DESC texture_desc; ID3D10ShaderResourceView *view; ID3D10Texture2D *texture; HRESULT hr; if (!format_supported(&desc->pixelFormat)) { WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n", desc->pixelFormat.format, desc->pixelFormat.alphaMode); return D2DERR_UNSUPPORTED_PIXEL_FORMAT; } texture_desc.Width = size.width; texture_desc.Height = size.height; texture_desc.MipLevels = 1; texture_desc.ArraySize = 1; texture_desc.Format = desc->pixelFormat.format; texture_desc.SampleDesc.Count = 1; texture_desc.SampleDesc.Quality = 0; texture_desc.Usage = D3D10_USAGE_DEFAULT; texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; texture_desc.CPUAccessFlags = 0; texture_desc.MiscFlags = 0; resource_data.pSysMem = src_data; resource_data.SysMemPitch = pitch; if (FAILED(hr = ID3D10Device_CreateTexture2D(render_target->device, &texture_desc, src_data ? &resource_data : NULL, &texture))) { ERR("Failed to create texture, hr %#x.\n", hr); return hr; } hr = ID3D10Device_CreateShaderResourceView(render_target->device, (ID3D10Resource *)texture, NULL, &view); ID3D10Texture2D_Release(texture); if (FAILED(hr)) { ERR("Failed to create view, hr %#x.\n", hr); return hr; } d2d_bitmap_init(bitmap, render_target->factory, view, size, desc); ID3D10ShaderResourceView_Release(view); return S_OK; }
static BOOL compare_surface(IDXGISurface *surface, const char *ref_sha1) { D3D10_MAPPED_TEXTURE2D mapped_texture; D3D10_TEXTURE2D_DESC texture_desc; DXGI_SURFACE_DESC surface_desc; ID3D10Resource *src_resource; ID3D10Texture2D *texture; ID3D10Device *device; HRESULT hr; BOOL ret; hr = IDXGISurface_GetDevice(surface, &IID_ID3D10Device, (void **)&device); ok(SUCCEEDED(hr), "Failed to get device, hr %#x.\n", hr); hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Resource, (void **)&src_resource); ok(SUCCEEDED(hr), "Failed to query resource interface, hr %#x.\n", hr); hr = IDXGISurface_GetDesc(surface, &surface_desc); ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr); texture_desc.Width = surface_desc.Width; texture_desc.Height = surface_desc.Height; texture_desc.MipLevels = 1; texture_desc.ArraySize = 1; texture_desc.Format = surface_desc.Format; texture_desc.SampleDesc = surface_desc.SampleDesc; texture_desc.Usage = D3D10_USAGE_STAGING; texture_desc.BindFlags = 0; texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; texture_desc.MiscFlags = 0; hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); ID3D10Device_CopyResource(device, (ID3D10Resource *)texture, src_resource); hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &mapped_texture); ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr); ret = compare_sha1(mapped_texture.pData, mapped_texture.RowPitch, 4, texture_desc.Width, texture_desc.Height, ref_sha1); ID3D10Texture2D_Unmap(texture, 0); ID3D10Texture2D_Release(texture); ID3D10Resource_Release(src_resource); ID3D10Device_Release(device); return ret; }