//----------------------------------------------------------------------------// void OpenGL3Texture::loadFromMemory(const void* buffer, const Sizef& buffer_size, PixelFormat pixel_format) { if (!isPixelFormatSupported(pixel_format)) CEGUI_THROW(InvalidRequestException( "Data was supplied in an unsupported pixel format.")); initInternalPixelFormatFields(pixel_format); setTextureSize_impl(buffer_size); // store size of original data we are loading d_dataSize = buffer_size; updateCachedScaleValues(); // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // do the real work of getting the data into the texture glBindTexture(GL_TEXTURE_2D, d_ogltexture); if (d_isCompressed) loadCompressedTextureBuffer(buffer_size, buffer); else loadUncompressedTextureBuffer(buffer_size, buffer); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); }
//----------------------------------------------------------------------------// Direct3D11Texture::Direct3D11Texture(IDevice11& device, const Size& sz) : d_device(device), d_texture(0), d_resourceView(0), d_size(0, 0), d_dataSize(0, 0), d_texelScaling(0, 0) { D3D11_TEXTURE2D_DESC tex_desc; ZeroMemory(&tex_desc, sizeof(tex_desc)); tex_desc.Width = static_cast<UINT>(sz.d_width); tex_desc.Height = static_cast<UINT>(sz.d_height); tex_desc.ArraySize = 1; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; tex_desc.Usage = D3D11_USAGE_DEFAULT; tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; tex_desc.CPUAccessFlags = 0; tex_desc.MiscFlags = 0; tex_desc.MipLevels = 1; if (FAILED(d_device.d_device->CreateTexture2D(&tex_desc, 0, &d_texture))) CEGUI_THROW(RendererException( "Direct3D11Texture: Failed to create texture with specified size.")); initialiseShaderResourceView(); d_dataSize = sz; updateTextureSize(); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLTexture::setTextureSize(const Size& sz) { const Size size(d_owner.getAdjustedTextureSize(sz)); // make sure size is within boundaries GLfloat maxSize; glGetFloatv(GL_MAX_TEXTURE_SIZE, &maxSize); if ((size.d_width > maxSize) || (size.d_height > maxSize)) CEGUI_THROW(RendererException( "OpenGLTexture::setTextureSize: size too big")); // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // set texture to required size glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, static_cast<GLsizei>(size.d_width), static_cast<GLsizei>(size.d_height), 0, GL_RGBA , GL_UNSIGNED_BYTE, 0); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); d_dataSize = d_size = size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLTexture::initialise(GLuint tex, const Sizef& size) { d_ogltexture = tex; d_size = size; d_dataSize = size; initInternalPixelFormatFields(PF_RGBA); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void DirectFBTexture::loadFromMemory(const void* buffer, const Sizef& buffer_size, PixelFormat pixel_format) { if (!isPixelFormatSupported(pixel_format)) CEGUI_THROW(InvalidRequestException( "Data was supplied in an unsupported pixel format.")); cleanupDirectFBTexture(); DFBSurfaceDescription desc; desc.flags = static_cast<DFBSurfaceDescriptionFlags> (DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); desc.width = buffer_size.d_width; desc.height = buffer_size.d_height; desc.pixelformat = DSPF_ARGB; if (d_directfb.CreateSurface(&d_directfb, &desc, &d_texture)) CEGUI_THROW(RendererException("Failed to create surface.")); char* dest; int pitch; if(d_texture->Lock(d_texture, DSLF_WRITE, reinterpret_cast<void**>(&dest), &pitch)) { d_texture->Release(d_texture); d_texture = 0; CEGUI_THROW(RendererException("Directfb::Lock failed.")); } // Copy data in. const size_t pix_sz = (pixel_format == PF_RGB) ? 3 : 4; const char* src = static_cast<const char*>(buffer); for (int i = 0; i < buffer_size.d_height; ++i) { for (int j = 0; j < buffer_size.d_width; ++j) { dest[j * 4 + 0] = src[j * pix_sz + 2]; dest[j * 4 + 1] = src[j * pix_sz + 1]; dest[j * 4 + 2] = src[j * pix_sz + 0]; dest[j * 4 + 3] = (pix_sz == 3) ? 0xFF : src[j * pix_sz + 3]; } dest += pitch; src += static_cast<size_t>(buffer_size.d_width) * pix_sz; } d_texture->Unlock(d_texture); // update size and scaling info int rw, rh; d_texture->GetSize(d_texture, &rw, &rh); d_size.d_width = static_cast<float>(rw); d_size.d_height = static_cast<float>(rh); d_dataSize = buffer_size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void Direct3D11Texture::loadFromMemory(const void* buffer, const Size& buffer_size, PixelFormat pixel_format) { cleanupDirect3D11Texture(); const void* img_src = buffer; if (pixel_format == PF_RGB) { const char* src = static_cast<const char*>(buffer); char* dest = new char[buffer_size.d_width * buffer_size.d_height * 4]; for (int i = 0; i < buffer_size.d_width * buffer_size.d_height; ++i) { dest[i * 4 + 0] = src[i * 3 + 0]; dest[i * 4 + 1] = src[i * 3 + 1]; dest[i * 4 + 2] = src[i * 3 + 2]; dest[i * 4 + 3] = 0xFF; } img_src = dest; } D3D11_TEXTURE2D_DESC tex_desc; ZeroMemory(&tex_desc, sizeof(tex_desc)); tex_desc.Width = static_cast<UINT>(buffer_size.d_width); tex_desc.Height = static_cast<UINT>(buffer_size.d_height); tex_desc.ArraySize = 1; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; tex_desc.Usage = D3D11_USAGE_DEFAULT; tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; tex_desc.CPUAccessFlags = 0; tex_desc.MiscFlags = 0; tex_desc.MipLevels = 1; D3D11_SUBRESOURCE_DATA data; ZeroMemory(&data, sizeof(D3D11_SUBRESOURCE_DATA)); data.pSysMem = img_src; data.SysMemPitch = 4 * tex_desc.Width; HRESULT hr = d_device.d_device->CreateTexture2D(&tex_desc, &data, &d_texture); if (pixel_format == PF_RGB) delete[] img_src; if (FAILED(hr)) CEGUI_THROW(RendererException( "Direct3D11Texture::loadFromMemory: Failed to " "create texture from memory buffer.")); initialiseShaderResourceView(); d_dataSize = buffer_size; updateTextureSize(); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGL3Texture::setTextureSize(const Sizef& sz) { initInternalPixelFormatFields(PF_RGBA); setTextureSize_impl(sz); d_dataSize = d_size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// OpenGLTexture::OpenGLTexture(OpenGLRenderer& owner, GLuint tex, const Size& size) : d_ogltexture(tex), d_size(size), d_grabBuffer(0), d_dataSize(size), d_owner(owner) { updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void DirectFBTexture::cleanupDirectFBTexture() { if (!d_texture) return; d_texture->Release(d_texture); d_texture = 0; d_size = d_dataSize = Sizef(0,0); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// OpenGL3Texture::OpenGL3Texture(OpenGL3Renderer& owner, const String& name, GLuint tex, const Sizef& size) : d_ogltexture(tex), d_size(size), d_grabBuffer(0), d_dataSize(size), d_owner(owner), d_name(name) { initInternalPixelFormatFields(PF_RGBA); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLTexture::setOpenGLTexture(GLuint tex, const Size& size) { if (d_ogltexture != tex) { // cleanup the current state first. cleanupOpenGLTexture(); d_ogltexture = tex; } d_dataSize = d_size = size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLTexture::loadFromMemory(const void* buffer, const Sizef& buffer_size, PixelFormat pixel_format) { if (!isPixelFormatSupported(pixel_format)) throw InvalidRequestException( "Data was supplied in an unsupported pixel format."); initInternalPixelFormatFields(pixel_format); setTextureSize_impl(buffer_size); // store size of original data we are loading d_dataSize = buffer_size; updateCachedScaleValues(); blitFromMemory(buffer, Rectf(glm::vec2(0, 0), buffer_size)); }
void IrrlichtTexture::loadFromFile(const String& filename, const String& resourceGroup) { freeTexture(); RawDataContainer texFile; System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, texFile, resourceGroup); IrrlichtMemoryFile imf(filename, texFile.getDataPtr(), texFile.getSize()); driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,true); tex=driver->getTexture(&imf); tex->grab(); // unload file data buffer System::getSingleton().getResourceProvider()->unloadRawDataContainer(texFile); updateCachedScaleValues(); }
void FlowVRCegTexture::loadFromMemory(const void* buffPtr, const Size &buffer_size, PixelFormat pixelFormat) { std::cout << "FlowVRCegTexture::loadFromMemory()" << std::endl; int imageType; int pixelType; switch(pixelFormat) { case Texture::PF_RGB: { std::cout << "RGB texture requested.\n"; imageType = flowvr::render::ChunkTexture::RGB; pixelType = ftl::Type::vector(ftl::Type::Byte, 3); break; } case Texture::PF_RGBA: { std::cout << "RGBA texture requested.\n"; imageType = flowvr::render::ChunkTexture::RGBA; pixelType = ftl::Type::vector(ftl::Type::Byte, 4); break; } default: return; // failed } FlowVRCegRenderer *parent = dynamic_cast<FlowVRCegRenderer*>( &m_owner ); flowvr::render::ChunkTexture *textureBuffer = parent->m_writer->addTexture(m_nTxId, imageType, pixelType, buffer_size.d_width, buffer_size.d_height ); memcpy(textureBuffer->data(),buffPtr,textureBuffer->dataSize()); m_originalSize = m_size = Size( textureBuffer->nx, textureBuffer->ny ); static int n = 0; std::string fname = ftl::toString<int>(n++)+ ".png"; parent->getChunkWriter().saveTexture( textureBuffer, fname ); m_strFileName = fname; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void Direct3D9Texture::createDirect3D9Texture(const Sizef sz, D3DFORMAT format) { cleanupDirect3D9Texture(); const Sizef tex_sz(d_owner.getAdjustedSize(sz)); HRESULT hr = D3DXCreateTexture(d_owner.getDevice(), static_cast<UINT>(tex_sz.d_width), static_cast<UINT>(tex_sz.d_height), 1, 0, format, D3DPOOL_MANAGED, &d_texture); if (FAILED(hr)) CEGUI_THROW(RendererException("D3DXCreateTexture failed.")); d_dataSize = sz; updateTextureSize(); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void Direct3D10Texture::setDirect3DTexture(ID3D10Texture2D* tex) { if (d_texture != tex) { cleanupDirect3D10Texture(); d_dataSize.d_width = d_dataSize.d_height = 0; d_texture = tex; if (d_texture) d_texture->AddRef(); } initialiseShaderResourceView(); updateTextureSize(); d_dataSize = d_size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// DirectFBTexture::DirectFBTexture(IDirectFB& directfb, const Size& size) : d_directfb(directfb), d_texture(0), d_size(0, 0), d_dataSize(0, 0), d_texelScaling(0, 0) { DFBSurfaceDescription desc; desc.flags = static_cast<DFBSurfaceDescriptionFlags> (DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); desc.width = size.d_width; desc.height = size.d_height; desc.pixelformat = DSPF_ARGB; if (d_directfb.CreateSurface(&d_directfb, &desc, &d_texture)) throw RendererException("DirectFBTexture: Failed to create texture of " "specified size."); d_size = d_dataSize = size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLTexture::loadFromMemory(const void* buffer, const Size& buffer_size, PixelFormat pixel_format) { GLint comps; GLenum format; switch (pixel_format) { case PF_RGB: comps = 3; format = GL_RGB; break; case PF_RGBA: comps = 4; format = GL_RGBA; break; }; setTextureSize(buffer_size); // store size of original data we are loading d_dataSize = buffer_size; // update scale values updateCachedScaleValues(); // save old states GLuint old_tex, old_pack; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); glGetIntegerv(GL_UNPACK_ALIGNMENT, reinterpret_cast<GLint*>(&old_pack)); // do the real work of getting the data into the texture glBindTexture(GL_TEXTURE_2D, d_ogltexture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, static_cast<GLsizei>(buffer_size.d_width), static_cast<GLsizei>(buffer_size.d_height), format, GL_UNSIGNED_BYTE, buffer); // restore previous states. glPixelStorei(GL_UNPACK_ALIGNMENT, old_pack); glBindTexture(GL_TEXTURE_2D, old_tex); }
//----------------------------------------------------------------------------// void OpenGLESTexture::blitFromMemory(void* sourceData, const Rectf& area) { // store size of original data we are loading d_dataSize = area.getSize(); setTextureSize(d_dataSize); // update scale values updateCachedScaleValues(); // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // do the real work of getting the data into the texture glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, static_cast<GLsizei>(d_dataSize.d_width), static_cast<GLsizei>(d_dataSize.d_height), GL_RGBA, GL_UNSIGNED_BYTE, sourceData); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); }
void IrrlichtTexture::loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight, PixelFormat pixelFormat) { freeTexture(); irr::core::dimension2d<irr::s32> dim(buffWidth,buffHeight); irr::core::stringc name=getUniqueName(); driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,true); unsigned int pixelSize; irr::video::ECOLOR_FORMAT texFormat; switch(pixelFormat) { case PF_RGB: pixelSize = 3; texFormat = irr::video::ECF_R8G8B8; break; case PF_RGBA: pixelSize = 4; texFormat = irr::video::ECF_A8R8G8B8; break; } tex=driver->addTexture(dim,name.c_str(), texFormat); if(texFormat == tex->getColorFormat()) // paranoid! { irr::u32* tt=(irr::u32*)tex->lock(); irr::core::dimension2d<irr::s32> d=tex->getSize(); memcpy(tt,buffPtr,d.Width*d.Height*pixelSize); tex->unlock(); } tex->grab(); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void Direct3D10Texture::setOriginalDataSize(const Size& sz) { d_dataSize = sz; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void Direct3D11Texture::loadFromMemory(const void* buffer, const Sizef& buffer_size, PixelFormat pixel_format) { if (!isPixelFormatSupported(pixel_format)) CEGUI_THROW(InvalidRequestException( "Data was supplied in an unsupported pixel format.")); cleanupDirect3D11Texture(); const void* img_src = buffer; if (pixel_format == PF_RGB) { const unsigned char* src = static_cast<const unsigned char*>(buffer); unsigned char* dest = new unsigned char[static_cast<unsigned int>( buffer_size.d_width * buffer_size.d_height * 4 )]; for (int i = 0; i < buffer_size.d_width * buffer_size.d_height; ++i) { dest[i * 4 + 0] = src[i * 3 + 0]; dest[i * 4 + 1] = src[i * 3 + 1]; dest[i * 4 + 2] = src[i * 3 + 2]; dest[i * 4 + 3] = 0xFF; } img_src = dest; } D3D11_TEXTURE2D_DESC tex_desc; ZeroMemory(&tex_desc, sizeof(tex_desc)); tex_desc.Width = static_cast<UINT>(buffer_size.d_width); tex_desc.Height = static_cast<UINT>(buffer_size.d_height); tex_desc.ArraySize = 1; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Format = toD3DPixelFormat(pixel_format); tex_desc.Usage = D3D11_USAGE_DEFAULT; tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; tex_desc.CPUAccessFlags = 0; tex_desc.MiscFlags = 0; tex_desc.MipLevels = 1; D3D11_SUBRESOURCE_DATA data; ZeroMemory(&data, sizeof(D3D11_SUBRESOURCE_DATA)); data.pSysMem = img_src; data.SysMemPitch = calculateDataWidth(tex_desc.Width, pixel_format); HRESULT hr = d_device.d_device->CreateTexture2D(&tex_desc, &data, &d_texture); if (pixel_format == PF_RGB) delete[] img_src; if (FAILED(hr)) CEGUI_THROW(RendererException( "Failed to create texture from memory buffer.")); initialiseShaderResourceView(); d_dataSize = buffer_size; updateTextureSize(); updateCachedScaleValues(); }
void FlowVRCegTexture::setSize( const Size &sz ) { m_size = sz; updateCachedScaleValues(); }