void GeoMultiProperty::resize(SizeT newsize) { UInt16 dim = getDimension(); UInt32 stride = getStride() ? getStride() : getFormatSize() * dim; if(stride * newsize + getOffset() >= getContainer()->size()) { getContainer()->resize(stride * newsize + getFormatSize() * dim + getOffset()); } setISize(UInt32(newsize)); }
void GeoMultiProperty::setGenericValue(const MaxTypeT &eval, const SizeT index ) { UInt16 dim = getDimension(); bool norm = getNormalize(); UInt32 stride = getStride() ? getStride() : getFormatSize() * dim; UInt8 *data = editData() + stride * index; #define setValNormCase(vectype) \ { \ vectype ival; \ if(norm) \ { \ GeoConvertNormalize::convertIn(ival, eval, \ TypeTraits<vectype::ValueType>::getMax(), 0); \ } \ else \ { \ GeoConvert::convertIn(ival, eval); \ } \ for (UInt16 i = 0; i < dim; ++i) \ reinterpret_cast<vectype::ValueType*>(data)[i] = \ ival[i]; \ } #define setValCase(vectype) \ { \ vectype ival; \ GeoConvert::convertIn(ival, eval); \ for (UInt16 i = 0; i < dim; ++i) \ reinterpret_cast<vectype::ValueType*>(data)[i] = \ ival[i]; \ } switch(getFormat()) { case GL_BYTE: setValNormCase(Vec4b ); break; case GL_UNSIGNED_BYTE: setValNormCase(Vec4ub); break; case GL_SHORT: setValNormCase(Vec4s ); break; case GL_UNSIGNED_SHORT: setValNormCase(Vec4us); break; /* case GL_INT: setValNormCase(Vec4i ); break; case GL_UNSIGNED_INT: setValNormCase(Vec4ui); break; */ case GL_FLOAT: setValCase (Vec4f ); break; #ifndef OSG_OGL_NO_DOUBLE case GL_DOUBLE: setValCase (Vec4d ); break; #endif } #undef setValNormCase #undef setValCase }
ID3D11ShaderResourceView* BufferD3D11::getD3DSRV( uint64 format ) { D3D11_SHADER_RESOURCE_VIEW_DESC desc; memset( &desc, 0, sizeof( desc ) ); desc.Format = MapperD3D11::mapPixelFormat( format ); desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; desc.Buffer.FirstElement = 0; desc.Buffer.NumElements = (UINT)( stride > 0 ? size / stride : size / getFormatSize( format ) ); const char* p = reinterpret_cast<const char*>( &desc ); uint32 hashValue = Math::Hash::DJB32( p, sizeof( desc ) ); HashMap<uint32, ID3D11ShaderResourceView*>::Iterator it = srvCache.find( hashValue ); if( it != srvCache.end() ) { return it.value(); } RenderDeviceD3D11* rd = static_cast<RenderDeviceD3D11*>( owner ); ID3D11Device* d3dDevice = rd->getD3DDevice(); ID3D11ShaderResourceView* d3dSRV = 0; HRESULT hr = d3dDevice->CreateShaderResourceView( d3dResource, &desc, &d3dSRV ); if( FAILED( hr ) ) { return 0; } srvCache.add( hashValue, d3dSRV ); return d3dSRV; }
ID3D11UnorderedAccessView* BufferD3D11::getD3DUAV( uint64 format ) { D3D11_UNORDERED_ACCESS_VIEW_DESC desc; memset( &desc, 0, sizeof( desc ) ); desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; if( accessHint & AH_Raw ) { desc.Format = DXGI_FORMAT_R32_TYPELESS; desc.Buffer.NumElements = (UINT)( size / 4U ); } else if( stride > 0 ) { desc.Format = DXGI_FORMAT_UNKNOWN; desc.Buffer.NumElements = (UINT)( size / stride ); } else { desc.Format = MapperD3D11::mapPixelFormat( format ); desc.Buffer.NumElements = (UINT)( size / getFormatSize( format ) ); } desc.Buffer.FirstElement = 0; desc.Buffer.Flags = 0; if( accessHint & AH_Raw ) { desc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW; } if( accessHint & AH_Append ) { desc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_APPEND; } if( accessHint & AH_Counter ) { desc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_COUNTER; } const char* p = reinterpret_cast<const char*>( &desc ); uint32 hashValue = Math::Hash::DJB32( p, sizeof( desc ) ); HashMap<uint32, ID3D11UnorderedAccessView*>::Iterator it = uavCache.find( hashValue ); if( it != uavCache.end() ) { return it.value(); } RenderDeviceD3D11* rd = static_cast<RenderDeviceD3D11*>( owner ); ID3D11Device* d3dDevice = rd->getD3DDevice(); ID3D11UnorderedAccessView* d3dUAV = 0; HRESULT hr = d3dDevice->CreateUnorderedAccessView( d3dResource, &desc, &d3dUAV ); if( FAILED( hr ) ) { return 0; } uavCache.add( hashValue, d3dUAV ); return d3dUAV; }
VertexDecl& VertexDecl::addElement(Vertex::Semantic s , Vertex::Format f , uint8 idx /*= 0 */) { Info info; info.semantic = s; info.format = f; info.offset = mVertexSize; info.idx = idx; mInfoVec.push_back( info ); mVertexSize += getFormatSize( f ); return *this; }
void Image::create(size_t width, size_t height, unsigned char num_channels, Format format) { ASSERT(width > 0); ASSERT(height > 0); m_width = width; m_height = height; m_format = format; m_nChannels = num_channels; m_bytesPerChannel = getFormatSize(format); m_bytesPerPixel = num_channels * m_bytesPerChannel; m_data.resize(m_width*m_height*m_bytesPerPixel); }
bool AudioBuffer::init(const Sample& data) { alGenBuffers(1, &m_bufferID); alBufferData(m_bufferID, convertToAL(data.format), data.data.data(), (ALsizei) data.data.size(), data.frequency); if (!checkAL("Error during OpenAL buffer creation")) return false; m_format = data.format; m_duration = Time(data.data.size()) / (getFormatSize(m_format) * data.frequency); return true; }
void TextureRectangle::init(int w, int h, TextureInternalFormat tf, TextureFormat f, PixelType t, const Parameters ¶ms, const Buffer::Parameters &s, const Buffer &pixels) { Texture::init(tf, params); this->w = w; this->h = h; pixels.bind(GL_PIXEL_UNPACK_BUFFER); bool needToGenerateMipmaps = true; if (isCompressed() && s.compressedSize() > 0) { glCompressedTexImage2D(textureTarget, 0, getTextureInternalFormat(internalFormat), w, h, 0, s.compressedSize(), pixels.data(0)); } else { s.set(); glTexImage2D(textureTarget, 0, getTextureInternalFormat(internalFormat), w, h, 0, getTextureFormat(f), getPixelType(t), pixels.data(0)); s.unset(); GLsizei size = s.compressedSize(); // should work because size is retrieved from file descriptor. int pixelSize = getFormatSize(f, t); if (size > w * h * pixelSize) { // get the other levels from the same buffer int offset = w * h * pixelSize; int level = 0; int wl = w; int hl = h; while (wl % 2 == 0 && hl % 2 == 0 && size - offset >= (wl * hl / 4) * pixelSize) { level += 1; wl = wl / 2; hl = hl / 2; glTexImage2D(textureTarget, level, getTextureInternalFormat(internalFormat), wl, hl, 0, getTextureFormat(f), getPixelType(t), pixels.data(offset)); offset += wl * hl * pixelSize; needToGenerateMipmaps = false; } this->params.lodMax(clamp(params.lodMax(), GLfloat(0.0f), GLfloat(level))); } } pixels.unbind(GL_PIXEL_UNPACK_BUFFER); if (needToGenerateMipmaps) { generateMipMap(); } if (FrameBuffer::getError() != 0) { throw exception(); } }
TextureCubeResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<0, TextureCube>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; TextureInternalFormat tf; TextureFormat f; PixelType t; Texture::Parameters params; Buffer::Parameters s[6]; int w; int h; try { checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,width,height,"); getIntParameter(desc, e, "width", &w); getIntParameter(desc, e, "height", &h); if (h != 6 * w) { if (Logger::ERROR_LOGGER != NULL) { log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'width' and 'height' attributes"); } throw exception(); } getParameters(desc, e, tf, f, t); getParameters(desc, e, params); int bpp = getFormatSize(f, t); ptr<Buffer> pixels[6]; for (int i = 0; i < 6; ++i) { pixels[i] = new CPUBuffer(desc->getData() + i * w * w * bpp); } try { init(w, w, tf, f, t, params, s, pixels); } catch (...) { throw exception(); } desc->clearData(); } catch (...) { desc->clearData(); throw exception(); } }