SLUDGE: Implement Dissolve transition

This commit is contained in:
Eugene Sandulenko
2021-05-16 17:09:32 +02:00
parent 345537c519
commit ada51d0b49
3 changed files with 57 additions and 92 deletions
+7
View File
@@ -90,6 +90,7 @@ void GraphicsManager::init() {
resetRandW();
_brightnessLevel = 255;
_fadeMode = 2;
_transitionTexture = nullptr;
}
void GraphicsManager::kill() {
@@ -142,6 +143,12 @@ void GraphicsManager::kill() {
if (_origBackdropSurface.getPixels())
_origBackdropSurface.free();
if (_transitionTexture) {
_transitionTexture->free();
delete _transitionTexture;
_transitionTexture = nullptr;
}
}
bool GraphicsManager::initGfx() {
+8
View File
@@ -185,8 +185,10 @@ public:
void setFadeMode(int fadeMode) { _fadeMode = fadeMode; };
void fixBrightness();
void resetRandW();
void reserveTransitionTexture();
void transitionFader();
void transitionDisolve();
private:
SludgeEngine *_vm;
@@ -244,6 +246,12 @@ private:
byte _brightnessLevel;
byte _fadeMode;
#define RANDKK 17
uint32 _randbuffer[RANDKK][2];
int _randp1, _randp2;
Graphics::TransparentSurface *_transitionTexture;
// Parallax
ParallaxLayers *_parallaxLayers;
+42 -92
View File
@@ -20,6 +20,7 @@
*
*/
#include "common/textconsole.h"
#include "sludge/graphics.h"
namespace Sludge {
@@ -124,121 +125,68 @@ void transitionSnapshotBox() {
// FAST PSEUDO-RANDOM NUMBER STUFF FOR DISOLVE EFFECT
//----------------------------------------------------
#define KK 17
uint32 randbuffer[KK][2]; // history buffer
int p1, p2;
void GraphicsManager::resetRandW() {
int32 seed = 12345;
for (int i = 0; i < KK; i++) {
for (int i = 0; i < RANDKK; i++) {
for (int j = 0; j < 2; j++) {
seed = seed * 2891336453u + 1;
randbuffer[i][j] = seed;
_randbuffer[i][j] = seed;
}
}
p1 = 0;
p2 = 10;
_randp1 = 0;
_randp2 = 10;
}
#if 0
GLubyte *transitionTexture = NULL;
GLuint transitionTextureName = 0;
#endif
void GraphicsManager::reserveTransitionTexture() {
_transitionTexture = new Graphics::TransparentSurface;
bool reserveTransitionTexture() {
#if 0
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (! transitionTexture) {
transitionTexture = new GLubyte [256 * 256 * 4];
if (! checkNew(transitionTexture)) return false;
}
if (! transitionTextureName) glGenTextures(1, &transitionTextureName);
glBindTexture(GL_TEXTURE_2D, transitionTextureName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, transitionTexture, transitionTextureName);
#endif
return true;
_transitionTexture->create(256, 256, _transitionTexture->getSupportedPixelFormat());
}
void transitionDisolve() {
void GraphicsManager::transitionDisolve() {
if (!_transitionTexture)
reserveTransitionTexture();
#if 0
if (! transitionTextureName) reserveTransitionTexture();
if (! brightnessLevel) {
if (!_brightnessLevel) {
transitionFader();
return;
}
uint32 n;
uint32 y;
GLubyte *toScreen = transitionTexture;
GLubyte *end = transitionTexture + (256 * 256 * 4);
byte *toScreen = (byte *)_transitionTexture->getPixels();
byte *end = (byte *)_transitionTexture->getBasePtr(255, 255);
do {
// generate next number
n = randbuffer[p1][1];
y = (n << 27) | ((n >> (32 - 27)) + randbuffer[p2][1]);
uint32 n = _randbuffer[_randp1][1];
uint32 y = (n << 27) | ((n >> (32 - 27)) + _randbuffer[_randp2][1]);
n = randbuffer[p1][0];
randbuffer[p1][1] = (n << 19) | ((n >> (32 - 19)) + randbuffer[p2][0]);
randbuffer[p1][0] = y;
n = _randbuffer[_randp1][0];
_randbuffer[_randp1][1] = (n << 19) | ((n >> (32 - 19)) + _randbuffer[_randp2][0]);
_randbuffer[_randp1][0] = y;
// rotate list pointers
if (! p1 --) p1 = KK - 1;
if (! p2 --) p2 = KK - 1;
if (!_randp1--)
_randp1 = RANDKK - 1;
if (!_randp2--)
_randp2 = RANDKK - 1;
if ((y & 255u) > brightnessLevel) {
toScreen[0] = toScreen[1] = toScreen[2] = 0;
toScreen[3] = 255;
if ((y & 0xff) > _brightnessLevel) {
toScreen[0] = 255;
toScreen[1] = toScreen[2] = toScreen[3] = 0;
} else {
toScreen[0] = toScreen[1] = toScreen[2] = toScreen[3] = 0;
}
toScreen += 4;
}while (toScreen < end);
} while (toScreen < end);
texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, transitionTexture, transitionTextureName);
glEnable(GL_BLEND);
const GLfloat vertices[] = {
0.f, (GLfloat)winHeight, 0.f,
(GLfloat)winWidth, (GLfloat)winHeight, 0.f,
0.f, 0.f, 0.f,
(GLfloat)winWidth, 0.f, 0.f
};
const GLfloat texCoords[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f
};
glUseProgram(shader.texture);
setPMVMatrix(shader.texture);
glUniform1i(glGetUniformLocation(shader.texture, "modulateColor"), 1);
setPrimaryColor(1.0f, 1.0f, 1.0f, 1.0f);
drawQuad(shader.texture, vertices, 1, texCoords);
glUniform1i(glGetUniformLocation(shader.texture, "modulateColor"), 0);
glUseProgram(0);
glDisable(GL_BLEND);
#endif
// The original stretched the texture, we just tile it
for (uint y = 0; y < _sceneHeight; y += _transitionTexture->h) {
for (uint x = 0; x < _sceneWidth; x += _transitionTexture->w) {
_transitionTexture->blit(_renderSurface, x, y);
}
}
}
void transitionTV() {
@@ -254,16 +202,18 @@ void transitionTV() {
do {
// generate next number
n = randbuffer[p1][1];
y = (n << 27) | ((n >> (32 - 27)) + randbuffer[p2][1]);
n = _randbuffer[_randp1][1];
y = (n << 27) | ((n >> (32 - 27)) + _randbuffer[_randp2][1]);
n = randbuffer[p1][0];
randbuffer[p1][1] = (n << 19) | ((n >> (32 - 19)) + randbuffer[p2][0]);
randbuffer[p1][0] = y;
n = _randbuffer[_randp1][0];
_randbuffer[_randp1][1] = (n << 19) | ((n >> (32 - 19)) + _randbuffer[_randp2][0]);
_randbuffer[_randp1][0] = y;
// rotate list pointers
if (! p1 --) p1 = KK - 1;
if (! p2 --) p2 = KK - 1;
if (!_randp1--)
_randp1 = RANDKK - 1;
if (!_randp2--)
_randp2 = RANDKK - 1;
if ((y & 255u) > brightnessLevel) {
toScreen[0] = toScreen[1] = toScreen[2] = (n & 255);