| 4926 | } |
| 4927 | |
| 4928 | static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) |
| 4929 | { |
| 4930 | if (BackbufferRatio::Count != _ratio) |
| 4931 | { |
| 4932 | _width = uint16_t(s_ctx->m_init.resolution.width); |
| 4933 | _height = uint16_t(s_ctx->m_init.resolution.height); |
| 4934 | getTextureSizeFromRatio(_ratio, _width, _height); |
| 4935 | } |
| 4936 | |
| 4937 | bx::ErrorAssert err; |
| 4938 | isTextureValid(_width, _height, 0, false, _numLayers, _format, _flags, &err); |
| 4939 | |
| 4940 | if (!err.isOk() ) |
| 4941 | { |
| 4942 | return BGFX_INVALID_HANDLE; |
| 4943 | } |
| 4944 | |
| 4945 | const uint8_t numMips = calcNumMips(_hasMips, _width, _height); |
| 4946 | _numLayers = bx::max<uint16_t>(_numLayers, 1); |
| 4947 | |
| 4948 | if (BX_ENABLED(BGFX_CONFIG_DEBUG) |
| 4949 | && NULL != _mem) |
| 4950 | { |
| 4951 | TextureInfo ti; |
| 4952 | calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format); |
| 4953 | BX_ASSERT(ti.storageSize == _mem->size |
| 4954 | , "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" |
| 4955 | , ti.storageSize |
| 4956 | , _mem->size |
| 4957 | ); |
| 4958 | } |
| 4959 | |
| 4960 | uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate); |
| 4961 | const Memory* mem = alloc(size); |
| 4962 | |
| 4963 | bx::StaticMemoryBlockWriter writer(mem->data, mem->size); |
| 4964 | bx::write(&writer, kChunkMagicTex, bx::ErrorAssert{}); |
| 4965 | |
| 4966 | TextureCreate tc; |
| 4967 | tc.m_width = _width; |
| 4968 | tc.m_height = _height; |
| 4969 | tc.m_depth = 0; |
| 4970 | tc.m_numLayers = _numLayers; |
| 4971 | tc.m_numMips = numMips; |
| 4972 | tc.m_format = _format; |
| 4973 | tc.m_cubeMap = false; |
| 4974 | tc.m_mem = _mem; |
| 4975 | bx::write(&writer, tc, bx::ErrorAssert{}); |
| 4976 | |
| 4977 | return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio, NULL != _mem); |
| 4978 | } |
| 4979 | |
| 4980 | TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) |
| 4981 | { |
no test coverage detected