Skip to content
Browse files

GLVideoDriver: Some fixes (Covering, attached palettes)

  • Loading branch information...
1 parent 9926428 commit fb5bd1a8f7c4d23822e153b9fa06784f06e9f327 @BehoIder BehoIder committed with lynxlynxlynx Jan 11, 2014
View
2 gemrb/plugins/SDLVideo/GLPaletteManager.cpp
@@ -17,8 +17,8 @@ GLuint GLPaletteManager::CreatePaletteTexture(Palette* palette, unsigned int col
PaletteKey key = std::make_pair(palette, colorKey);
if (GLPaletteManager::textures.find(key) == GLPaletteManager::textures.end())
{
- GLuint texture;
// not found, we need to create it
+ GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
View
45 gemrb/plugins/SDLVideo/GLTextureSprite2D.cpp
@@ -24,8 +24,10 @@ GLTextureSprite2D::GLTextureSprite2D (int Width, int Height, int Bpp, void* pixe
Uint32 bmask, Uint32 amask) : Sprite2D(Width, Height, Bpp, pixels)
{
currentPalette = NULL;
+ attachedPalette = NULL;
glTexture = 0;
glPaletteTexture = 0;
+ glAttachedPaletteTexture = 0;
glMaskTexture = 0;
colorKeyIndex = 0; // invalid index
rMask = rmask;
@@ -38,8 +40,10 @@ GLTextureSprite2D::~GLTextureSprite2D()
{
if (glTexture != 0) glDeleteTextures(1, &glTexture);
if (glMaskTexture != 0) glDeleteTextures(1, &glMaskTexture);
- if (IsPaletted() && glPaletteTexture != 0)
- GLPaletteManager::RemovePaletteTexture(glPaletteTexture);
+ if (glPaletteTexture != 0)
+ GLPaletteManager::RemovePaletteTexture(currentPalette, colorKeyIndex);
+ if (glAttachedPaletteTexture != 0)
+ GLPaletteManager::RemovePaletteTexture(attachedPalette, colorKeyIndex);
}
GLTextureSprite2D::GLTextureSprite2D(const GLTextureSprite2D &obj) : Sprite2D(obj)
@@ -48,7 +52,9 @@ GLTextureSprite2D::GLTextureSprite2D(const GLTextureSprite2D &obj) : Sprite2D(ob
glTexture = 0;
glMaskTexture = 0;
glPaletteTexture = 0;
+ glAttachedPaletteTexture = 0;
currentPalette = NULL;
+ attachedPalette = NULL;
colorKeyIndex = obj.colorKeyIndex;
rMask = obj.rMask;
gMask = obj.bMask;
@@ -64,18 +70,15 @@ GLTextureSprite2D* GLTextureSprite2D::copy() const
void GLTextureSprite2D::SetPalette(Palette *pal)
{
- if(!IsPaletted() || currentPalette == pal) return;
- if (pal != NULL)
- {
- pal->acquire();
- }
- if (currentPalette != NULL)
+ if(!IsPaletted() || currentPalette == pal || !pal) return;
+ pal->acquire();
+ if (currentPalette)
{
currentPalette->release();
}
- if (glPaletteTexture != 0) GLPaletteManager::RemovePaletteTexture(glPaletteTexture);
- currentPalette = pal;
+ if (glPaletteTexture != 0) GLPaletteManager::RemovePaletteTexture(currentPalette, colorKeyIndex);
glPaletteTexture = 0;
+ currentPalette = pal;
}
Palette* GLTextureSprite2D::GetPalette() const
@@ -91,8 +94,10 @@ void GLTextureSprite2D::SetColorKey(ieDword index)
if(IsPaletted())
{
glDeleteTextures(1, &glMaskTexture);
- if (glPaletteTexture != 0) GLPaletteManager::RemovePaletteTexture(glPaletteTexture);
+ if (glPaletteTexture != 0) GLPaletteManager::RemovePaletteTexture(currentPalette, colorKeyIndex);
+ if (glAttachedPaletteTexture != 0) GLPaletteManager::RemovePaletteTexture(attachedPalette, colorKeyIndex);
glPaletteTexture = 0;
+ glAttachedPaletteTexture = 0;
glMaskTexture = 0;
}
else
@@ -185,16 +190,16 @@ GLuint GLTextureSprite2D::GetPaletteTexture()
return glPaletteTexture;
}
-GLuint GLTextureSprite2D::GetPaletteTexture(Palette* pal)
+// use this method only for adding external palettes
+GLuint GLTextureSprite2D::GetPaletteTexture(Palette* attached)
{
- if (pal == NULL || !IsPaletted()) return 0; // nothing to do
-
- // we already have a texture from requested palette
- if (pal == currentPalette && glPaletteTexture != 0) return glPaletteTexture;
-
- SetPalette(pal);
- createGlTextureForPalette();
- return glPaletteTexture;
+ if (attached == NULL || !IsPaletted()) return 0; // nothing to do
+
+ // we already have a texture for requested palette
+ if (attached == attachedPalette && glAttachedPaletteTexture != 0) return glAttachedPaletteTexture;
+ attachedPalette = attached;
+ glAttachedPaletteTexture = GLPaletteManager::CreatePaletteTexture(attachedPalette, colorKeyIndex);
+ return glAttachedPaletteTexture;
}
GLuint GLTextureSprite2D::GetMaskTexture()
View
4 gemrb/plugins/SDLVideo/GLTextureSprite2D.h
@@ -15,6 +15,10 @@ namespace GemRB
Uint32 rMask, gMask, bMask, aMask;
ieDword colorKeyIndex;
+ // blitSprite used attached palette
+ Palette* attachedPalette;
+ GLuint glAttachedPaletteTexture;
+
void createGlTexture();
void createGlTextureForPalette();
void createGLMaskTexture();
View
52 gemrb/plugins/SDLVideo/SDL20GLVideo.cpp
@@ -431,19 +431,17 @@ void GLVideoDriver::blitSprite(GLTextureSprite2D* spr, int x, int y, const Regio
program = programPal;
}
else
+ {
program = program32;
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
useProgram(program);
glActiveTexture(GL_TEXTURE0);
GLuint texture = spr->GetTexture();
glBindTexture(GL_TEXTURE_2D, texture);
- if (spr->IsPaletted())
- {
- glActiveTexture(GL_TEXTURE1);
- GLuint palTexture = spr->GetPaletteTexture();
- glBindTexture(GL_TEXTURE_2D, palTexture);
- }
if (mask)
{
glActiveTexture(GL_TEXTURE2);
@@ -499,12 +497,19 @@ void GLVideoDriver::BlitTile(const Sprite2D* spr, const Sprite2D* mask, int x, i
if (flags & TILE_HALFTRANS) blitFlags |= BLIT_HALFTRANS;
if (flags & TILE_GREY) blitFlags |= BLIT_GREY;
if (flags & TILE_SEPIA) blitFlags |= BLIT_SEPIA;
+ GLTextureSprite2D* glSprite = (GLTextureSprite2D*)spr;
+ if (glSprite->IsPaletted())
+ {
+ GLuint palTexture = glSprite->GetPaletteTexture();
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, palTexture);
+ }
if (core->GetGame())
{
const Color* totint = core->GetGame()->GetGlobalTint();
- return blitSprite((GLTextureSprite2D*)spr, tx, ty, clip, blitFlags, totint, (GLTextureSprite2D*)mask);
+ return blitSprite(glSprite, tx, ty, clip, blitFlags, totint, (GLTextureSprite2D*)mask);
}
- return blitSprite((GLTextureSprite2D*)spr, tx, ty, clip, blitFlags, NULL, (GLTextureSprite2D*)mask);
+ return blitSprite(glSprite, tx, ty, clip, blitFlags, NULL, (GLTextureSprite2D*)mask);
}
@@ -519,9 +524,13 @@ void GLVideoDriver::BlitSprite(const Sprite2D* spr, int x, int y, bool anchor, c
tx -= Viewport.x;
ty -= Viewport.y;
}
- if (palette || glSprite->IsPaletted())
+ if (glSprite->IsPaletted())
{
- if (palette) glSprite->SetPalette(palette);
+ GLuint palTexture;
+ if (palette) palTexture = glSprite->GetPaletteTexture(palette);
+ else palTexture = glSprite->GetPaletteTexture();
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, palTexture);
}
return blitSprite(glSprite, tx, ty, clip);
@@ -572,10 +581,15 @@ void GLVideoDriver::BlitGameSprite(const Sprite2D* spr, int x, int y, unsigned i
flags |= BLIT_EXTERNAL_MASK;
}
- if (palette)
+ if (glSprite->IsPaletted())
{
- if (palette) glSprite->SetPalette(palette);
+ GLuint palTexture;
+ if (palette) palTexture = glSprite->GetPaletteTexture(palette);
+ else palTexture = glSprite->GetPaletteTexture();
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, palTexture);
}
+
if (!anchor && core->GetGame())
{
const Color *totint = core->GetGame()->GetGlobalTint();
@@ -594,7 +608,10 @@ void GLVideoDriver::BlitGameSprite(const Sprite2D* spr, int x, int y, unsigned i
}
blitSprite(glSprite, tx, ty, clip, flags, &tint);
}
+ else blitSprite(glSprite, tx, ty, clip, flags);
}
+ else
+ blitSprite(glSprite, tx, ty, clip, flags);
}
else
blitSprite(glSprite, tx, ty, clip, flags);
@@ -696,6 +713,17 @@ void GLVideoDriver::DestroyMovieScreen()
SDL20VideoDriver::DestroyMovieScreen();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_SCISSOR_TEST);
+}
+
+Sprite2D* GLVideoDriver::GetScreenshot(Region r)
+{
+ unsigned int w = r.w ? r.w : width - r.x;
+ unsigned int h = r.h ? r.h : height - r.y;
+ Uint8* pixels = new Uint8[3*w*h];
+ glReadPixels(r.x, r.y, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+ Sprite2D* screenshot = new GLTextureSprite2D(w, h, 24, pixels, 0x00ff0000, 0x0000ff00, 0x000000ff);
+ return screenshot;
}
#include "plugindef.h"
View
1 gemrb/plugins/SDLVideo/SDL20GLVideo.h
@@ -49,6 +49,7 @@ namespace GemRB
void DrawHLine(short x1, short y, short x2, const Color& color, bool clipped = false);
void DrawVLine(short x, short y1, short y2, const Color& color, bool clipped = false);
void DestroyMovieScreen();
+ Sprite2D* GetScreenshot(Region r);
};
}

0 comments on commit fb5bd1a

Please sign in to comment.
Something went wrong with that request. Please try again.