Git Product home page Git Product logo

ddspp's Introduction

DDS++

DDS image readers are typically not multiplatform and pull in many extra headers (e.g. the fantastic gli or Microsoft DirectXTex) This single no-dependency header can decode and encode the DDS headers and compute the mipmap and slice offset of a given DDS texture. It is meant as an aid to provide this information directly to graphics APIs to upload data to the GPU.

Usage

The code below is not meant to be an exhaustive example on how to create textures from a DDS file, merely a guideline of how you would go about using this in your own engine/API.

#include "ddspp.h"

// Load image as a stream of bytes
const char* ddsData = ...

// Decode header and get pointer to initial data
ddspp::Descriptor desc;
ddspp::Result decodeResult = ddspp::decode_header(ddsData, desc);

// Feed to the graphics API
if(decodeResult == ddspp::Success)
{
    const char* initialData = ddsData + desc.headerSize;

    // D3D example
    {
        D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
        srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
        srvDesc.Format = desc.format; // Maps directly to D3D
        if(desc.type == ddspp::Texture2D)
        {
            if(desc.arraySize > 1)
            {
                srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
                srvDesc.Texture2DArray.MipLevels = desc.numMips;
                srvDesc.Texture2DArray.ArraySize = desc.arraySize;
            }
            else
            {
                srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
                srvDesc.Texture2D.MipLevels = desc.mipMapCount;
            }
        }
        // ... Fill in the rest
    }

    // Vulkan Example
    {
        VkImageCreateInfo imageCreateInfo = {};
        imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
        imageCreateInfo.pNext = nullptr;
        imageCreateInfo.format = GetVulkanFormat(desc.format); // Translate DXGI format to Vulkan
        imageCreateInfo.extent = { desc.width, desc.height, desc.depth };
        imageCreateInfo.mipLevels = desc.numMips;
        imageCreateInfo.arrayLayers = desc.arraySize;
        if(desc.type == ddspp::Texture2D)
        {
            imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
        }
        // ... Fill in the rest
    }
}

ddspp's People

Contributors

redorav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ddspp's Issues

DXGI_Texture1D extents issue

Perhaps I'm missing something, but shouldn't this be height and depth? Not width?

case DXGI_Texture1D:
	desc.width = desc.height = 1;
	desc.type = Texture1D;
	break;

Row pitch for other mip levels

Does ddspp provide the row pitch for mipmap levels beyond the first one (level 0) directly?

If not, do you know how to calculate that from the information inside Descriptor?

Edit: I am trying to load a BC7 compressed texture with mipmaps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.