Beispiel #1
0
void Texture::updateData(const void* pixels)
{
    if (0 == textureId || NULL == pixels) return;

    enablePalette();

    storePixelData(pixels);

    disablePalette();
}
Beispiel #2
0
void Texture::bind()
{
    glBindTexture(GL_TEXTURE_2D, textureId);

    if (filtering)
    {
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    }
    else
    {
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    }

    enablePalette();

}
Beispiel #3
0
void PagePalette::Rebuild()
{
	rebuildMasters();
	rebuildPages();
	enablePalette(m_view != 0);
}
Beispiel #4
0
bool Texture::create(int width, int height, int bitsPerPixel, const void* pixels, SDL_Color* palette, int paletteSize)
{
    this->width = width;
    this->height = height;
    this->bitsPerPixel = bitsPerPixel;
    this->pitch = (width * bitsPerPixel) / 8;
    this->size = height * pitch;

    internalFormat = 0;
    format = 0;

    bool usePalette = true;

    switch (bitsPerPixel)
    {
        case 32:
            internalFormat = GL_RGBA;
            format = GL_RGBA;
            break;
        case 24:
            internalFormat = GL_RGB;
            format = GL_RGB;
            break;
        case 8:
            if (usePalette)
            {
                #ifndef HAVE_GLES
                    internalFormat = GL_RGB;
                    format = GL_COLOR_INDEX;
                #else
                    internalFormat = GL_PALETTE8_RGB8_OES;
                    format = 0;
                #endif
            }
            else
            {
                internalFormat = 1;
                format = GL_LUMINANCE;
            }
            break;
        default:
            return false;
    }

    textureId = 0;
    glGenTextures(1, &textureId);
    glBindTexture(GL_TEXTURE_2D, textureId);
    
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);

    //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    //glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);

    if (8 == bitsPerPixel && usePalette)
    {
        this->paletteSize  = paletteSize;
        if (this->paletteSize < 256) this->paletteSize = 256;
        paletteRed   = new float[this->paletteSize];
        paletteGreen = new float[this->paletteSize];
        paletteBlue  = new float[this->paletteSize];

        for (int i=0; i<paletteSize; i++)
        {
            paletteRed[i]   = (float) palette[i].r / 256.0f;
            paletteGreen[i] = (float) palette[i].g / 256.0f;
            paletteBlue[i]  = (float) palette[i].b / 256.0f;
        }

        enablePalette();
    }

    if (NULL != pixels)
    {
        storePixelData(pixels);
    }

    glBindTexture(GL_TEXTURE_2D, 0);

    disablePalette();

    return true;

}