void TBBitmapFragmentManager::SetDefaultMapSize(int w, int h) { assert(TBGetNearestPowerOfTwo(w) == w); assert(TBGetNearestPowerOfTwo(h) == h); m_default_map_w = w; m_default_map_h = h; }
TBBitmapFragment *TBBitmapFragmentManager::CreateNewFragment(const TBID &id, bool dedicated_map, int data_w, int data_h, int data_stride, uint32 *data) { assert(!GetFragment(id)); TBBitmapFragment *frag = nullptr; // Create a fragment in any of the fragment maps. Doing it in the reverse order // would be faster since it's most likely to succeed, but we want to maximize // the amount of fragments per map, so do it in the creation order. if (!dedicated_map) { for (int i = 0; i < m_fragment_maps.GetNumItems(); i++) { if ((frag = m_fragment_maps[i]->CreateNewFragment(data_w, data_h, data_stride, data, m_add_border))) break; } } // If we couldn't create the fragment in any map, create a new map where we know it will fit. bool allow_another_map = (m_num_maps_limit == 0 || m_fragment_maps.GetNumItems() < m_num_maps_limit); if (!frag && allow_another_map && m_fragment_maps.GrowIfNeeded()) { int po2w = TBGetNearestPowerOfTwo(MAX(data_w, m_default_map_w)); int po2h = TBGetNearestPowerOfTwo(MAX(data_h, m_default_map_h)); if (dedicated_map) { po2w = TBGetNearestPowerOfTwo(data_w); po2h = TBGetNearestPowerOfTwo(data_h); } TBBitmapFragmentMap *fm = new TBBitmapFragmentMap(); if (fm && fm->Init(po2w, po2h)) { m_fragment_maps.Add(fm); frag = fm->CreateNewFragment(data_w, data_h, data_stride, data, m_add_border); } else delete fm; } // Finally, add the new fragment to the hash. if (frag && m_fragments.Add(id, frag)) { frag->m_id = id; return frag; } delete frag; return nullptr; }
bool TBBitmapGL::Init(int width, int height, uint32 *data) { assert(width == TBGetNearestPowerOfTwo(width)); assert(height == TBGetNearestPowerOfTwo(height)); m_w = width; m_h = height; glGenTextures(1, &m_texture); BindBitmap(this); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); SetData(data); return true; }