示例#1
0
//----------------------------------------------------------------------------//
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);
}
示例#2
0
//----------------------------------------------------------------------------//
void Direct3D9Texture::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."));

    const D3DFORMAT pixfmt = toD3DPixelFormat(pixel_format);
    createDirect3D9Texture(buffer_size, pixfmt);

    LPDIRECT3DSURFACE9 surface = getTextureSurface();
    const PixelBuffer pixel_buffer(buffer, buffer_size, pixel_format);

    const RECT src_rect = { 0, 0,
        static_cast<LONG>(buffer_size.d_width),
        static_cast<LONG>(buffer_size.d_height) };

    HRESULT hr = D3DXLoadSurfaceFromMemory(
            surface, 0, 0, pixel_buffer.getPixelDataPtr(),
            pixfmt == D3DFMT_X8R8G8B8 ? D3DFMT_R8G8B8 : pixfmt,
            pixel_buffer.getPitch(), 0, &src_rect, D3DX_FILTER_NONE, 0);

    surface->Release();

    if (FAILED(hr))
        CEGUI_THROW(RendererException(
            "D3DXLoadSurfaceFromMemory failed."));
}
示例#3
0
//----------------------------------------------------------------------------//
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();
}
示例#4
0
//----------------------------------------------------------------------------//
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));
}
示例#5
0
//----------------------------------------------------------------------------//
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();
}