Improve transition shader portability
Use #version 120 explicitly, and adapt the shader shader code accordingly, to use strictly only GLSL 1.20 constructs. Also, use less vertex attribute data in the Vortex vertex shader: We can pack the per-vertex tile x and y index and in-tile vertex index information into one float. Also, the shader can calculate the center of the tile a vertex belongs to based on the knowledge of which tile it is. Now the shader transitions work on OS X, too. Change-Id: I93e8b5069a6d06d2e412ffee322b1eb32805e606
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#version 120
|
||||
|
||||
varying vec2 v_texturePosition;
|
||||
|
||||
void main( void )
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#version 120
|
||||
|
||||
uniform sampler2D leavingSlideTexture;
|
||||
uniform sampler2D enteringSlideTexture;
|
||||
uniform sampler2D permTexture;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#version 120
|
||||
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
uniform sampler2D leavingSlideTexture;
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#version 120
|
||||
|
||||
uniform sampler2D leavingSlideTexture;
|
||||
uniform sampler2D enteringSlideTexture;
|
||||
uniform sampler2D permTexture;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#version 120
|
||||
|
||||
uniform sampler2D leavingSlideTexture;
|
||||
uniform sampler2D enteringSlideTexture;
|
||||
uniform float time;
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#version 120
|
||||
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
uniform float time;
|
||||
uniform ivec2 numTiles;
|
||||
uniform sampler2D permTexture;
|
||||
attribute vec2 tileCenter;
|
||||
attribute int tileXIndex;
|
||||
attribute int tileYIndex;
|
||||
attribute int vertexIndexInTile;
|
||||
attribute float tileInfo;
|
||||
varying vec2 v_texturePosition;
|
||||
varying float v_textureSelect;
|
||||
|
||||
@@ -52,9 +51,17 @@ void main( void )
|
||||
// at time=0.5, when the tiles there (the rightmost ones) start
|
||||
// moving.
|
||||
|
||||
// In GLSL 1.20 we don't have any bitwise operators, sigh
|
||||
|
||||
int tileXIndex = int(mod(int(tileInfo), 256));
|
||||
int tileYIndex = int(mod(int(tileInfo) / 256, 256));
|
||||
int vertexIndexInTile = int(mod(int(tileInfo) / (256*256), 256));
|
||||
|
||||
float startTime = float(tileXIndex)/(numTiles.x-1) * 0.5;
|
||||
float endTime = startTime + 0.5;
|
||||
|
||||
vec2 tileCenter = vec2(-1 + 1.5 * tileXIndex * (2.0/numTiles.x), -1 + 1.5 * tileYIndex * (2.0/numTiles.y));
|
||||
|
||||
if (time <= startTime)
|
||||
{
|
||||
// Still at start location, nothing needed
|
||||
@@ -86,7 +93,7 @@ void main( void )
|
||||
v.z += (fuzz < 0.5 ? -1 : 1) * tileCenter.x * sin(moveTime*M_PI);
|
||||
|
||||
// Perturb z a bit randomly
|
||||
v.z += ((((tileXIndex << 3) ^ tileYIndex) % 10) - 5) * (1 - abs(time-0.5)*2);
|
||||
v.z += (fuzz - 0.5) * 5 * (1 - abs(time-0.5)*2);
|
||||
|
||||
v_textureSelect = float(rotation > 0.5);
|
||||
}
|
||||
|
||||
@@ -1659,20 +1659,11 @@ class VortexTransition : public ShaderTransition
|
||||
public:
|
||||
VortexTransition(const TransitionScene& rScene, const TransitionSettings& rSettings, int nNX, int nNY)
|
||||
: ShaderTransition(rScene, rSettings)
|
||||
, mnTileCenterLocation(0)
|
||||
, mnTileXIndexLocation(0)
|
||||
, mnTileYIndexLocation(0)
|
||||
, mnVertexIndexInTileLocation(0)
|
||||
, mnTileCenterBuffer(0)
|
||||
, mnTileXIndexBuffer(0)
|
||||
, mnTileYIndexBuffer(0)
|
||||
, mnVertexIndexInTileBuffer(0)
|
||||
, mnTileInfoLocation(0)
|
||||
, mnTileInfoBuffer(0)
|
||||
, maNumTiles(nNX,nNY)
|
||||
{
|
||||
mvTileCenters.resize(6*maNumTiles.x*maNumTiles.y);
|
||||
mvTileXIndexes.resize(6*maNumTiles.x*maNumTiles.y);
|
||||
mvTileYIndexes.resize(6*maNumTiles.x*maNumTiles.y);
|
||||
mvVertexIndexesInTiles.resize(6*maNumTiles.x*maNumTiles.y);
|
||||
mvTileInfo.resize(6*maNumTiles.x*maNumTiles.y);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -1682,53 +1673,23 @@ private:
|
||||
|
||||
virtual GLuint makeShader() override;
|
||||
|
||||
GLint mnTileCenterLocation;
|
||||
GLint mnTileXIndexLocation;
|
||||
GLint mnTileYIndexLocation;
|
||||
GLint mnVertexIndexInTileLocation;
|
||||
GLuint mnTileCenterBuffer;
|
||||
GLuint mnTileXIndexBuffer;
|
||||
GLuint mnTileYIndexBuffer;
|
||||
GLuint mnVertexIndexInTileBuffer;
|
||||
GLint mnTileInfoLocation;
|
||||
GLuint mnTileInfoBuffer;
|
||||
|
||||
glm::ivec2 maNumTiles;
|
||||
|
||||
std::vector<glm::vec2> mvTileCenters;
|
||||
std::vector<GLint> mvTileXIndexes;
|
||||
std::vector<GLint> mvTileYIndexes;
|
||||
std::vector<GLint> mvVertexIndexesInTiles;
|
||||
std::vector<GLfloat> mvTileInfo;
|
||||
};
|
||||
|
||||
void VortexTransition::prepare( double, double, double, double, double )
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileCenterBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileInfoBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glEnableVertexAttribArray(mnTileCenterLocation);
|
||||
glEnableVertexAttribArray(mnTileInfoLocation);
|
||||
CHECK_GL_ERROR();
|
||||
glVertexAttribPointer(mnTileCenterLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileXIndexBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glEnableVertexAttribArray(mnTileXIndexLocation);
|
||||
CHECK_GL_ERROR();
|
||||
glVertexAttribIPointer(mnTileXIndexLocation, 1, GL_INT, 0, 0);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileYIndexBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glEnableVertexAttribArray(mnTileYIndexLocation);
|
||||
CHECK_GL_ERROR();
|
||||
glVertexAttribIPointer(mnTileYIndexLocation, 1, GL_INT, 0, 0);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnVertexIndexInTileBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glEnableVertexAttribArray(mnVertexIndexInTileLocation);
|
||||
CHECK_GL_ERROR();
|
||||
glVertexAttribIPointer(mnVertexIndexInTileLocation, 1, GL_INT, 0, 0);
|
||||
glVertexAttribPointer(mnTileInfoLocation, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
@@ -1746,13 +1707,7 @@ GLuint VortexTransition::makeShader()
|
||||
|
||||
if (nProgram)
|
||||
{
|
||||
mnTileCenterLocation = glGetAttribLocation(nProgram, "tileCenter");
|
||||
CHECK_GL_ERROR();
|
||||
mnTileXIndexLocation = glGetAttribLocation(nProgram, "tileXIndex");
|
||||
CHECK_GL_ERROR();
|
||||
mnTileYIndexLocation = glGetAttribLocation(nProgram, "tileYIndex");
|
||||
CHECK_GL_ERROR();
|
||||
mnVertexIndexInTileLocation = glGetAttribLocation(nProgram, "vertexIndexInTile");
|
||||
mnTileInfoLocation = glGetAttribLocation(nProgram, "tileInfo");
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glUseProgram(nProgram);
|
||||
@@ -1765,15 +1720,13 @@ GLuint VortexTransition::makeShader()
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
glGenBuffers(1, &mnTileCenterBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glGenBuffers(1, &mnTileXIndexBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glGenBuffers(1, &mnTileYIndexBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glGenBuffers(1, &mnVertexIndexInTileBuffer);
|
||||
glGenBuffers(1, &mnTileInfoBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
// We store the (x,y) indexes of the tile each vertex belongs to in a float, so they must fit.
|
||||
assert(maNumTiles.x < 256);
|
||||
assert(maNumTiles.y < 256);
|
||||
|
||||
// Two triangles, i.e. six vertices, per tile
|
||||
{
|
||||
int n = 0;
|
||||
@@ -1783,40 +1736,16 @@ GLuint VortexTransition::makeShader()
|
||||
{
|
||||
for (int v = 0; v < 6; v++)
|
||||
{
|
||||
// Note that Primitive::pushTriangle() has mapped the coordinates from the 0..1
|
||||
// passed to it (by makeVortex() in this case) to -1..1, and also reflected the Y
|
||||
// coordinates. Why the code can't use those from the start I don't
|
||||
// know... Confusing. Anyway, so here when we store the center of each rectangle
|
||||
// that the vertices belong to, we need to use the actual coordinates.
|
||||
mvTileCenters[n] = glm::vec2(2*((x+0.5)/maNumTiles.x) - 1, -2*((y+0.5)/maNumTiles.y) + 1);
|
||||
|
||||
mvTileXIndexes[n] = x;
|
||||
mvTileYIndexes[n] = y;
|
||||
mvVertexIndexesInTiles[n] = v;
|
||||
mvTileInfo[n] = x + (y << 8) + (v << 16);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileCenterBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileInfoBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glBufferData(GL_ARRAY_BUFFER, mvTileCenters.size()*sizeof(glm::vec2), mvTileCenters.data(), GL_STATIC_DRAW);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileXIndexBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glBufferData(GL_ARRAY_BUFFER, mvTileXIndexes.size()*sizeof(GLint), mvTileXIndexes.data(), GL_STATIC_DRAW);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnTileYIndexBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glBufferData(GL_ARRAY_BUFFER, mvTileYIndexes.size()*sizeof(GLint), mvTileYIndexes.data(), GL_STATIC_DRAW);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mnVertexIndexInTileBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
glBufferData(GL_ARRAY_BUFFER, mvVertexIndexesInTiles.size()*sizeof(GLint), mvVertexIndexesInTiles.data(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, mvTileInfo.size()*sizeof(GLfloat), mvTileInfo.data(), GL_STATIC_DRAW);
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
Reference in New Issue
Block a user