| 160 | } |
| 161 | |
| 162 | void TileMapAtlas::updateAtlasValueAt(const Vec2& pos, const Color3B& value, int index) |
| 163 | { |
| 164 | AXASSERT(index >= 0 && index < _textureAtlas->getCapacity(), "updateAtlasValueAt: Invalid index"); |
| 165 | |
| 166 | V3F_C4B_T2F_Quad* quad = &((_textureAtlas->getQuads())[index]); |
| 167 | |
| 168 | int x = pos.x; |
| 169 | int y = pos.y; |
| 170 | float row = (float)(value.r % _itemsPerRow); |
| 171 | float col = (float)(value.r / _itemsPerRow); |
| 172 | |
| 173 | float textureWide = (float)(_textureAtlas->getTexture()->getPixelsWide()); |
| 174 | float textureHigh = (float)(_textureAtlas->getTexture()->getPixelsHigh()); |
| 175 | |
| 176 | float itemWidthInPixels = _itemWidth * AX_CONTENT_SCALE_FACTOR(); |
| 177 | float itemHeightInPixels = _itemHeight * AX_CONTENT_SCALE_FACTOR(); |
| 178 | |
| 179 | #if AX_FIX_ARTIFACTS_BY_STRECHING_TEXEL |
| 180 | float left = (2 * row * itemWidthInPixels + 1) / (2 * textureWide); |
| 181 | float right = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide); |
| 182 | float top = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh); |
| 183 | float bottom = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh); |
| 184 | #else |
| 185 | float left = (row * itemWidthInPixels) / textureWide; |
| 186 | float right = left + itemWidthInPixels / textureWide; |
| 187 | float top = (col * itemHeightInPixels) / textureHigh; |
| 188 | float bottom = top + itemHeightInPixels / textureHigh; |
| 189 | #endif |
| 190 | |
| 191 | quad->tl.texCoords.u = left; |
| 192 | quad->tl.texCoords.v = top; |
| 193 | quad->tr.texCoords.u = right; |
| 194 | quad->tr.texCoords.v = top; |
| 195 | quad->bl.texCoords.u = left; |
| 196 | quad->bl.texCoords.v = bottom; |
| 197 | quad->br.texCoords.u = right; |
| 198 | quad->br.texCoords.v = bottom; |
| 199 | |
| 200 | quad->bl.vertices.x = (float)(x * _itemWidth); |
| 201 | quad->bl.vertices.y = (float)(y * _itemHeight); |
| 202 | quad->bl.vertices.z = 0.0f; |
| 203 | quad->br.vertices.x = (float)(x * _itemWidth + _itemWidth); |
| 204 | quad->br.vertices.y = (float)(y * _itemHeight); |
| 205 | quad->br.vertices.z = 0.0f; |
| 206 | quad->tl.vertices.x = (float)(x * _itemWidth); |
| 207 | quad->tl.vertices.y = (float)(y * _itemHeight + _itemHeight); |
| 208 | quad->tl.vertices.z = 0.0f; |
| 209 | quad->tr.vertices.x = (float)(x * _itemWidth + _itemWidth); |
| 210 | quad->tr.vertices.y = (float)(y * _itemHeight + _itemHeight); |
| 211 | quad->tr.vertices.z = 0.0f; |
| 212 | |
| 213 | Color4B color(_displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity); |
| 214 | quad->tr.colors = color; |
| 215 | quad->tl.colors = color; |
| 216 | quad->br.colors = color; |
| 217 | quad->bl.colors = color; |
| 218 | |
| 219 | _textureAtlas->setDirty(true); |
no test coverage detected