MCPcopy Create free account
hub / github.com/crownengine/crown / createTexture2D

Function createTexture2D

3rdparty/bgfx/src/bgfx.cpp:4928–4978  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 4

initMethod · 0.85
createFrameBufferFunction · 0.85
createMethod · 0.85
resetMethod · 0.85

Calls 7

getTextureSizeFromRatioFunction · 0.85
isTextureValidFunction · 0.85
calcTextureSizeFunction · 0.85
allocFunction · 0.85
calcNumMipsFunction · 0.70
writeFunction · 0.70
createTextureMethod · 0.45

Tested by

no test coverage detected