| 72 | } // namespace |
| 73 | |
| 74 | Texture::Texture( |
| 75 | ref<Device> pDevice, |
| 76 | Type type, |
| 77 | ResourceFormat format, |
| 78 | uint32_t width, |
| 79 | uint32_t height, |
| 80 | uint32_t depth, |
| 81 | uint32_t arraySize, |
| 82 | uint32_t mipLevels, |
| 83 | uint32_t sampleCount, |
| 84 | ResourceBindFlags bindFlags, |
| 85 | const void* pInitData |
| 86 | ) |
| 87 | : Resource(std::move(pDevice), type, bindFlags, 0) |
| 88 | , mFormat(format) |
| 89 | , mWidth(width) |
| 90 | , mHeight(height) |
| 91 | , mDepth(depth) |
| 92 | , mMipLevels(mipLevels) |
| 93 | , mArraySize(arraySize) |
| 94 | , mSampleCount(sampleCount) |
| 95 | { |
| 96 | FALCOR_ASSERT(mType != Type::Buffer); |
| 97 | FALCOR_ASSERT(mFormat != ResourceFormat::Unknown); |
| 98 | FALCOR_ASSERT(mWidth > 0 && mHeight > 0 && mDepth > 0); |
| 99 | switch (mType) |
| 100 | { |
| 101 | case Resource::Type::Texture1D: |
| 102 | FALCOR_ASSERT(mHeight == 1 && mDepth == 1 && mSampleCount == 1); |
| 103 | break; |
| 104 | case Resource::Type::Texture2D: |
| 105 | FALCOR_ASSERT(mDepth == 1 && mSampleCount == 1); |
| 106 | break; |
| 107 | case Resource::Type::Texture2DMultisample: |
| 108 | FALCOR_ASSERT(mDepth == 1); |
| 109 | break; |
| 110 | case Resource::Type::Texture3D: |
| 111 | FALCOR_ASSERT(mSampleCount == 1); |
| 112 | break; |
| 113 | case Resource::Type::TextureCube: |
| 114 | FALCOR_ASSERT(mDepth == 1 && mSampleCount == 1); |
| 115 | break; |
| 116 | default: |
| 117 | FALCOR_UNREACHABLE(); |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | FALCOR_ASSERT(mArraySize > 0 && mMipLevels > 0 && mSampleCount > 0); |
| 122 | |
| 123 | bool autoGenerateMips = pInitData && (mMipLevels == Texture::kMaxPossible); |
| 124 | |
| 125 | if (autoGenerateMips) |
| 126 | mBindFlags |= ResourceBindFlags::RenderTarget; |
| 127 | |
| 128 | if (mMipLevels == kMaxPossible) |
| 129 | { |
| 130 | uint32_t dims = width | height | depth; |
| 131 | mMipLevels = bitScanReverse(dims) + 1; |
nothing calls this directly
no test coverage detected