Visje

Member
  • Content count

    21
  • Joined

  • Last visited

Community Reputation

109 Neutral

About Visje

  • Rank
    Member
  1. Thanks Erik, I just came across [url="http://www.gamedev.net/topic/583161-d3d11-creating-a-dynamic-texture/"]this[/url] topic where I found what I was looking for. I'm just trying now to convert Byte into UINT32, if you have an idea on how to do it ?
  2. Hey guys, I'm trying to do a water like effect like this one : (Processing uses a Java-Like langage) [url="http://www.openprocessing.org/sketch/43543"]http://www.openproce...rg/sketch/43543[/url] The thing is that it works by replacing the color of one pixel from the texture on the back by another one when the pointer of the mouse is moved. So my question is, do you know how I can get all the pixels from a texture and change their colors as I like (and not just a single pixel like in the Pixel Shader) ? I have initialized and displayed a "ID3D11Texture2D", so I'm wondering if I can get the pixels from this texture... Thanks [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
  3. DirectX11 mip mapping

    I'll do that. Thanks
  4. DirectX11 mip mapping

    Alright, it works fine ! The game is not lagging and the colors and textures are alright with a mipLevel of 0. Thank you so much Erik !! The only thing remaining is that it's still lagging a bit on the menu where I wanted the mip mapping applied; do I have to call a particular function like GenerateMips on frameTime or I can't do anything about it ?
  5. DirectX11 mip mapping

    The textures are static, I'll try this and hope it won't be so laggy, because it's unplayable right now.
  6. DirectX11 mip mapping

    Yaaay I just got it to work ! The problem is now that it's incredibly laggy... maybe because I do the UpdateSubresource + generateMips each frame... ?
  7. DirectX11 mip mapping

    Ok. First I create the texture with a call to Basic Loader, then I get the size of the texture + texture & textureView into my class : [CODE] BasicLoader^ loader = ref new BasicLoader(m_d3dDevice.Get()); loader->LoadTexture(fileName_, &texture, &textureView); D3D11_TEXTURE2D_DESC textDesc; texture->GetDesc(&textDesc); w = textDesc.Width; h = textDesc.Height; contentSize.width = w; contentSize.height = h; [/CODE] Inside the BasicLoader, this is what I do (important part only) : [CODE] D3D11_TEXTURE2D_DESC textureDesc; ZeroMemory( &textureDesc, sizeof(textureDesc) ); textureDesc.Width = width; textureDesc.Height = height; textureDesc.MipLevels = 0; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; textureDesc.SampleDesc.Count = 1; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; HRESULT hr = m_d3dDevice->CreateTexture2D( &textureDesc, NULL, &texture2D ); [/CODE] And at each frame, I make a call to a function that contains the "updateSubResource" & the GenerateMips: [CODE] D3D11_BOX destBox; destBox.left = 0; destBox.right = this->contentSize.width; destBox.top = 0; destBox.bottom = this->contentSize.height; destBox.front = 0; destBox.back = 1; ComPtr<IWICFormatConverter> formatConverter; Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory; if (m_wicFactory.Get() == nullptr) { DX::ThrowIfFailed( CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_wicFactory) ) ); } DX::ThrowIfFailed( m_wicFactory->CreateFormatConverter(&formatConverter) ); int taille = this->contentSize.width * this->contentSize.height * 4; std::unique_ptr<byte[]> bitmapPixels(new byte[taille]); // ************* THE PROGRAM IS CRASHING HERE; IF I DON'T PUT THIS, IT'S NOT CRASHING BUT THE TEXTURES ARE NOT DISPLAYED ! ************* DX::ThrowIfFailed( formatConverter->CopyPixels( nullptr, this->contentSize.width * 4, this->contentSize.width * this->contentSize.height * 4, bitmapPixels.get() ) ); // *********************************************************************************************************************************************** m_d3dDeviceContext->UpdateSubresource( this->texture.Get(), // the texture to update 0, // first mip-level &destBox, // position of the pixels to update in the texture bitmapPixels.get(), // image data this->contentSize.width * 4, // row pitch 0 // not used for 2D textures ); m_d3dDeviceContext->GenerateMips(this->textureView.Get()); [/CODE] There's a comment line in CAPITALS for you upward.
  8. DirectX11 mip mapping

    So I've managed to get it to work, the code compiles and the app launches but none of my textures are displayed :/ instead I get some weird white squares (the colored background should also be textured): [img]http://tof.canardpc.com/view/0b7c0557-a3a7-4730-aed7-0a199b6484a9.jpg[/img]
  9. DirectX11 mip mapping

    Okay, I made this : [CODE] D3D11_BOX destBox; destBox.left = 0; destBox.right = width; destBox.top = 0; destBox.bottom = height; destBox.front = 0; destBox.back = 1; std::unique_ptr<byte[]> bitmapPixels(new byte[width * height * 4]); m_d3dDeviceContext->UpdateSubresource( this->texture.Get(), // the texture to update 0, // first mip-level &destBox, // position of the pixels to update in the texture bitmapPixels.get(), // image data width * 4, // row pitch 0 // not used for 2D textures ); m_d3dDeviceContext->GenerateMips(this->textureView.Get()); [/CODE] It still does'nt work but gives me another error, I'll try to find what's wrong and tell you how it goes.
  10. DirectX11 mip mapping

    Wow big answer there, thanks ! "I got the impression that this is what you want, for D3D to automatically generate your mipmaps for you." - Yep that is exactly what I want. "I believe D3DX11CreateTextureFromMemory does this automatically for you" - As I'm doing a Metro application, I can't use this library :/ "The other option is to let D3D generate mipmaps with D3D11_RESOURCE_MISC_GENERATE_MIPS." - I'll try this one because it's not so different from my base code. "Is your goal to do this during a game-frame, and automatically have mipmaps generated for your new texture?" - Yes, as the object get far from the camera I want the mip map to update to a lower resolution texture in the better case I'll try with the UpdateSubresource method and tell you if all works properly. Thanks again mate !
  11. DirectX11 mip mapping

    Hi Erik, I passed NULL to CreateTexture2D and all became black as expected, then at each frame I call this codeto render my textures : [CODE] m_d3dDeviceContext->UpdateSubresource( m_constantBuffer.Get(), 0, nullptr, &(m_constantBufferData), 0, 0 ); [/CODE] I don't know if I should put this function just after the createTexture, or if I must change the parameters of it... nvertheless it still is'nt working :/ MJP : I did what you told me but I still got the problem ><, I'm kind of a noob on this one Here's the code if interested : [CODE] D3D11_SUBRESOURCE_DATA* initData(new D3D11_SUBRESOURCE_DATA[3 * 3]); initData[0].pSysMem = bitmapPixels.get(); initData[0].SysMemPitch = width * 4; initData[0].SysMemSlicePitch = 0; initData[1].pSysMem = bitmapPixels.get(); initData[1].SysMemPitch = width * 4; initData[1].SysMemSlicePitch = 0; initData[2].pSysMem = bitmapPixels.get(); initData[2].SysMemPitch = width * 4; initData[2].SysMemSlicePitch = 0; D3D11_TEXTURE2D_DESC textureDesc; ZeroMemory( &textureDesc, sizeof(textureDesc) ); textureDesc.Width = width; textureDesc.Height = height; textureDesc.MipLevels = 0; // PROBLEM WITH THIS textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; textureDesc.SampleDesc.Count = 1; textureDesc.Usage = D3D11_USAGE_IMMUTABLE; // PROBLEM HERE ALSO textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; HRESULT hr = m_d3dDevice->CreateTexture2D( &textureDesc, initData, &texture2D ); [/CODE] Thanks again for your help guys
  12. DirectX11 mip mapping

    That's how I initialize initialData : [CODE] D3D11_SUBRESOURCE_DATA initialData; ZeroMemory(&initialData, sizeof(initialData)); initialData.pSysMem = bitmapPixels.get(); initialData.SysMemPitch = width * 4; initialData.SysMemSlicePitch = 0; [/CODE] "Skip using initialData and instead upload the first mip-level using UpdateSubResource." humm... how can I do that ? :s
  13. DirectX11 mip mapping

    I did this : [CODE] HRESULT hr = m_d3dDevice->CreateTexture2D( &textureDesc, &initialData, &texture2D ); [/CODE] but I get an error inside "CreateTexture2D", thus I cannot check the error code of HRESULT :/
  14. DirectX11 mip mapping

    I actually already have the "D3D11_CREATE_DEVICE_BGRA_SUPPORT" flag. I changed the format to R8G8B8A8 and did the quick fix in the Pixel Shader, the game works fine but I still get an error when I set MipLevels to 0, I'll try with the HRESULT. Just for info, I'm working on a Metro app.