HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Pie
|
9.0.0_r8
下载
查看原文件
收藏
根目录
external
swiftshader
src
Renderer
Blitter.cpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "Blitter.hpp" #include "Shader/ShaderCore.hpp" #include "Reactor/Reactor.hpp" #include "Common/Memory.hpp" #include "Common/Debug.hpp" namespace sw { Blitter::Blitter() { blitCache = new RoutineCache
(1024); } Blitter::~Blitter() { delete blitCache; } void Blitter::clear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask) { if(fastClear(pixel, format, dest, dRect, rgbaMask)) { return; } sw::Surface *color = sw::Surface::create(1, 1, 1, format, pixel, sw::Surface::bytes(format), sw::Surface::bytes(format)); SliceRectF sRect((float)dRect.x0, (float)dRect.y0, (float)dRect.x1, (float)dRect.y1, 0); blit(color, sRect, dest, dRect, {rgbaMask}); delete color; } bool Blitter::fastClear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask) { if(format != FORMAT_A32B32G32R32F) { return false; } float *color = (float*)pixel; float r = color[0]; float g = color[1]; float b = color[2]; float a = color[3]; uint32_t packed; switch(dest->getFormat()) { case FORMAT_R5G6B5: if((rgbaMask & 0x7) != 0x7) return false; packed = ((uint16_t)(31 * b + 0.5f) << 0) | ((uint16_t)(63 * g + 0.5f) << 5) | ((uint16_t)(31 * r + 0.5f) << 11); break; case FORMAT_X8B8G8R8: if((rgbaMask & 0x7) != 0x7) return false; packed = ((uint32_t)(255) << 24) | ((uint32_t)(255 * b + 0.5f) << 16) | ((uint32_t)(255 * g + 0.5f) << 8) | ((uint32_t)(255 * r + 0.5f) << 0); break; case FORMAT_A8B8G8R8: if((rgbaMask & 0xF) != 0xF) return false; packed = ((uint32_t)(255 * a + 0.5f) << 24) | ((uint32_t)(255 * b + 0.5f) << 16) | ((uint32_t)(255 * g + 0.5f) << 8) | ((uint32_t)(255 * r + 0.5f) << 0); break; case FORMAT_X8R8G8B8: if((rgbaMask & 0x7) != 0x7) return false; packed = ((uint32_t)(255) << 24) | ((uint32_t)(255 * r + 0.5f) << 16) | ((uint32_t)(255 * g + 0.5f) << 8) | ((uint32_t)(255 * b + 0.5f) << 0); break; case FORMAT_A8R8G8B8: if((rgbaMask & 0xF) != 0xF) return false; packed = ((uint32_t)(255 * a + 0.5f) << 24) | ((uint32_t)(255 * r + 0.5f) << 16) | ((uint32_t)(255 * g + 0.5f) << 8) | ((uint32_t)(255 * b + 0.5f) << 0); break; default: return false; } bool useDestInternal = !dest->isExternalDirty(); uint8_t *slice = (uint8_t*)dest->lock(dRect.x0, dRect.y0, dRect.slice, sw::LOCK_WRITEONLY, sw::PUBLIC, useDestInternal); for(int j = 0; j < dest->getSamples(); j++) { uint8_t *d = slice; switch(Surface::bytes(dest->getFormat())) { case 2: for(int i = dRect.y0; i < dRect.y1; i++) { sw::clear((uint16_t*)d, packed, dRect.x1 - dRect.x0); d += dest->getPitchB(useDestInternal); } break; case 4: for(int i = dRect.y0; i < dRect.y1; i++) { sw::clear((uint32_t*)d, packed, dRect.x1 - dRect.x0); d += dest->getPitchB(useDestInternal); } break; default: assert(false); } slice += dest->getSliceB(useDestInternal); } dest->unlock(useDestInternal); return true; } void Blitter::blit(Surface *source, const SliceRectF &sourceRect, Surface *dest, const SliceRect &destRect, const Blitter::Options& options) { if(dest->getInternalFormat() == FORMAT_NULL) { return; } if(blitReactor(source, sourceRect, dest, destRect, options)) { return; } SliceRectF sRect = sourceRect; SliceRect dRect = destRect; bool flipX = destRect.x0 > destRect.x1; bool flipY = destRect.y0 > destRect.y1; if(flipX) { swap(dRect.x0, dRect.x1); swap(sRect.x0, sRect.x1); } if(flipY) { swap(dRect.y0, dRect.y1); swap(sRect.y0, sRect.y1); } source->lockInternal((int)sRect.x0, (int)sRect.y0, sRect.slice, sw::LOCK_READONLY, sw::PUBLIC); dest->lockInternal(dRect.x0, dRect.y0, dRect.slice, sw::LOCK_WRITEONLY, sw::PUBLIC); float w = sRect.width() / dRect.width(); float h = sRect.height() / dRect.height(); const float xStart = sRect.x0 + 0.5f * w; float y = sRect.y0 + 0.5f * h; for(int j = dRect.y0; j < dRect.y1; j++) { float x = xStart; for(int i = dRect.x0; i < dRect.x1; i++) { // FIXME: Support RGBA mask dest->copyInternal(source, i, j, x, y, options.filter); x += w; } y += h; } source->unlockInternal(); dest->unlockInternal(); } void Blitter::blit3D(Surface *source, Surface *dest) { source->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); dest->lockInternal(0, 0, 0, sw::LOCK_WRITEONLY, sw::PUBLIC); float w = static_cast
(source->getWidth()) / static_cast
(dest->getWidth()); float h = static_cast
(source->getHeight()) / static_cast
(dest->getHeight()); float d = static_cast
(source->getDepth()) / static_cast
(dest->getDepth()); float z = 0.5f * d; for(int k = 0; k < dest->getDepth(); k++) { float y = 0.5f * h; for(int j = 0; j < dest->getHeight(); j++) { float x = 0.5f * w; for(int i = 0; i < dest->getWidth(); i++) { dest->copyInternal(source, i, j, k, x, y, z, true); x += w; } y += h; } z += d; } source->unlockInternal(); dest->unlockInternal(); } bool Blitter::read(Float4 &c, Pointer
element, const State &state) { c = Float4(0.0f, 0.0f, 0.0f, 1.0f); switch(state.sourceFormat) { case FORMAT_L8: c.xyz = Float(Int(*Pointer
(element))); c.w = float(0xFF); break; case FORMAT_A8: c.w = Float(Int(*Pointer
(element))); break; case FORMAT_R8I: case FORMAT_R8_SNORM: c.x = Float(Int(*Pointer
(element))); c.w = float(0x7F); break; case FORMAT_R8: case FORMAT_R8UI: c.x = Float(Int(*Pointer
(element))); c.w = float(0xFF); break; case FORMAT_R16I: c.x = Float(Int(*Pointer
(element))); c.w = float(0x7FFF); break; case FORMAT_R16UI: c.x = Float(Int(*Pointer
(element))); c.w = float(0xFFFF); break; case FORMAT_R32I: c.x = Float(*Pointer
(element)); c.w = float(0x7FFFFFFF); break; case FORMAT_R32UI: c.x = Float(*Pointer
(element)); c.w = float(0xFFFFFFFF); break; case FORMAT_A8R8G8B8: c = Float4(*Pointer
(element)).zyxw; break; case FORMAT_A8B8G8R8I: case FORMAT_A8B8G8R8_SNORM: c = Float4(*Pointer
(element)); break; case FORMAT_A8B8G8R8: case FORMAT_A8B8G8R8UI: case FORMAT_SRGB8_A8: c = Float4(*Pointer
(element)); break; case FORMAT_X8R8G8B8: c = Float4(*Pointer
(element)).zyxw; c.w = float(0xFF); break; case FORMAT_R8G8B8: c.z = Float(Int(*Pointer
(element + 0))); c.y = Float(Int(*Pointer
(element + 1))); c.x = Float(Int(*Pointer
(element + 2))); c.w = float(0xFF); break; case FORMAT_B8G8R8: c.x = Float(Int(*Pointer
(element + 0))); c.y = Float(Int(*Pointer
(element + 1))); c.z = Float(Int(*Pointer
(element + 2))); c.w = float(0xFF); break; case FORMAT_X8B8G8R8I: case FORMAT_X8B8G8R8_SNORM: c = Float4(*Pointer
(element)); c.w = float(0x7F); break; case FORMAT_X8B8G8R8: case FORMAT_X8B8G8R8UI: case FORMAT_SRGB8_X8: c = Float4(*Pointer
(element)); c.w = float(0xFF); break; case FORMAT_A16B16G16R16I: c = Float4(*Pointer
(element)); break; case FORMAT_A16B16G16R16: case FORMAT_A16B16G16R16UI: c = Float4(*Pointer
(element)); break; case FORMAT_X16B16G16R16I: c = Float4(*Pointer
(element)); c.w = float(0x7FFF); break; case FORMAT_X16B16G16R16UI: c = Float4(*Pointer
(element)); c.w = float(0xFFFF); break; case FORMAT_A32B32G32R32I: c = Float4(*Pointer
(element)); break; case FORMAT_A32B32G32R32UI: c = Float4(*Pointer
(element)); break; case FORMAT_X32B32G32R32I: c = Float4(*Pointer
(element)); c.w = float(0x7FFFFFFF); break; case FORMAT_X32B32G32R32UI: c = Float4(*Pointer
(element)); c.w = float(0xFFFFFFFF); break; case FORMAT_G8R8I: case FORMAT_G8R8_SNORM: c.x = Float(Int(*Pointer
(element + 0))); c.y = Float(Int(*Pointer
(element + 1))); c.w = float(0x7F); break; case FORMAT_G8R8: case FORMAT_G8R8UI: c.x = Float(Int(*Pointer
(element + 0))); c.y = Float(Int(*Pointer
(element + 1))); c.w = float(0xFF); break; case FORMAT_G16R16I: c.x = Float(Int(*Pointer
(element + 0))); c.y = Float(Int(*Pointer
(element + 2))); c.w = float(0x7FFF); break; case FORMAT_G16R16: case FORMAT_G16R16UI: c.x = Float(Int(*Pointer
(element + 0))); c.y = Float(Int(*Pointer
(element + 2))); c.w = float(0xFFFF); break; case FORMAT_G32R32I: c.x = Float(*Pointer
(element + 0)); c.y = Float(*Pointer
(element + 4)); c.w = float(0x7FFFFFFF); break; case FORMAT_G32R32UI: c.x = Float(*Pointer
(element + 0)); c.y = Float(*Pointer
(element + 4)); c.w = float(0xFFFFFFFF); break; case FORMAT_A32B32G32R32F: c = *Pointer
(element); break; case FORMAT_X32B32G32R32F: case FORMAT_X32B32G32R32F_UNSIGNED: case FORMAT_B32G32R32F: c.z = *Pointer
(element + 8); case FORMAT_G32R32F: c.x = *Pointer
(element + 0); c.y = *Pointer
(element + 4); break; case FORMAT_R32F: c.x = *Pointer
(element); break; case FORMAT_R5G6B5: c.x = Float(Int((*Pointer
(element) & UShort(0xF800)) >> UShort(11))); c.y = Float(Int((*Pointer
(element) & UShort(0x07E0)) >> UShort(5))); c.z = Float(Int(*Pointer
(element) & UShort(0x001F))); break; case FORMAT_A2B10G10R10: case FORMAT_A2B10G10R10UI: c.x = Float(Int((*Pointer
(element) & UInt(0x000003FF)))); c.y = Float(Int((*Pointer
(element) & UInt(0x000FFC00)) >> 10)); c.z = Float(Int((*Pointer
(element) & UInt(0x3FF00000)) >> 20)); c.w = Float(Int((*Pointer
(element) & UInt(0xC0000000)) >> 30)); break; case FORMAT_D16: c.x = Float(Int((*Pointer
(element)))); break; case FORMAT_D24S8: c.x = Float(Int((*Pointer
(element)))); break; case FORMAT_D32: c.x = Float(Int((*Pointer
(element)))); break; case FORMAT_D32F_COMPLEMENTARY: case FORMAT_D32FS8_COMPLEMENTARY: c.x = 1.0f - *Pointer
(element); break; case FORMAT_D32F: case FORMAT_D32FS8: case FORMAT_D32F_LOCKABLE: case FORMAT_D32FS8_TEXTURE: case FORMAT_D32F_SHADOW: case FORMAT_D32FS8_SHADOW: c.x = *Pointer
(element); break; case FORMAT_S8: c.x = Float(Int(*Pointer
(element))); break; default: return false; } return true; } bool Blitter::write(Float4 &c, Pointer
element, const State &state) { bool writeR = state.writeRed; bool writeG = state.writeGreen; bool writeB = state.writeBlue; bool writeA = state.writeAlpha; bool writeRGBA = writeR && writeG && writeB && writeA; switch(state.destFormat) { case FORMAT_L8: *Pointer
(element) = Byte(RoundInt(Float(c.x))); break; case FORMAT_A8: if(writeA) { *Pointer
(element) = Byte(RoundInt(Float(c.w))); } break; case FORMAT_A8R8G8B8: if(writeRGBA) { Short4 c0 = RoundShort4(c.zyxw); *Pointer
(element) = Byte4(PackUnsigned(c0, c0)); } else { if(writeB) { *Pointer
(element + 0) = Byte(RoundInt(Float(c.z))); } if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } if(writeR) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.x))); } if(writeA) { *Pointer
(element + 3) = Byte(RoundInt(Float(c.w))); } } break; case FORMAT_A8B8G8R8: case FORMAT_SRGB8_A8: if(writeRGBA) { Short4 c0 = RoundShort4(c); *Pointer
(element) = Byte4(PackUnsigned(c0, c0)); } else { if(writeR) { *Pointer
(element + 0) = Byte(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.z))); } if(writeA) { *Pointer
(element + 3) = Byte(RoundInt(Float(c.w))); } } break; case FORMAT_X8R8G8B8: if(writeRGBA) { Short4 c0 = RoundShort4(c.zyxw) | Short4(0x0000, 0x0000, 0x0000, 0x00FF); *Pointer
(element) = Byte4(PackUnsigned(c0, c0)); } else { if(writeB) { *Pointer
(element + 0) = Byte(RoundInt(Float(c.z))); } if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } if(writeR) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.x))); } if(writeA) { *Pointer
(element + 3) = Byte(0xFF); } } break; case FORMAT_X8B8G8R8: case FORMAT_SRGB8_X8: if(writeRGBA) { Short4 c0 = RoundShort4(c) | Short4(0x0000, 0x0000, 0x0000, 0x00FF); *Pointer
(element) = Byte4(PackUnsigned(c0, c0)); } else { if(writeR) { *Pointer
(element + 0) = Byte(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.z))); } if(writeA) { *Pointer
(element + 3) = Byte(0xFF); } } break; case FORMAT_R8G8B8: if(writeR) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 0) = Byte(RoundInt(Float(c.z))); } break; case FORMAT_B8G8R8: if(writeR) { *Pointer
(element + 0) = Byte(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.z))); } break; case FORMAT_A32B32G32R32F: if(writeRGBA) { *Pointer
(element) = c; } else { if(writeR) { *Pointer
(element) = c.x; } if(writeG) { *Pointer
(element + 4) = c.y; } if(writeB) { *Pointer
(element + 8) = c.z; } if(writeA) { *Pointer
(element + 12) = c.w; } } break; case FORMAT_X32B32G32R32F: case FORMAT_X32B32G32R32F_UNSIGNED: if(writeA) { *Pointer
(element + 12) = 1.0f; } case FORMAT_B32G32R32F: if(writeR) { *Pointer
(element) = c.x; } if(writeG) { *Pointer
(element + 4) = c.y; } if(writeB) { *Pointer
(element + 8) = c.z; } break; case FORMAT_G32R32F: if(writeR && writeG) { *Pointer
(element) = Float2(c); } else { if(writeR) { *Pointer
(element) = c.x; } if(writeG) { *Pointer
(element + 4) = c.y; } } break; case FORMAT_R32F: if(writeR) { *Pointer
(element) = c.x; } break; case FORMAT_A8B8G8R8I: case FORMAT_A8B8G8R8_SNORM: if(writeA) { *Pointer
(element + 3) = SByte(RoundInt(Float(c.w))); } case FORMAT_X8B8G8R8I: case FORMAT_X8B8G8R8_SNORM: if(writeA && (state.destFormat == FORMAT_X8B8G8R8I || state.destFormat == FORMAT_X8B8G8R8_SNORM)) { *Pointer
(element + 3) = SByte(0x7F); } if(writeB) { *Pointer
(element + 2) = SByte(RoundInt(Float(c.z))); } case FORMAT_G8R8I: case FORMAT_G8R8_SNORM: if(writeG) { *Pointer
(element + 1) = SByte(RoundInt(Float(c.y))); } case FORMAT_R8I: case FORMAT_R8_SNORM: if(writeR) { *Pointer
(element) = SByte(RoundInt(Float(c.x))); } break; case FORMAT_A8B8G8R8UI: if(writeA) { *Pointer
(element + 3) = Byte(RoundInt(Float(c.w))); } case FORMAT_X8B8G8R8UI: if(writeA && (state.destFormat == FORMAT_X8B8G8R8UI)) { *Pointer
(element + 3) = Byte(0xFF); } if(writeB) { *Pointer
(element + 2) = Byte(RoundInt(Float(c.z))); } case FORMAT_G8R8UI: case FORMAT_G8R8: if(writeG) { *Pointer
(element + 1) = Byte(RoundInt(Float(c.y))); } case FORMAT_R8UI: case FORMAT_R8: if(writeR) { *Pointer
(element) = Byte(RoundInt(Float(c.x))); } break; case FORMAT_A16B16G16R16I: if(writeRGBA) { *Pointer
(element) = Short4(RoundInt(c)); } else { if(writeR) { *Pointer
(element) = Short(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 2) = Short(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 4) = Short(RoundInt(Float(c.z))); } if(writeA) { *Pointer
(element + 6) = Short(RoundInt(Float(c.w))); } } break; case FORMAT_X16B16G16R16I: if(writeRGBA) { *Pointer
(element) = Short4(RoundInt(c)); } else { if(writeR) { *Pointer
(element) = Short(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 2) = Short(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 4) = Short(RoundInt(Float(c.z))); } } if(writeA) { *Pointer
(element + 6) = Short(0x7F); } break; case FORMAT_G16R16I: if(writeR && writeG) { *Pointer
(element) = Short2(Short4(RoundInt(c))); } else { if(writeR) { *Pointer
(element) = Short(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 2) = Short(RoundInt(Float(c.y))); } } break; case FORMAT_R16I: if(writeR) { *Pointer
(element) = Short(RoundInt(Float(c.x))); } break; case FORMAT_A16B16G16R16UI: case FORMAT_A16B16G16R16: if(writeRGBA) { *Pointer
(element) = UShort4(RoundInt(c)); } else { if(writeR) { *Pointer
(element) = UShort(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 2) = UShort(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 4) = UShort(RoundInt(Float(c.z))); } if(writeA) { *Pointer
(element + 6) = UShort(RoundInt(Float(c.w))); } } break; case FORMAT_X16B16G16R16UI: if(writeRGBA) { *Pointer
(element) = UShort4(RoundInt(c)); } else { if(writeR) { *Pointer
(element) = UShort(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 2) = UShort(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 4) = UShort(RoundInt(Float(c.z))); } } if(writeA) { *Pointer
(element + 6) = UShort(0xFF); } break; case FORMAT_G16R16UI: case FORMAT_G16R16: if(writeR && writeG) { *Pointer
(element) = UShort2(UShort4(RoundInt(c))); } else { if(writeR) { *Pointer
(element) = UShort(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 2) = UShort(RoundInt(Float(c.y))); } } break; case FORMAT_R16UI: if(writeR) { *Pointer
(element) = UShort(RoundInt(Float(c.x))); } break; case FORMAT_A32B32G32R32I: if(writeRGBA) { *Pointer
(element) = RoundInt(c); } else { if(writeR) { *Pointer
(element) = RoundInt(Float(c.x)); } if(writeG) { *Pointer
(element + 4) = RoundInt(Float(c.y)); } if(writeB) { *Pointer
(element + 8) = RoundInt(Float(c.z)); } if(writeA) { *Pointer
(element + 12) = RoundInt(Float(c.w)); } } break; case FORMAT_X32B32G32R32I: if(writeRGBA) { *Pointer
(element) = RoundInt(c); } else { if(writeR) { *Pointer
(element) = RoundInt(Float(c.x)); } if(writeG) { *Pointer
(element + 4) = RoundInt(Float(c.y)); } if(writeB) { *Pointer
(element + 8) = RoundInt(Float(c.z)); } } if(writeA) { *Pointer
(element + 12) = Int(0x7FFFFFFF); } break; case FORMAT_G32R32I: if(writeG) { *Pointer
(element + 4) = RoundInt(Float(c.y)); } case FORMAT_R32I: if(writeR) { *Pointer
(element) = RoundInt(Float(c.x)); } break; case FORMAT_A32B32G32R32UI: if(writeRGBA) { *Pointer
(element) = UInt4(RoundInt(c)); } else { if(writeR) { *Pointer
(element) = As
(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 4) = As
(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 8) = As
(RoundInt(Float(c.z))); } if(writeA) { *Pointer
(element + 12) = As
(RoundInt(Float(c.w))); } } break; case FORMAT_X32B32G32R32UI: if(writeRGBA) { *Pointer
(element) = UInt4(RoundInt(c)); } else { if(writeR) { *Pointer
(element) = As
(RoundInt(Float(c.x))); } if(writeG) { *Pointer
(element + 4) = As
(RoundInt(Float(c.y))); } if(writeB) { *Pointer
(element + 8) = As
(RoundInt(Float(c.z))); } } if(writeA) { *Pointer
(element + 12) = UInt4(0xFFFFFFFF); } break; case FORMAT_G32R32UI: if(writeG) { *Pointer
(element + 4) = As
(RoundInt(Float(c.y))); } case FORMAT_R32UI: if(writeR) { *Pointer
(element) = As
(RoundInt(Float(c.x))); } break; case FORMAT_R5G6B5: if(writeR && writeG && writeB) { *Pointer
(element) = UShort(RoundInt(Float(c.z)) | (RoundInt(Float(c.y)) << Int(5)) | (RoundInt(Float(c.x)) << Int(11))); } else { unsigned short mask = (writeB ? 0x001F : 0x0000) | (writeG ? 0x07E0 : 0x0000) | (writeR ? 0xF800 : 0x0000); unsigned short unmask = ~mask; *Pointer
(element) = (*Pointer
(element) & UShort(unmask)) | (UShort(RoundInt(Float(c.z)) | (RoundInt(Float(c.y)) << Int(5)) | (RoundInt(Float(c.x)) << Int(11))) & UShort(mask)); } break; case FORMAT_A2B10G10R10: case FORMAT_A2B10G10R10UI: if(writeRGBA) { *Pointer
(element) = UInt(RoundInt(Float(c.x)) | (RoundInt(Float(c.y)) << 10) | (RoundInt(Float(c.z)) << 20) | (RoundInt(Float(c.w)) << 30)); } else { unsigned int mask = (writeA ? 0xC0000000 : 0x0000) | (writeB ? 0x3FF00000 : 0x0000) | (writeG ? 0x000FFC00 : 0x0000) | (writeR ? 0x000003FF : 0x0000); unsigned int unmask = ~mask; *Pointer
(element) = (*Pointer
(element) & UInt(unmask)) | (UInt(RoundInt(Float(c.x)) | (RoundInt(Float(c.y)) << 10) | (RoundInt(Float(c.z)) << 20) | (RoundInt(Float(c.w)) << 30)) & UInt(mask)); } break; case FORMAT_D16: *Pointer
(element) = UShort(RoundInt(Float(c.x))); break; case FORMAT_D24S8: *Pointer
(element) = UInt(RoundInt(Float(c.x))); break; case FORMAT_D32: *Pointer
(element) = UInt(RoundInt(Float(c.x))); break; case FORMAT_D32F_COMPLEMENTARY: case FORMAT_D32FS8_COMPLEMENTARY: *Pointer
(element) = 1.0f - c.x; break; case FORMAT_D32F: case FORMAT_D32FS8: case FORMAT_D32F_LOCKABLE: case FORMAT_D32FS8_TEXTURE: case FORMAT_D32F_SHADOW: case FORMAT_D32FS8_SHADOW: *Pointer
(element) = c.x; break; case FORMAT_S8: *Pointer
(element) = Byte(RoundInt(Float(c.x))); break; default: return false; } return true; } bool Blitter::read(Int4 &c, Pointer
element, const State &state) { c = Int4(0, 0, 0, 1); switch(state.sourceFormat) { case FORMAT_A8B8G8R8I: c = Insert(c, Int(*Pointer
(element + 3)), 3); case FORMAT_X8B8G8R8I: c = Insert(c, Int(*Pointer
(element + 2)), 2); case FORMAT_G8R8I: c = Insert(c, Int(*Pointer
(element + 1)), 1); case FORMAT_R8I: c = Insert(c, Int(*Pointer
(element)), 0); break; case FORMAT_A8B8G8R8UI: c = Insert(c, Int(*Pointer
(element + 3)), 3); case FORMAT_X8B8G8R8UI: c = Insert(c, Int(*Pointer
(element + 2)), 2); case FORMAT_G8R8UI: c = Insert(c, Int(*Pointer
(element + 1)), 1); case FORMAT_R8UI: c = Insert(c, Int(*Pointer
(element)), 0); break; case FORMAT_A16B16G16R16I: c = Insert(c, Int(*Pointer
(element + 6)), 3); case FORMAT_X16B16G16R16I: c = Insert(c, Int(*Pointer
(element + 4)), 2); case FORMAT_G16R16I: c = Insert(c, Int(*Pointer
(element + 2)), 1); case FORMAT_R16I: c = Insert(c, Int(*Pointer
(element)), 0); break; case FORMAT_A16B16G16R16UI: c = Insert(c, Int(*Pointer
(element + 6)), 3); case FORMAT_X16B16G16R16UI: c = Insert(c, Int(*Pointer
(element + 4)), 2); case FORMAT_G16R16UI: c = Insert(c, Int(*Pointer
(element + 2)), 1); case FORMAT_R16UI: c = Insert(c, Int(*Pointer
(element)), 0); break; case FORMAT_A32B32G32R32I: case FORMAT_A32B32G32R32UI: c = *Pointer
(element); break; case FORMAT_X32B32G32R32I: case FORMAT_X32B32G32R32UI: c = Insert(c, *Pointer
(element + 8), 2); case FORMAT_G32R32I: case FORMAT_G32R32UI: c = Insert(c, *Pointer
(element + 4), 1); case FORMAT_R32I: case FORMAT_R32UI: c = Insert(c, *Pointer
(element), 0); break; default: return false; } return true; } bool Blitter::write(Int4 &c, Pointer
element, const State &state) { bool writeR = state.writeRed; bool writeG = state.writeGreen; bool writeB = state.writeBlue; bool writeA = state.writeAlpha; bool writeRGBA = writeR && writeG && writeB && writeA; switch(state.destFormat) { case FORMAT_A8B8G8R8I: if(writeA) { *Pointer
(element + 3) = SByte(Extract(c, 3)); } case FORMAT_X8B8G8R8I: if(writeA && (state.destFormat != FORMAT_A8B8G8R8I)) { *Pointer
(element + 3) = SByte(0x7F); } if(writeB) { *Pointer
(element + 2) = SByte(Extract(c, 2)); } case FORMAT_G8R8I: if(writeG) { *Pointer
(element + 1) = SByte(Extract(c, 1)); } case FORMAT_R8I: if(writeR) { *Pointer
(element) = SByte(Extract(c, 0)); } break; case FORMAT_A8B8G8R8UI: if(writeA) { *Pointer
(element + 3) = Byte(Extract(c, 3)); } case FORMAT_X8B8G8R8UI: if(writeA && (state.destFormat != FORMAT_A8B8G8R8UI)) { *Pointer
(element + 3) = Byte(0xFF); } if(writeB) { *Pointer
(element + 2) = Byte(Extract(c, 2)); } case FORMAT_G8R8UI: if(writeG) { *Pointer
(element + 1) = Byte(Extract(c, 1)); } case FORMAT_R8UI: if(writeR) { *Pointer
(element) = Byte(Extract(c, 0)); } break; case FORMAT_A16B16G16R16I: if(writeA) { *Pointer
(element + 6) = Short(Extract(c, 3)); } case FORMAT_X16B16G16R16I: if(writeA && (state.destFormat != FORMAT_A16B16G16R16I)) { *Pointer
(element + 6) = Short(0x7FFF); } if(writeB) { *Pointer
(element + 4) = Short(Extract(c, 2)); } case FORMAT_G16R16I: if(writeG) { *Pointer
(element + 2) = Short(Extract(c, 1)); } case FORMAT_R16I: if(writeR) { *Pointer
(element) = Short(Extract(c, 0)); } break; case FORMAT_A16B16G16R16UI: if(writeA) { *Pointer
(element + 6) = UShort(Extract(c, 3)); } case FORMAT_X16B16G16R16UI: if(writeA && (state.destFormat != FORMAT_A16B16G16R16UI)) { *Pointer
(element + 6) = UShort(0xFFFF); } if(writeB) { *Pointer
(element + 4) = UShort(Extract(c, 2)); } case FORMAT_G16R16UI: if(writeG) { *Pointer
(element + 2) = UShort(Extract(c, 1)); } case FORMAT_R16UI: if(writeR) { *Pointer
(element) = UShort(Extract(c, 0)); } break; case FORMAT_A32B32G32R32I: if(writeRGBA) { *Pointer
(element) = c; } else { if(writeR) { *Pointer
(element) = Extract(c, 0); } if(writeG) { *Pointer
(element + 4) = Extract(c, 1); } if(writeB) { *Pointer
(element + 8) = Extract(c, 2); } if(writeA) { *Pointer
(element + 12) = Extract(c, 3); } } break; case FORMAT_X32B32G32R32I: if(writeRGBA) { *Pointer
(element) = c; } else { if(writeR) { *Pointer
(element) = Extract(c, 0); } if(writeG) { *Pointer
(element + 4) = Extract(c, 1); } if(writeB) { *Pointer
(element + 8) = Extract(c, 2); } } if(writeA) { *Pointer
(element + 12) = Int(0x7FFFFFFF); } break; case FORMAT_G32R32I: if(writeR) { *Pointer
(element) = Extract(c, 0); } if(writeG) { *Pointer
(element + 4) = Extract(c, 1); } break; case FORMAT_R32I: if(writeR) { *Pointer
(element) = Extract(c, 0); } break; case FORMAT_A32B32G32R32UI: if(writeRGBA) { *Pointer
(element) = As
(c); } else { if(writeR) { *Pointer
(element) = As
(Extract(c, 0)); } if(writeG) { *Pointer
(element + 4) = As
(Extract(c, 1)); } if(writeB) { *Pointer
(element + 8) = As