Merge remote-tracking branch 'upstream/master' into SmoothMoveCamera

This commit is contained in:
Dk
2014-04-03 15:45:45 +05:30
213 changed files with 5207 additions and 3633 deletions

BIN
data/gui/scroll_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
data/gui/scroll_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -9,12 +9,12 @@ varying vec2 uv;
#define FragColor gl_FragColor
#endif
vec3 getCIEYxy(vec3 rgbColor);
void main()
{
vec3 weights = vec3(0.2126, 0.7152, 0.0722); // ITU-R BT. 709
vec3 col = texture(tex, uv).xyz;
float luma = dot(weights, col);
float luma = getCIEYxy(col).x;
col *= smoothstep(1., 2., luma);

View File

@@ -1,3 +1,7 @@
//#define DOF_ENABLED
#ifdef DOF_ENABLED
uniform sampler2D tex;
uniform sampler2D dtex;
uniform vec3 inlevel;
@@ -198,13 +202,17 @@ void main()
}*/
#else
/*uniform sampler2D tex;
//#define AUTO_EXPOSURE
uniform sampler2D tex;
uniform sampler2D dtex;
uniform vec3 inlevel;
uniform vec2 outlevel;
uniform mat4 invprojm;
uniform sampler2D logluminancetex;
#if __VERSION__ >= 130
in vec2 uv;
@@ -214,11 +222,26 @@ varying vec2 uv;
#define FragColor gl_FragColor
#endif
vec3 getCIEYxy(vec3 rgbColor);
vec3 getRGBFromCIEXxy(vec3 YxyColor);
float exposure = .1;
float whitePoint = 2.5;
float delta = 0.0001;
void main()
{
vec4 col = texture(tex, uv);
#ifdef AUTO_EXPOSURE
float avgLuminance = textureLod(logluminancetex, uv, 10.).x;
avgLuminance = exp(avgLuminance) - delta;
vec3 Yxy = getCIEYxy(col.xyz);
float a = max(0, 1.5 - 1.5 / (avgLuminance * .1 + 1)) + .1;
float Lp = Yxy.r * a / avgLuminance;
Yxy.r = (Lp * (1. * Lp / (whitePoint * whitePoint))) / (1. + Lp);
col.xyz = getRGBFromCIEXxy(Yxy);
#endif
float curdepth = texture(dtex, uv).x;
vec4 FragPos = invprojm * (2.0 * vec4(uv, curdepth, 1.0f) - 1.0f);
@@ -246,4 +269,5 @@ void main()
FragColor = vec4(colFinal * vignette, 1.0);
//FragColor = vec4(vec3(depth), 1.0);
}*/
}
#endif

View File

@@ -42,6 +42,6 @@ void main(void)
float g = dot(extendednormal, gmat * extendednormal);
float b = dot(extendednormal, bmat * extendednormal);
Diff = 0.25 * vec4(r, g, b, .1);
Diff = max(0.25 * vec4(r, g, b, .1), vec4(0.));
Spec = vec4(0.);
}

View File

@@ -12,6 +12,7 @@ in float anglespeed;
out float lf;
out vec2 tc;
out vec3 pc;
void main(void)
{
@@ -57,4 +58,5 @@ void main(void)
vec4 viewpos = ViewMatrix * vec4(newposition + newquadcorner, 1.0);
gl_Position = ProjectionMatrix * viewpos;
pc = vec3(1.);
}

View File

@@ -0,0 +1,34 @@
uniform sampler2D Albedo;
uniform vec3 SunDir;
uniform mat4 invproj;
uniform sampler2D dtex;
uniform vec2 screen;
in vec3 nor;
in vec2 uv;
out vec4 FragColor;
vec3 getLightFactor(float specMapValue);
void main(void)
{
vec2 texc = gl_FragCoord.xy / screen;
float z = texture(dtex, texc).x;
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
xpos = invproj * xpos;
xpos /= xpos.w;
vec3 eyedir = normalize(xpos.xyz);
// Inspired from http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html
float fEdotL = max(0., dot(SunDir, eyedir));
float fPowEdotL = pow(fEdotL, 4.);
float fLdotNBack = max(0., - dot(nor, SunDir) * 0.6 + 0.4);
float scattering = mix(fPowEdotL, fLdotNBack, .5);
vec4 color = texture(Albedo, uv);
if (color.a < 0.5) discard;
vec3 LightFactor = scattering + getLightFactor(1.);
FragColor = vec4(color.xyz * LightFactor, 1.);
}

View File

@@ -1,20 +0,0 @@
uniform vec3 windDir;
uniform mat4 ModelViewProjectionMatrix;
#if __VERSION__ >= 130
in vec3 Position;
in vec2 Texcoord;
in vec4 Color;
out vec2 uv;
#else
attribute vec3 Position;
attribute vec2 Texcoord;
attribute vec4 Color;
varying vec2 uv;
#endif
void main()
{
uv = Texcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position + windDir * Color.r, 1.);
}

View File

@@ -0,0 +1,27 @@
uniform vec3 windDir;
uniform mat4 ViewProjectionMatrix;
uniform mat4 InverseViewMatrix;
in vec3 Origin;
in vec3 Orientation;
in vec3 Scale;
in vec3 Position;
in vec3 Normal;
in vec2 Texcoord;
in vec4 Color;
out vec3 nor;
out vec2 uv;
mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
void main()
{
mat4 ModelMatrix = getWorldMatrix(Origin + windDir * Color.r, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + windDir * Color.r, Orientation, Scale) * InverseViewMatrix);
gl_Position = ViewProjectionMatrix * ModelMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
}

View File

@@ -0,0 +1,25 @@
uniform mat4 ViewProjectionMatrix;
uniform mat4 InverseViewMatrix;
in vec3 Origin;
in vec3 Orientation;
in vec3 Scale;
in vec3 Position;
in vec3 Normal;
in vec2 Texcoord;
out vec3 nor;
out vec2 uv;
mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
void main(void)
{
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix);
gl_Position = ViewProjectionMatrix * ModelMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
}

View File

@@ -0,0 +1,18 @@
in vec3 Origin;
in vec3 Orientation;
in vec3 Scale;
in vec3 Position;
in vec2 Texcoord;
out vec2 tc;
mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
void main(void)
{
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
gl_Position = ModelMatrix * vec4(Position, 1.);
tc = Texcoord;
}

View File

@@ -0,0 +1,14 @@
uniform sampler2D tex;
in vec2 uv;
out vec4 FragColor;
float delta = 0.0001;
void main()
{
vec3 weight = vec3(0.2125f, 0.7154f, 0.0721f);
vec3 col = texture(tex, uv).xyz;
float luma = dot(col, weight);
FragColor = vec4(log(luma + delta));
}

View File

@@ -1,14 +1,13 @@
#version 330 compatibility
#define MAX_SEARCH_STEPS 8.0
#define MAX_DISTANCE 33.0
#extension GL_ARB_shader_texture_lod: enable
uniform sampler2D edgesMap;
uniform sampler2D areaMap;
uniform vec2 PIXEL_SIZE;
#define MAX_SEARCH_STEPS 8.0
#define MAX_DISTANCE 33.0
in vec2 uv;
out vec4 FragColor;
/**
@@ -17,7 +16,7 @@ out vec4 FragColor;
* bit.
*/
vec4 tex2Doffset(sampler2D map, vec2 texcoord, vec2 offset) {
return texture2DLod(map, texcoord + PIXEL_SIZE * offset, 0.0);
return textureLod(map, texcoord + PIXEL_SIZE * offset, 0.0);
}
float SearchXLeft(vec2 texcoord) {
@@ -79,16 +78,16 @@ vec2 Area(vec2 distance, float e1, float e2) {
void main() {
vec4 areas = vec4(0.0);
vec2 e = texture(edgesMap, gl_TexCoord[0].xy).rg;
vec2 e = texture(edgesMap, uv).rg;
if (e.g != 0.0) { // Edge at north
// Search distances to the left and to the right:
vec2 d = vec2(SearchXLeft(gl_TexCoord[0].xy), SearchXRight(gl_TexCoord[0].xy));
vec2 d = vec2(SearchXLeft(uv), SearchXRight(uv);
// Now fetch the crossing edges. Instead of sampling between edgels, we
// sample at 0.25, to be able to discern what value has each edgel:
vec4 coords = vec4(d.x, 0.25, d.y + 1.0, 0.25) * PIXEL_SIZE.xyxy + gl_TexCoord[0].xyxy;
vec4 coords = vec4(d.x, 0.25, d.y + 1.0, 0.25) * PIXEL_SIZE.xyxy + uv.xyxy;
float e1 = texture2DLod(edgesMap, coords.xy, 0.0).r;
float e2 = texture2DLod(edgesMap, coords.zw, 0.0).r;
@@ -100,10 +99,10 @@ void main() {
if (e.r != 0.0) { // Edge at west
// Search distances to the top and to the bottom:
vec2 d = vec2(SearchYUp(gl_TexCoord[0].xy), SearchYDown(gl_TexCoord[0].xy));
vec2 d = vec2(SearchYUp(uv), SearchYDown(uv));
// Now fetch the crossing edges (yet again):
vec4 coords = vec4(-0.25, d.x, -0.25, d.y - 1.0) * PIXEL_SIZE.xyxy + gl_TexCoord[0].xyxy;
vec4 coords = vec4(-0.25, d.x, -0.25, d.y - 1.0) * PIXEL_SIZE.xyxy + uv.xyxy;
float e1 = texture2DLod(edgesMap, coords.xy, 0.0).g;
float e2 = texture2DLod(edgesMap, coords.zw, 0.0).g;

View File

@@ -1,8 +1,8 @@
#version 330 compatibility
uniform sampler2D colorMapG;
in vec4 offset[2];
in vec2 uv;
uniform sampler2D colorMapG;
const float threshold = 0.1;
out vec4 FragColor;

View File

@@ -1,11 +1,11 @@
#version 330 compatibility
in vec4 offset[2];
in vec2 uv;
out vec4 FragColor;
uniform sampler2D blendMap;
uniform sampler2D colorMap;
in vec4 offset[2];
in vec2 uv;
out vec4 FragColor;
void main() {
// Fetch the blending weights for current pixel:
vec4 topLeft = texture(blendMap, uv);

View File

@@ -1,13 +1,14 @@
#version 330 compatibility
uniform vec2 PIXEL_SIZE;
uniform mat4 ModelViewProjectionMatrix;
in vec2 Position;
in vec2 Texcoord;
out vec4 offset[2];
out vec2 uv;
void main() {
gl_Position = ModelViewProjectionMatrix * gl_Vertex;
vec4 invy = gl_MultiTexCoord0;
gl_Position = vec4(Position, 0., 1.);
vec4 invy = vec4(Texcoord, Texcoord);
// invy.y = 1.0 - invy.y;
uv = invy.st;

View File

@@ -8,23 +8,27 @@ uniform mat4 TextureMatrix =
#if __VERSION__ >= 130
in vec3 Position;
in vec3 Normal;
in vec2 Texcoord;
in vec2 SecondTexcoord;
in vec3 Normal;
out vec3 nor;
out vec2 uv;
out vec2 uv_bis;
#else
attribute vec3 Position;
attribute vec3 Normal;
attribute vec2 Texcoord;
attribute vec2 SecondTexcoord;
varying vec3 nor;
varying vec2 uv;
varying vec2 uv_bis;
#endif
void main(void)
{
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv_bis = SecondTexcoord;
}

View File

@@ -1,19 +0,0 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;
#if __VERSION__ >= 130
in vec3 Position;
in vec3 Normal;
out vec3 nor;
#else
attribute vec3 Position;
attribute vec3 Normal;
varying vec3 nor;
#endif
void main(void)
{
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
}

View File

@@ -1,28 +0,0 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TextureMatrix =
mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1.);
#if __VERSION__ >= 130
in vec3 Position;
in vec2 Texcoord;
in vec2 SecondTexcoord;
out vec2 uv;
out vec2 uv_bis;
#else
attribute vec3 Position;
attribute vec2 Texcoord;
attribute vec2 SecondTexcoord;
varying vec2 uv;
varying vec2 uv_bis;
#endif
void main(void)
{
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv_bis = SecondTexcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}

View File

@@ -1,23 +1,36 @@
uniform mat4 ModelViewProjectionMatrix[4];
uniform mat4 ViewProjectionMatrix[4];
#if __VERSION__ >= 400
layout(triangles, invocations=4) in;
#else
layout(triangles) in;
#endif
layout(triangle_strip, max_vertices=12) out;
in vec2 tc[3];
out vec2 uv;
void emitToLayer(int layerId)
{
gl_Layer = layerId;
for(int i=0; i<3; i++)
{
uv = tc[i];
gl_Position = ViewProjectionMatrix[layerId] * gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
void main(void)
{
#if __VERSION__ >= 400
emitToLayer(gl_InvocationID);
#else
for (int j = 0; j<4; j++)
{
gl_Layer = j;
for(int i=0; i<3; i++)
{
uv = tc[i];
gl_Position = ModelViewProjectionMatrix[j] * gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
emitToLayer(j);
}
#endif
}

View File

@@ -1,12 +1,12 @@
uniform mat4 ModelMatrix;
in vec3 Position;
in vec2 Texcoord;
out vec2 tc;
void main(void)
{
tc = Texcoord;
gl_Position = vec4(Position, 1.);
gl_Position = ModelMatrix * vec4(Position, 1.);
}

View File

@@ -0,0 +1,16 @@
uniform sampler2D tex;
uniform ivec4 color;
#if __VERSION__ >= 130
in vec2 uv;
out vec4 FragColor;
#else
varying vec2 uv;
#define FragColor gl_FragColor
#endif
void main()
{
vec4 res = texture(tex, uv);
FragColor = vec4(res.xyz * color.xyz / 255., res.a);
}

View File

@@ -0,0 +1,17 @@
// Using numerical value from here
// http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering
vec3 getCIEYxy(vec3 rgbColor)
{
// convert rgb to srgb
vec3 sRGBColor = rgbColor;//vec3(pow(rgbColor.x, 1. / 2.2), pow(rgbColor.y, 1. / 2.2), pow(rgbColor.z, 1. / 2.2));
mat3 sRGB2XYZ = transpose(mat3(
vec3(.4125, .2126, .0193),
vec3(.3576, .7152, .1192),
vec3(.1805, .0722, .9505)));
vec3 XYZ = sRGB2XYZ * sRGBColor;
float sum = dot(vec3(1.), XYZ);
return vec3(XYZ.y, XYZ.xy / sum);
}

View File

@@ -11,5 +11,5 @@ vec3 getLightFactor(float specMapValue)
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
float ao = texture(SSAO, tc).x;
vec3 tmp = ao * ambient + DiffuseComponent + SpecularComponent * specMapValue;
return tmp * (0.4 + ao*0.6);
return tmp * ao;
}

View File

@@ -0,0 +1,17 @@
// Using numerical value from here
// http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering
vec3 getRGBFromCIEXxy(vec3 YxyColor)
{
float Yovery = YxyColor.x / YxyColor.z;
vec3 XYZ = vec3(YxyColor.y * Yovery, YxyColor.x, (1. - YxyColor.y - YxyColor.z) * Yovery);
mat3 XYZ2sRGB = transpose(mat3(
vec3(3.2405, -.9693, .0556),
vec3(-1.5371, 1.8760, -.2040),
vec3(-.4985, .0416, 1.0572)));
vec3 sRGBColor = XYZ2sRGB * XYZ;
return sRGBColor;//vec3(pow(sRGBColor.x, 2.2), pow(sRGBColor.y, 2.2), pow(sRGBColor.z, 2.2));
}

View File

@@ -0,0 +1,50 @@
const float DEG2GRAD = 3.14 / 180.;
mat4 getMatrixFromRotation(vec3 rotation)
{
// from irrlicht
float cr = cos(DEG2GRAD * rotation.x );
float sr = sin(DEG2GRAD * rotation.x );
float cp = cos(DEG2GRAD * rotation.y );
float sp = sin(DEG2GRAD * rotation.y );
float cy = cos(DEG2GRAD * rotation.z );
float sy = sin(DEG2GRAD * rotation.z );
float srsp = sr*sp;
float crsp = cr*sp;
return transpose(mat4(
vec4(cp * cy, srsp * cy - cr * sy, crsp * cy + sr * sy, 0.),
vec4(cp * sy, srsp * sy + cr * cy, crsp * sy - sr * cy, 0.),
vec4(-sp, sr * cp, cr * cp, 0.),
vec4(0., 0., 0., 1.)));
}
mat4 getScaleMatrix(vec3 scale)
{
mat4 result = mat4(
vec4(scale.x, 0., 0., 0.),
vec4(0., scale.y, 0., 0.),
vec4(0., 0., scale.z, 0.),
vec4(0., 0., 0., 1.)
);
return result;
}
mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale)
{
mat4 result = getMatrixFromRotation(rotation);
// translation
result[3].xyz += translation;
return result * getScaleMatrix(scale);
}
mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale)
{
mat4 result = transpose(getMatrixFromRotation(rotation));
// FIXME: it's wrong but the fourth column is not used
result[3].xyz -= translation;
return getScaleMatrix(1. / scale) * result;
}

View File

@@ -84,6 +84,52 @@ bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData, CIrr
return true;
}
static PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs_ARB;
static HGLRC getMeAGLContext(HDC HDc)
{
HGLRC hrc = 0;
int ctx40[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
hrc = wglCreateContextAttribs_ARB(HDc, 0, ctx40);
if (hrc)
return hrc;
int ctx33[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
hrc = wglCreateContextAttribs_ARB(HDc, 0, ctx33);
if (hrc)
return hrc;
int ctx31[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
hrc = wglCreateContextAttribs_ARB(HDc, 0, ctx31);
if (hrc)
return hrc;
return NULL;
}
//! inits the open gl driver
bool COpenGLDriver::initDriver(CIrrDeviceWin32* device)
{
@@ -339,7 +385,7 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device)
#endif
AntiAlias=0;
#ifdef WGL_ARB_create_context
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs_ARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
wglCreateContextAttribs_ARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
#endif
wglMakeCurrent(HDc, NULL);
wglDeleteContext(hrc);
@@ -409,22 +455,7 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device)
#ifdef WGL_ARB_create_context
if (wglCreateContextAttribs_ARB)
{
int iAttribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //WGL_CONTEXT_CORE_PROFILE_BIT_ARB
0
};
// hd3000 only provides 3.1, so try all minor versions backwards, to find one that works.
for (int minor = 3; minor >= 0; minor--)
{
iAttribs[3] = minor;
hrc = wglCreateContextAttribs_ARB(HDc, 0, iAttribs);
if (hrc)
break;
}
hrc = getMeAGLContext(HDc);
}
else
#endif

View File

@@ -31,7 +31,6 @@ src/graphics/callbacks.cpp
src/graphics/camera.cpp
src/graphics/CBatchingMesh.cpp
src/graphics/explosion.cpp
src/graphics/glow.cpp
src/graphics/glwrap.cpp
src/graphics/gpuparticles.cpp
src/graphics/hardware_skinning.cpp
@@ -63,6 +62,7 @@ src/graphics/slip_stream.cpp
src/graphics/stars.cpp
src/graphics/stkanimatedmesh.cpp
src/graphics/stkbillboard.cpp
src/graphics/stkinstancedscenenode.cpp
src/graphics/stkmesh.cpp
src/graphics/stkmeshscenenode.cpp
src/graphics/sun.cpp
@@ -304,7 +304,7 @@ src/tracks/check_manager.cpp
src/tracks/check_sphere.cpp
src/tracks/check_structure.cpp
src/tracks/graph_node.cpp
src/tracks/lod_node_loader.cpp
src/tracks/model_definition_loader.cpp
src/tracks/quad.cpp
src/tracks/quad_graph.cpp
src/tracks/quad_set.cpp
@@ -365,7 +365,6 @@ src/graphics/callbacks.hpp
src/graphics/camera.hpp
src/graphics/CBatchingMesh.hpp
src/graphics/explosion.hpp
src/graphics/glow.hpp
src/graphics/glwrap.hpp
src/graphics/gpuparticles.hpp
src/graphics/hardware_skinning.hpp
@@ -399,6 +398,7 @@ src/graphics/slip_stream.hpp
src/graphics/stars.hpp
src/graphics/stkanimatedmesh.hpp
src/graphics/stkbillboard.hpp
src/graphics/stkinstancedscenenode.hpp
src/graphics/stkmesh.hpp
src/graphics/stkmeshscenenode.hpp
src/graphics/sun.hpp
@@ -646,7 +646,7 @@ src/tracks/check_manager.hpp
src/tracks/check_sphere.hpp
src/tracks/check_structure.hpp
src/tracks/graph_node.hpp
src/tracks/lod_node_loader.hpp
src/tracks/model_definition_loader.hpp
src/tracks/quad.hpp
src/tracks/quad_graph.hpp
src/tracks/quad_set.hpp

View File

@@ -35,7 +35,7 @@ class XMLNode;
* storage for state information by a generic key-value mapping. The values
* are stored as strings, but can be used to store numerical values. E.g.
* you can call increase("key", 10) for an achievement, which will convert
* the string to int, add 10, then convert the result back to string for
* the string to int, add 10, then convert the result back to string for
* storage.
* \ingroup achievements
*/
@@ -69,7 +69,7 @@ public:
virtual void reset();
virtual irr::core::stringw getProgressAsString() const;
void onRaceEnd();
void onRaceEnd();
void onLapEnd();
// ------------------------------------------------------------------------
/** Returns the id of this achievement. */
@@ -89,4 +89,4 @@ public:
return m_progress_map;
} // getProgress
}; // class Achievement
#endif
#endif

View File

@@ -41,7 +41,7 @@ AchievementInfo::AchievementInfo(const XMLNode * input)
input->get("description", &m_description );
if (!all)
{
Log::error("AchievementInfo",
Log::error("AchievementInfo",
"Not all necessary values for achievement defined.");
Log::error("AchievementInfo",
"ID %d title '%s' description '%s'", m_id, m_title.c_str(),
@@ -80,7 +80,7 @@ AchievementInfo::AchievementInfo(const XMLNode * input)
m_goal_values[key] = goal;
}
if (m_goal_values.size() != input->getNumNodes())
Log::fatal("AchievementInfo",
Log::fatal("AchievementInfo",
"Duplicate keys for the entries of a MapAchievement found.");
if (m_check_type == AC_ONE_AT_LEAST)
@@ -156,7 +156,7 @@ bool AchievementInfo::checkCompletion(Achievement * achievement) const
}
// ----------------------------------------------------------------------------
int AchievementInfo::getGoalValue(const std::string &key) const
{
{
std::map<std::string, int>::const_iterator it;
it = m_goal_values.find(key);
if (it != m_goal_values.end())

View File

@@ -74,14 +74,14 @@ AchievementsManager::~AchievementsManager()
* information for a single player.
* \param node The XML of saved data, or NULL if no saved data exists.
*/
AchievementsStatus*
AchievementsStatus*
AchievementsManager::createAchievementsStatus(const XMLNode *node)
{
AchievementsStatus *status = new AchievementsStatus();
// First add all achievements, before restoring the saved data.
std::map<uint32_t, AchievementInfo *>::const_iterator it;
for (it = m_achievements_info.begin();
for (it = m_achievements_info.begin();
it != m_achievements_info.end(); ++it)
{
Achievement * achievement;
@@ -98,7 +98,7 @@ AchievementsStatus*
// ----------------------------------------------------------------------------
AchievementInfo * AchievementsManager::getAchievementInfo(uint32_t id) const
{
std::map<uint32_t, AchievementInfo*>::const_iterator info =
std::map<uint32_t, AchievementInfo*>::const_iterator info =
m_achievements_info.find(id);
if (info != m_achievements_info.end())
return info->second;

View File

@@ -76,7 +76,7 @@ public:
// ------------------------------------------------------------------------
const std::map<uint32_t, AchievementInfo *> & getAllInfo()
{
return m_achievements_info;
return m_achievements_info;
} // getAllInfo
}; // class AchievementsManager

View File

@@ -140,4 +140,4 @@ void AchievementsStatus::onLapEnd()
for (iter = m_achievements.begin(); iter != m_achievements.end(); ++iter) {
iter->second->onLapEnd();
}
} // onLapEnd
} // onLapEnd

View File

@@ -62,7 +62,7 @@ public :
void onRaceEnd();
void onLapEnd();
// ------------------------------------------------------------------------
const std::map<uint32_t, Achievement *>& getAllAchievements()
const std::map<uint32_t, Achievement *>& getAllAchievements()
{
return m_achievements;
}

View File

@@ -179,7 +179,7 @@ bool Addon::testIncluded(const std::string &min_ver, const std::string &max_ver)
}
// ----------------------------------------------------------------------------
/**
/**
* \brief Filter the add-on with a list of words.
* \param words A list of words separated by ' '.
* \return true if the add-on contains one of the words, otherwise false.

View File

@@ -106,7 +106,7 @@ void AddonsManager::init(const XMLNode *xml,
include->get("mtime", &tmp);
mtime = tmp;
bool download =
bool download =
( mtime > UserConfigParams::m_addons_last_updated +frequency ||
force_refresh ||
!file_manager->fileExists(filename) )
@@ -116,7 +116,7 @@ void AddonsManager::init(const XMLNode *xml,
{
Log::info("NetworkHttp", "Downloading updated addons.xml");
Online::HTTPRequest *download_request = new Online::HTTPRequest("addons.xml");
download_request->setURL(addon_list_url);
download_request->setURL(addon_list_url);
download_request->executeNow();
if(download_request->hadDownloadError())
{
@@ -375,7 +375,7 @@ void AddonsManager::downloadIcons()
m_addon->setIconReady();
} // callback
public:
IconRequest(const std::string &filename,
IconRequest(const std::string &filename,
const std::string &url,
Addon *addon ) : HTTPRequest(filename, true, 1)
{
@@ -558,8 +558,8 @@ bool AddonsManager::uninstall(const Addon &addon)
// some files were successfully removed. Since we can not
// know if the addon is still functional, better remove it.
// On the other hand, in case of a problem the user will have
// the option in the GUI to try again. In this case
// removeTrack/Kart would not find the addon and assert. So
// the option in the GUI to try again. In this case
// removeTrack/Kart would not find the addon and assert. So
// check first if the track is still known.
if(addon.getType()=="kart")
{

View File

@@ -52,7 +52,7 @@ NewsManager::~NewsManager()
* separate thread to execute downloadNews() - which (if necessary) the
* news.xml file and updating the list of news messages. It also initialises
* the addons manager (which can trigger another download of news.xml).
* \param force_refresh Re-download news.xml, even if
* \param force_refresh Re-download news.xml, even if
*/
void NewsManager::init(bool force_refresh)
{
@@ -102,7 +102,7 @@ void* NewsManager::downloadNews(void *obj)
bool download = ( UserConfigParams::m_news_last_updated==0 ||
UserConfigParams::m_news_last_updated
+UserConfigParams::m_news_frequency
< StkTime::getTimeSinceEpoch() ||
< StkTime::getTimeSinceEpoch() ||
me->m_force_refresh ||
!news_exists )
&& UserConfigParams::m_internet_status==RequestManager::IPERM_ALLOWED;

View File

@@ -262,7 +262,7 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
// Only use the filename if no full path is specified. This is used
// to load terrain specific sfx.
const std::string full_path = (path == "")
const std::string full_path = (path == "")
? file_manager->getAsset(FileManager::SFX,filename)
: path;

View File

@@ -45,7 +45,7 @@ class XMLNode;
* challenge is not possible yet (inactive), active (i.e. user can try to
* solve it), or solved. This status is stored for each difficulty level.
* This data is saved to and loaded from the players.xml file.
* A StoryModeStatus instance will store an array of ChallengeStatuses,
* A StoryModeStatus instance will store an array of ChallengeStatuses,
* one for each Challenge in STK.
*
* \ingroup challenges

View File

@@ -111,9 +111,9 @@ public:
/** Returns if this is the first time the intro is shown. */
bool isFirstTime() const { return m_first_time; }
// ------------------------------------------------------------------------
const ChallengeStatus *getCurrentChallengeStatus() const
const ChallengeStatus *getCurrentChallengeStatus() const
{
return m_current_challenge;
return m_current_challenge;
} // getCurrentChallengeStatus
// ------------------------------------------------------------------------
/** Returns a challenge given the challenge id.

View File

@@ -29,7 +29,7 @@
PlayerManager *PlayerManager::m_player_manager = NULL;
/** Create the instance of the player manager.
/** Create the instance of the player manager.
* Also make sure that at least one player is defined (and if not,
* create a default player and a guest player).
*/
@@ -137,7 +137,7 @@ void PlayerManager::addNewPlayer(const core::stringw& name)
} // addNewPlayer
// ----------------------------------------------------------------------------
/** Deletes a player profile from the list of all profiles.
/** Deletes a player profile from the list of all profiles.
*/
void PlayerManager::deletePlayer(PlayerProfile *player)
{
@@ -146,7 +146,7 @@ void PlayerManager::deletePlayer(PlayerProfile *player)
// ----------------------------------------------------------------------------
/** This function makes sure that a current player is defined. This is called
* when a screen skipping command line option is given (-N, -R, ...), in
* when a screen skipping command line option is given (-N, -R, ...), in
* which case there might not be a current player (if no default player is
* set in players.xml, i.e. the 'remember be' option was not picked ). Since
* a lot of code depends on having a local player, just set the most

View File

@@ -45,7 +45,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
m_unique_id = PlayerManager::get()->getUniqueId();
m_story_mode_status = unlock_manager->createStoryModeStatus();
m_is_default = false;
m_achievements_status =
m_achievements_status =
AchievementsManager::get()->createAchievementsStatus();
} // PlayerProfile
@@ -77,8 +77,8 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
*/
void PlayerProfile::save(UTFWriter &out)
{
out << L" <player name=\"" << m_name
<< L"\" guest=\"" << m_is_guest_account
out << L" <player name=\"" << m_name
<< L"\" guest=\"" << m_is_guest_account
<< L"\" use-frequency=\"" << m_use_frequency
<< L"\" is-default=\"" << m_is_default
<< L"\" unique-id=\"" << m_unique_id << L"\">\n";
@@ -111,7 +111,7 @@ void PlayerProfile::raceFinished()
} // raceFinished
//------------------------------------------------------------------------------
/** Comparison used to sort players.
/** Comparison used to sort players.
*/
bool PlayerProfile::operator<(const PlayerProfile &other)
{

View File

@@ -31,7 +31,7 @@ using namespace irr;
class UTFWriter;
class AchievementsStatus;
/** Class for managing player profiles (name, usage frequency,
/** Class for managing player profiles (name, usage frequency,
* etc.). All PlayerProfiles are managed by the PlayerManager.
* A PlayerProfile keeps track of the story mode progress using an instance
* of StoryModeStatus, and achievements with AchievementsStatus. All data
@@ -42,7 +42,7 @@ class PlayerProfile : public NoCopy
{
private:
/** The name of the player (wide string, so it can be in native
/** The name of the player (wide string, so it can be in native
* language). */
core::stringw m_name;
@@ -130,14 +130,14 @@ public:
/** Returnes if the feature (kart, track) is locked. */
bool isLocked(const std::string &feature) const
{
return m_story_mode_status->isLocked(feature);
return m_story_mode_status->isLocked(feature);
} // isLocked
// ------------------------------------------------------------------------
/** Returns all active challenges. */
void computeActive() { m_story_mode_status->computeActive(); }
// ------------------------------------------------------------------------
/** Returns the list of recently completed challenges. */
std::vector<const ChallengeData*> getRecentlyCompletedChallenges()
std::vector<const ChallengeData*> getRecentlyCompletedChallenges()
{
return m_story_mode_status->getRecentlyCompletedChallenges();
} // getRecently Completed Challenges
@@ -173,7 +173,7 @@ public:
// ------------------------------------------------------------------------
unsigned int getNumEasyTrophies() const
{
return m_story_mode_status->getNumEasyTrophies();
return m_story_mode_status->getNumEasyTrophies();
} // getNumEasyTrophies
// ------------------------------------------------------------------------
unsigned int getNumMediumTrophies() const
@@ -183,10 +183,10 @@ public:
// -----------------------------------------------------------------------
unsigned int getNumHardTrophies() const
{
return m_story_mode_status->getNumHardTrophies();
return m_story_mode_status->getNumHardTrophies();
} // getNumHardTropies
// ------------------------------------------------------------------------
AchievementsStatus* getAchievementsStatus()
AchievementsStatus* getAchievementsStatus()
{
return m_achievements_status;
} // getAchievementsStatus

View File

@@ -67,7 +67,7 @@ public:
float m_parachute_ubound_fraction; /**<Upper bound fraction of speed when
lost will detach parachute. */
float m_parachute_lbound_fraction; /**<Lower bound fraction of speed when
lost will detach parachute. */
lost will detach parachute. */
float m_parachute_max_speed; /**<Max speed to rate current speed */
float m_parachute_time; /**<Time a parachute is active. */
float m_parachute_time_other; /**<Time a parachute attached to other

View File

@@ -692,7 +692,7 @@ bool UserConfig::loadConfig()
"Could not read user config file '%s'.", filename.c_str());
if(root) delete root;
// Create a default config file - just in case that stk crashes later
// there is a config file that can be modified (to e.g. disable
// there is a config file that can be modified (to e.g. disable
// shaders)
saveConfig();
return false;
@@ -703,7 +703,7 @@ bool UserConfig::loadConfig()
if(root->get("version", &config_file_version) < 1)
{
GUIEngine::showMessage( _("Your config file was malformed, so it was deleted and a new one will be created."), 10.0f);
Log::error("UserConfig",
Log::error("UserConfig",
"Warning, malformed user config file! Contains no version");
}
if (config_file_version < m_current_config_version)

View File

@@ -560,7 +560,7 @@ namespace UserConfigParams
// This saves the actual user preference.
PARAM_PREFIX IntUserConfigParam m_xmas_mode
PARAM_DEFAULT( IntUserConfigParam(0, "christmas-mode",
&m_graphics_quality, "Christmas hats: 0 use calendar, 1 always on, 2 always off") );
&m_graphics_quality, "Christmas hats: 0 use current date, 1 always on, 2 always off") );
PARAM_PREFIX BoolUserConfigParam m_weather_effects
PARAM_DEFAULT( BoolUserConfigParam(true, "weather_gfx",

View File

@@ -14,232 +14,232 @@ CBatchingMesh::CBatchingMesh()
CBatchingMesh::~CBatchingMesh()
{
u32 i;
for (i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->drop();
u32 i;
for (i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->drop();
for (i=0; i < SourceBuffers.size(); ++i)
SourceBuffers[i]->drop();
for (i=0; i < SourceBuffers.size(); ++i)
SourceBuffers[i]->drop();
}
bool CBatchingMesh::isDirty(s32 id)
{
if ((u32)id > DestBuffers.size())
return IsDirty;
else
return DestBuffers[id].IsDirty;
if ((u32)id > DestBuffers.size())
return IsDirty;
else
return DestBuffers[id].IsDirty;
}
//! refreshes the internal buffers from source
void CBatchingMesh::update()
{
// allocate the index and vertex arrays
u32 i;
for (i=0; i<DestBuffers.size(); ++i)
{
if (DestBuffers[i].IndexCount != DestBuffers[i].Buffer->getIndexCount() ||
DestBuffers[i].VertexCount != DestBuffers[i].Buffer->getVertexCount())
{
DestBuffers[i].IsDirty = true;
// allocate the index and vertex arrays
u32 i;
for (i=0; i<DestBuffers.size(); ++i)
{
if (DestBuffers[i].IndexCount != DestBuffers[i].Buffer->getIndexCount() ||
DestBuffers[i].VertexCount != DestBuffers[i].Buffer->getVertexCount())
{
DestBuffers[i].IsDirty = true;
switch (DestBuffers[i].VertexType)
{
case video::EVT_STANDARD:
{
SMeshBuffer* mb = (SMeshBuffer*)DestBuffers[i].Buffer;
mb->Vertices.set_used(DestBuffers[i].VertexCount);
mb->Indices.set_used(DestBuffers[i].IndexCount);
break;
}
case video::EVT_2TCOORDS:
{
SMeshBufferLightMap* mb = (SMeshBufferLightMap*)DestBuffers[i].Buffer;
mb->Vertices.set_used(DestBuffers[i].VertexCount);
mb->Indices.set_used(DestBuffers[i].IndexCount);
break;
}
case video::EVT_TANGENTS:
{
SMeshBufferTangents* mb = (SMeshBufferTangents*)DestBuffers[i].Buffer;
mb->Vertices.set_used(DestBuffers[i].VertexCount);
mb->Indices.set_used(DestBuffers[i].IndexCount);
break;
}
default: // shouldn't ever happen
continue;
}
}
}
switch (DestBuffers[i].VertexType)
{
case video::EVT_STANDARD:
{
SMeshBuffer* mb = (SMeshBuffer*)DestBuffers[i].Buffer;
mb->Vertices.set_used(DestBuffers[i].VertexCount);
mb->Indices.set_used(DestBuffers[i].IndexCount);
break;
}
case video::EVT_2TCOORDS:
{
SMeshBufferLightMap* mb = (SMeshBufferLightMap*)DestBuffers[i].Buffer;
mb->Vertices.set_used(DestBuffers[i].VertexCount);
mb->Indices.set_used(DestBuffers[i].IndexCount);
break;
}
case video::EVT_TANGENTS:
{
SMeshBufferTangents* mb = (SMeshBufferTangents*)DestBuffers[i].Buffer;
mb->Vertices.set_used(DestBuffers[i].VertexCount);
mb->Indices.set_used(DestBuffers[i].IndexCount);
break;
}
default: // shouldn't ever happen
continue;
}
}
}
// refresh dirty buffers from source
for (i=0; i<BufferReferences.size(); ++i)
{
if (DestBuffers[BufferReferences[i].DestReference].IsDirty)
{
updateDestFromSourceBuffer(i);
}
}
// refresh dirty buffers from source
for (i=0; i<BufferReferences.size(); ++i)
{
if (DestBuffers[BufferReferences[i].DestReference].IsDirty)
{
updateDestFromSourceBuffer(i);
}
}
// calculate bounding boxes
for (i=0; i< DestBuffers.size(); ++i)
{
if (DestBuffers[i].IsDirty)
{
recalculateDestBufferBoundingBox(i);
// reset dirty state too
DestBuffers[i].IsDirty = false;
}
}
// calculate bounding boxes
for (i=0; i< DestBuffers.size(); ++i)
{
if (DestBuffers[i].IsDirty)
{
recalculateDestBufferBoundingBox(i);
// reset dirty state too
DestBuffers[i].IsDirty = false;
}
}
IsDirty = false;
recalculateBoundingBox();
IsDirty = false;
recalculateBoundingBox();
}
//! adds a mesh to the buffers with the given offset
/** \Returns Returns an array of ID numbers */
core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, core::vector3df pos, core::vector3df rot, core::vector3df scale)
{
core::matrix4 m;
m.setRotationDegrees(rot);
m.setTranslation(pos);
core::matrix4 m;
m.setRotationDegrees(rot);
m.setTranslation(pos);
core::matrix4 scalem;
scalem.setScale(scale);
m *= scalem;
core::matrix4 scalem;
scalem.setScale(scale);
m *= scalem;
return addMesh(mesh, m);
return addMesh(mesh, m);
}
//! adds a mesh with the given transformation
core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, const core::matrix4 &transform)
{
core::array<s32> bufferNos;
core::array<s32> bufferNos;
if (!mesh)
return bufferNos;
if (!mesh)
return bufferNos;
u32 i;
for (i=0; i<mesh->getMeshBufferCount(); ++i)
bufferNos.push_back(addMeshBuffer(mesh->getMeshBuffer(i), transform));
u32 i;
for (i=0; i<mesh->getMeshBufferCount(); ++i)
bufferNos.push_back(addMeshBuffer(mesh->getMeshBuffer(i), transform));
return bufferNos;
return bufferNos;
}
//! adds a mesh buffer with the given transformation
/** \Return Returns the ID of this mesh buffer */
s32 CBatchingMesh::addMeshBuffer(IMeshBuffer* buffer, core::vector3df pos, core::vector3df rot, core::vector3df scale)
{
core::matrix4 m;
m.setRotationDegrees(rot);
m.setTranslation(pos);
core::matrix4 m;
m.setRotationDegrees(rot);
m.setTranslation(pos);
core::matrix4 scalem;
scalem.setScale(scale);
m *= scalem;
core::matrix4 scalem;
scalem.setScale(scale);
m *= scalem;
return addMeshBuffer(buffer, m);
return addMeshBuffer(buffer, m);
}
//! adds a mesh with the given transformation
/** \Return Returns the ID of this mesh buffer */
s32 CBatchingMesh::addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform)
{
if (!buffer || IsFinal)
return -1;
if (!buffer || IsFinal)
return -1;
u32 i;
video::SMaterial m = buffer->getMaterial();
u32 i;
video::SMaterial m = buffer->getMaterial();
// find material
bool found=false;
video::E_VERTEX_TYPE vt = buffer->getVertexType();
for (i=0; i<MaterialReferences.size(); ++i)
{
if (MaterialReferences[i].VertexType == vt &&
MaterialReferences[i].Material == m)
{
// will there be too many vertices in the buffer?
u32 newTotalI = buffer->getIndexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount;
u32 newTotalV = buffer->getVertexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount;
// find material
bool found=false;
video::E_VERTEX_TYPE vt = buffer->getVertexType();
for (i=0; i<MaterialReferences.size(); ++i)
{
if (MaterialReferences[i].VertexType == vt &&
MaterialReferences[i].Material == m)
{
// will there be too many vertices in the buffer?
u32 newTotalI = buffer->getIndexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount;
u32 newTotalV = buffer->getVertexCount() + DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount;
if ( newTotalI < 65536*3 && newTotalV < 65536)
{
found = true;
DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount = newTotalI;
DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount = newTotalV;
break;
}
}
}
if ( newTotalI < 65536*3 && newTotalV < 65536)
{
found = true;
DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount = newTotalI;
DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount = newTotalV;
break;
}
}
}
if (!found)
{
// we need a new destination buffer and material reference
IMeshBuffer *mb=0;
if (!found)
{
// we need a new destination buffer and material reference
IMeshBuffer *mb=0;
SMaterialReference r;
r.Material = m;
r.VertexType = vt;
r.BufferIndex = DestBuffers.size();
switch (vt)
{
case video::EVT_STANDARD:
mb = (IMeshBuffer*)new SMeshBuffer();
mb->getMaterial() = m;
break;
case video::EVT_2TCOORDS:
mb = (IMeshBuffer*)new SMeshBufferLightMap();
mb->getMaterial() = m;
break;
case video::EVT_TANGENTS:
mb = (IMeshBuffer*)new SMeshBufferTangents();
mb->getMaterial() = m;
break;
default: // unknown vertex type
return -1;
}
i = MaterialReferences.size();
MaterialReferences.push_back(r);
SMaterialReference r;
r.Material = m;
r.VertexType = vt;
r.BufferIndex = DestBuffers.size();
switch (vt)
{
case video::EVT_STANDARD:
mb = (IMeshBuffer*)new SMeshBuffer();
mb->getMaterial() = m;
break;
case video::EVT_2TCOORDS:
mb = (IMeshBuffer*)new SMeshBufferLightMap();
mb->getMaterial() = m;
break;
case video::EVT_TANGENTS:
mb = (IMeshBuffer*)new SMeshBufferTangents();
mb->getMaterial() = m;
break;
default: // unknown vertex type
return -1;
}
i = MaterialReferences.size();
MaterialReferences.push_back(r);
SDestBufferReference db;
db.Buffer = mb;
db.IndexCount = buffer->getIndexCount();
db.VertexCount = buffer->getVertexCount();
db.IsDirty = true;
db.VertexType = vt;
SDestBufferReference db;
db.Buffer = mb;
db.IndexCount = buffer->getIndexCount();
db.VertexCount = buffer->getVertexCount();
db.IsDirty = true;
db.VertexType = vt;
DestBuffers.push_back(db);
}
// now we add the mesh reference
SBufferReference r;
r.DestReference = i;
r.SourceBuffer = buffer;
r.Transform = transform;
r.IndexCount = buffer->getIndexCount();
r.VertexCount = buffer->getVertexCount();
r.FirstIndex = DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount - r.IndexCount;
r.FirstVertex = DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount - r.VertexCount;
r.Initialized = false;
BufferReferences.push_back(r);
addSourceBuffer(buffer);
DestBuffers.push_back(db);
}
// now we add the mesh reference
SBufferReference r;
r.DestReference = i;
r.SourceBuffer = buffer;
r.Transform = transform;
r.IndexCount = buffer->getIndexCount();
r.VertexCount = buffer->getVertexCount();
r.FirstIndex = DestBuffers[ MaterialReferences[i].BufferIndex ].IndexCount - r.IndexCount;
r.FirstVertex = DestBuffers[ MaterialReferences[i].BufferIndex ].VertexCount - r.VertexCount;
r.Initialized = false;
BufferReferences.push_back(r);
addSourceBuffer(buffer);
IsDirty = true;
return BufferReferences.size()-1;
IsDirty = true;
return BufferReferences.size()-1;
}
//! updates bouding box from internal buffers
void CBatchingMesh::recalculateBoundingBox()
{
if (DestBuffers.size() == 0)
Box.reset(0,0,0);
else
{
Box.reset(DestBuffers[0].Buffer->getBoundingBox().MinEdge);
if (DestBuffers.size() == 0)
Box.reset(0,0,0);
else
{
Box.reset(DestBuffers[0].Buffer->getBoundingBox().MinEdge);
u32 i;
for (i=0; i < DestBuffers.size(); ++i)
Box.addInternalBox(DestBuffers[i].Buffer->getBoundingBox());
}
u32 i;
for (i=0; i < DestBuffers.size(); ++i)
Box.addInternalBox(DestBuffers[i].Buffer->getBoundingBox());
}
}
@@ -249,7 +249,7 @@ void CBatchingMesh::recalculateBoundingBox()
/** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */
u32 CBatchingMesh::getMeshBufferCount() const
{
return DestBuffers.size();
return DestBuffers.size();
}
//! Returns pointer to a mesh buffer.
@@ -259,29 +259,29 @@ getMeshBufferCount() - 1;
NULL if there is no such mesh buffer. */
IMeshBuffer* CBatchingMesh::getMeshBuffer(u32 nr) const
{
if (nr < DestBuffers.size())
return DestBuffers[nr].Buffer;
else
return 0;
if (nr < DestBuffers.size())
return DestBuffers[nr].Buffer;
else
return 0;
}
//! Returns pointer to a mesh buffer which fits a material
IMeshBuffer* CBatchingMesh::getMeshBuffer( const video::SMaterial &material) const
{
return 0;
return 0;
}
//! Returns an axis aligned bounding box of the mesh.
/** \return A bounding box of this mesh is returned. */
const core::aabbox3d<f32>& CBatchingMesh::getBoundingBox() const
{
return Box;
return Box;
}
//! set user axis aligned bounding box
void CBatchingMesh::setBoundingBox( const core::aabbox3df& box)
{
Box = box;
Box = box;
}
//! Sets a flag of all contained materials to a new value.
@@ -289,218 +289,218 @@ void CBatchingMesh::setBoundingBox( const core::aabbox3df& box)
\param newvalue: New value to set in all materials. */
void CBatchingMesh::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{
for (u32 i=0; i<DestBuffers.size(); ++i)
DestBuffers[i].Buffer->getMaterial().setFlag(flag, newvalue);
for (u32 i=0; i<DestBuffers.size(); ++i)
DestBuffers[i].Buffer->getMaterial().setFlag(flag, newvalue);
}
//! drops all buffers and clears internal states
void CBatchingMesh::clear()
{
u32 i;
for (i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->drop();
u32 i;
for (i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->drop();
for (i=0; i < SourceBuffers.size(); ++i)
SourceBuffers[i]->drop();
for (i=0; i < SourceBuffers.size(); ++i)
SourceBuffers[i]->drop();
BufferReferences.clear();
MaterialReferences.clear();
DestBuffers.clear();
SourceBuffers.clear();
BufferReferences.clear();
MaterialReferences.clear();
DestBuffers.clear();
SourceBuffers.clear();
IsDirty = false;
IsFinal = false;
IsDirty = false;
IsFinal = false;
}
//! first updates the mesh, then drops all source buffers.
/** once this mesh has been finalized, it cannot be changed again! */
void CBatchingMesh::finalize()
{
update();
update();
for (u32 i=0; i < SourceBuffers.size(); ++i)
SourceBuffers[i]->drop();
for (u32 i=0; i < SourceBuffers.size(); ++i)
SourceBuffers[i]->drop();
SourceBuffers.clear();
SourceBuffers.clear();
IsFinal = true;
IsFinal = true;
}
//! Moves a mesh
core::array<bool> CBatchingMesh::moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix)
{
core::array<bool> result;
result.reallocate(bufferIDs.size());
for (u32 i=0; i<bufferIDs.size(); ++i)
result.push_back(moveMeshBuffer(bufferIDs[i], newMatrix));
core::array<bool> result;
result.reallocate(bufferIDs.size());
for (u32 i=0; i<bufferIDs.size(); ++i)
result.push_back(moveMeshBuffer(bufferIDs[i], newMatrix));
return result;
return result;
}
//! Moves a mesh buffer
bool CBatchingMesh::moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix)
{
if ((u32)id > BufferReferences.size() || IsFinal )
return false;
if ((u32)id > BufferReferences.size() || IsFinal )
return false;
BufferReferences[id].Transform = newMatrix;
BufferReferences[id].Transform = newMatrix;
// is the source buffer dirty?
if (!DestBuffers[BufferReferences[id].DestReference].IsDirty)
{
// transform each vertex and normal
updateDestFromSourceBuffer(id);
recalculateDestBufferBoundingBox(BufferReferences[id].DestReference);
}
return true;
// is the source buffer dirty?
if (!DestBuffers[BufferReferences[id].DestReference].IsDirty)
{
// transform each vertex and normal
updateDestFromSourceBuffer(id);
recalculateDestBufferBoundingBox(BufferReferences[id].DestReference);
}
return true;
}
//! returns the source buffer, if available
IMeshBuffer* CBatchingMesh::getSourceBuffer(s32 id)
{
if ((u32)id > BufferReferences.size() || IsFinal)
return 0;
else
return BufferReferences[id].SourceBuffer;
if ((u32)id > BufferReferences.size() || IsFinal)
return 0;
else
return BufferReferences[id].SourceBuffer;
}
//! returns the matrix of the source buffer
core::matrix4 CBatchingMesh::getSourceBufferMatrix(s32 id)
{
core::matrix4 ret;
if ((u32)id > BufferReferences.size() || IsFinal)
ret.makeIdentity();
else
ret = BufferReferences[id].Transform;
core::matrix4 ret;
if ((u32)id > BufferReferences.size() || IsFinal)
ret.makeIdentity();
else
ret = BufferReferences[id].Transform;
return ret;
return ret;
}
//! returns the number of source buffers
u32 CBatchingMesh::getSourceBufferCount() const
{
return BufferReferences.size();
return BufferReferences.size();
}
// private functions
void CBatchingMesh::recalculateDestBufferBoundingBox(u32 i)
{
switch (DestBuffers[i].VertexType)
{
case video::EVT_STANDARD:
((SMeshBuffer*)DestBuffers[i].Buffer)->recalculateBoundingBox();
break;
case video::EVT_2TCOORDS:
((SMeshBufferLightMap*)DestBuffers[i].Buffer)->recalculateBoundingBox();
break;
case video::EVT_TANGENTS:
((SMeshBufferTangents*)DestBuffers[i].Buffer)->recalculateBoundingBox();
break;
}
switch (DestBuffers[i].VertexType)
{
case video::EVT_STANDARD:
((SMeshBuffer*)DestBuffers[i].Buffer)->recalculateBoundingBox();
break;
case video::EVT_2TCOORDS:
((SMeshBufferLightMap*)DestBuffers[i].Buffer)->recalculateBoundingBox();
break;
case video::EVT_TANGENTS:
((SMeshBufferTangents*)DestBuffers[i].Buffer)->recalculateBoundingBox();
break;
}
}
void CBatchingMesh::updateDestFromSourceBuffer(u32 i)
{
u16* ind = BufferReferences[i].SourceBuffer->getIndices();
void*ver = BufferReferences[i].SourceBuffer->getVertices();
core::matrix4 m = BufferReferences[i].Transform;
u32 fi = BufferReferences[i].FirstIndex;
u32 fv = BufferReferences[i].FirstVertex;
u32 ic = BufferReferences[i].IndexCount;
u32 vc = BufferReferences[i].VertexCount;
u32 x;
video::E_VERTEX_TYPE vt = DestBuffers[BufferReferences[i].DestReference].VertexType;
switch (vt)
{
case video::EVT_STANDARD:
{
SMeshBuffer* dest = (SMeshBuffer*) DestBuffers[BufferReferences[i].DestReference].Buffer;
u16* ind = BufferReferences[i].SourceBuffer->getIndices();
void*ver = BufferReferences[i].SourceBuffer->getVertices();
core::matrix4 m = BufferReferences[i].Transform;
u32 fi = BufferReferences[i].FirstIndex;
u32 fv = BufferReferences[i].FirstVertex;
u32 ic = BufferReferences[i].IndexCount;
u32 vc = BufferReferences[i].VertexCount;
u32 x;
video::E_VERTEX_TYPE vt = DestBuffers[BufferReferences[i].DestReference].VertexType;
switch (vt)
{
case video::EVT_STANDARD:
{
SMeshBuffer* dest = (SMeshBuffer*) DestBuffers[BufferReferences[i].DestReference].Buffer;
for (x=fi; x < fi+ic; ++x)
dest->Indices[x] = ind[x-fi]+fv;
for (x=fi; x < fi+ic; ++x)
dest->Indices[x] = ind[x-fi]+fv;
video::S3DVertex* vertices= (video::S3DVertex*) ver;
video::S3DVertex* vertices= (video::S3DVertex*) ver;
for (x=fv; x < fv+vc; ++x)
{
dest->Vertices[x] = vertices[x-fv];
m.transformVect(dest->Vertices[x].Pos);
m.rotateVect(dest->Vertices[x].Normal);
}
break;
}
case video::EVT_2TCOORDS:
{
SMeshBufferLightMap* dest = (SMeshBufferLightMap*) DestBuffers[BufferReferences[i].DestReference].Buffer;
for (x=fv; x < fv+vc; ++x)
{
dest->Vertices[x] = vertices[x-fv];
m.transformVect(dest->Vertices[x].Pos);
m.rotateVect(dest->Vertices[x].Normal);
}
break;
}
case video::EVT_2TCOORDS:
{
SMeshBufferLightMap* dest = (SMeshBufferLightMap*) DestBuffers[BufferReferences[i].DestReference].Buffer;
for (x=fi; x < fi+ic; ++x)
dest->Indices[x] = ind[x-fi]+fv;
for (x=fi; x < fi+ic; ++x)
dest->Indices[x] = ind[x-fi]+fv;
video::S3DVertex2TCoords* vertices= (video::S3DVertex2TCoords*) ver;
video::S3DVertex2TCoords* vertices= (video::S3DVertex2TCoords*) ver;
for (x=fv; x < fv+vc; ++x)
{
dest->Vertices[x] = vertices[x-fv];
m.transformVect(dest->Vertices[x].Pos);
m.rotateVect(dest->Vertices[x].Normal);
}
break;
}
case video::EVT_TANGENTS:
{
SMeshBufferTangents* dest = (SMeshBufferTangents*) DestBuffers[BufferReferences[i].DestReference].Buffer;
for (x=fv; x < fv+vc; ++x)
{
dest->Vertices[x] = vertices[x-fv];
m.transformVect(dest->Vertices[x].Pos);
m.rotateVect(dest->Vertices[x].Normal);
}
break;
}
case video::EVT_TANGENTS:
{
SMeshBufferTangents* dest = (SMeshBufferTangents*) DestBuffers[BufferReferences[i].DestReference].Buffer;
for (x=fi; x < fi+ic; ++x)
dest->Indices[x] = ind[x-fi]+fv;
for (x=fi; x < fi+ic; ++x)
dest->Indices[x] = ind[x-fi]+fv;
video::S3DVertexTangents* vertices= (video::S3DVertexTangents*) ver;
video::S3DVertexTangents* vertices= (video::S3DVertexTangents*) ver;
for (x=fv; x < fv+vc; ++x)
{
dest->Vertices[x] = vertices[x-fv];
m.transformVect(dest->Vertices[x].Pos);
m.rotateVect(dest->Vertices[x].Normal); // are tangents/binormals in face space?
}
break;
}
default:
break;
}
for (x=fv; x < fv+vc; ++x)
{
dest->Vertices[x] = vertices[x-fv];
m.transformVect(dest->Vertices[x].Pos);
m.rotateVect(dest->Vertices[x].Normal); // are tangents/binormals in face space?
}
break;
}
default:
break;
}
}
void CBatchingMesh::addSourceBuffer(IMeshBuffer *source)
{
bool found = false;
for (u32 i=0; i<SourceBuffers.size(); ++i)
{
if (SourceBuffers[i] == source)
{
found = true;
break;
}
}
if (!found)
{
source->grab();
SourceBuffers.push_back(source);
}
bool found = false;
for (u32 i=0; i<SourceBuffers.size(); ++i)
{
if (SourceBuffers[i] == source)
{
found = true;
break;
}
}
if (!found)
{
source->grab();
SourceBuffers.push_back(source);
}
}
void CBatchingMesh::setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type)
{
for (u32 i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->setHardwareMappingHint(mapping, type);
for (u32 i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->setHardwareMappingHint(mapping, type);
}
void CBatchingMesh::setDirty(E_BUFFER_TYPE type)
{
for (u32 i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->setDirty(type);
for (u32 i=0; i < DestBuffers.size(); ++i)
DestBuffers[i].Buffer->setDirty(type);
}
} // namespace scene

View File

@@ -15,157 +15,157 @@ namespace scene
class CBatchingMesh : public IMesh
{
public:
CBatchingMesh();
CBatchingMesh();
virtual ~CBatchingMesh();
virtual ~CBatchingMesh();
//! returns true if new buffers have been added without updating the internal buffers
bool isDirty(s32 id=-1);
//! returns true if new buffers have been added without updating the internal buffers
bool isDirty(s32 id=-1);
//! refreshes the internal buffers from source
void update();
//! refreshes the internal buffers from source
void update();
//! drops all buffers and clears internal states
void clear();
//! drops all buffers and clears internal states
void clear();
//! first updates the mesh, then drops all source buffers.
/** once this mesh has been finalized, it cannot be changed again! */
void finalize();
//! first updates the mesh, then drops all source buffers.
/** once this mesh has been finalized, it cannot be changed again! */
void finalize();
//! adds a mesh to the buffers with the given offset
/** \Return: Returns an array of ID numbers */
core::array<s32> addMesh(IMesh* mesh,
core::vector3df pos = core::vector3df(0,0,0),
core::vector3df rot = core::vector3df(0,0,0),
core::vector3df scale = core::vector3df(1,1,1));
//! adds a mesh to the buffers with the given offset
/** \Return: Returns an array of ID numbers */
core::array<s32> addMesh(IMesh* mesh,
core::vector3df pos = core::vector3df(0,0,0),
core::vector3df rot = core::vector3df(0,0,0),
core::vector3df scale = core::vector3df(1,1,1));
//! adds a mesh with the given transformation
/** \Return: Returns an array of ID numbers */
core::array<s32> addMesh(IMesh* mesh, const core::matrix4 &transform);
//! adds a mesh with the given transformation
/** \Return: Returns an array of ID numbers */
core::array<s32> addMesh(IMesh* mesh, const core::matrix4 &transform);
//! adds a mesh buffer with the given transformation
/** \Return: Returns the ID of this mesh buffer */
s32 addMeshBuffer(IMeshBuffer* buffer,
core::vector3df pos = core::vector3df(0,0,0),
core::vector3df rot = core::vector3df(0,0,0),
core::vector3df scale = core::vector3df(1,1,1));
//! adds a mesh buffer with the given transformation
/** \Return: Returns the ID of this mesh buffer */
s32 addMeshBuffer(IMeshBuffer* buffer,
core::vector3df pos = core::vector3df(0,0,0),
core::vector3df rot = core::vector3df(0,0,0),
core::vector3df scale = core::vector3df(1,1,1));
//! adds a mesh with the given transformation
/** \Return Returns the ID of this mesh buffer */
s32 addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform);
//! adds a mesh with the given transformation
/** \Return Returns the ID of this mesh buffer */
s32 addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform);
//! updates bouding box from internal buffers
void recalculateBoundingBox();
//! updates bouding box from internal buffers
void recalculateBoundingBox();
//! Moves a mesh,
/** mesh buffers in clean destination buffers will be moved immediately,
ones in dirty buffers will be left until the next update */
core::array<bool> moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix);
//! Moves a mesh,
/** mesh buffers in clean destination buffers will be moved immediately,
ones in dirty buffers will be left until the next update */
core::array<bool> moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix);
//! Moves a mesh buffer
/** if the destination buffer is clean it will be moved immediately,
if a member of a dirty buffer, it will be left until the next update */
bool moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix);
//! Moves a mesh buffer
/** if the destination buffer is clean it will be moved immediately,
if a member of a dirty buffer, it will be left until the next update */
bool moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix);
//! returns the source buffer, if available
IMeshBuffer* getSourceBuffer(s32 id);
//! returns the source buffer, if available
IMeshBuffer* getSourceBuffer(s32 id);
//! returns the matrix of the source buffer
core::matrix4 getSourceBufferMatrix(s32 id);
//! returns the matrix of the source buffer
core::matrix4 getSourceBufferMatrix(s32 id);
//! returns the number of source buffers
u32 getSourceBufferCount() const;
//! returns the number of source buffers
u32 getSourceBufferCount() const;
/* Standard IMesh functions */
/* Standard IMesh functions */
//! Returns the amount of mesh buffers.
/** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */
virtual u32 getMeshBufferCount() const;
//! Returns the amount of mesh buffers.
/** \return Returns the amount of mesh buffers (IMeshBuffer) in this mesh. */
virtual u32 getMeshBufferCount() const;
//! Returns pointer to a mesh buffer.
/** \param nr: Zero based index of the mesh buffer. The maximum value is
getMeshBufferCount() - 1;
\return Returns the pointer to the mesh buffer or
NULL if there is no such mesh buffer. */
virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
//! Returns pointer to a mesh buffer.
/** \param nr: Zero based index of the mesh buffer. The maximum value is
getMeshBufferCount() - 1;
\return Returns the pointer to the mesh buffer or
NULL if there is no such mesh buffer. */
virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
//! Returns pointer to a mesh buffer which fits a material
/** \param material: material to search for
\return Returns the pointer to the mesh buffer or
NULL if there is no such mesh buffer. */
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const;
//! Returns pointer to a mesh buffer which fits a material
/** \param material: material to search for
\return Returns the pointer to the mesh buffer or
NULL if there is no such mesh buffer. */
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const;
//! Returns an axis aligned bounding box of the mesh.
/** \return A bounding box of this mesh is returned. */
virtual const core::aabbox3d<f32>& getBoundingBox() const;
//! Returns an axis aligned bounding box of the mesh.
/** \return A bounding box of this mesh is returned. */
virtual const core::aabbox3d<f32>& getBoundingBox() const;
//! set user axis aligned bounding box
virtual void setBoundingBox( const core::aabbox3df& box);
//! set user axis aligned bounding box
virtual void setBoundingBox( const core::aabbox3df& box);
//! Sets a flag of all contained materials to a new value.
/** \param flag: Flag to set in all materials.
\param newvalue: New value to set in all materials. */
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue);
//! Sets a flag of all contained materials to a new value.
/** \param flag: Flag to set in all materials.
\param newvalue: New value to set in all materials. */
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue);
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type);
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type);
virtual void setDirty(E_BUFFER_TYPE type);
virtual void setDirty(E_BUFFER_TYPE type);
private:
// add a buffer to the source buffers array if it doesn't already exist
void addSourceBuffer(IMeshBuffer* source);
// add a buffer to the source buffers array if it doesn't already exist
void addSourceBuffer(IMeshBuffer* source);
// updates the vertices in dest buffer from the source one
void updateDestFromSourceBuffer(u32 id);
// updates the vertices in dest buffer from the source one
void updateDestFromSourceBuffer(u32 id);
// recalculates the bounding box for the given dest buffer
void recalculateDestBufferBoundingBox(u32 i);
// recalculates the bounding box for the given dest buffer
void recalculateDestBufferBoundingBox(u32 i);
struct SBufferReference
{
SBufferReference()
: SourceBuffer(0), DestReference(0), FirstVertex(0), VertexCount(0),
FirstIndex(0), IndexCount(0), Initialized(false) { }
struct SBufferReference
{
SBufferReference()
: SourceBuffer(0), DestReference(0), FirstVertex(0), VertexCount(0),
FirstIndex(0), IndexCount(0), Initialized(false) { }
IMeshBuffer* SourceBuffer;
u32 DestReference;
u32 FirstVertex, VertexCount, FirstIndex, IndexCount;
core::matrix4 Transform;
bool Initialized;
};
IMeshBuffer* SourceBuffer;
u32 DestReference;
u32 FirstVertex, VertexCount, FirstIndex, IndexCount;
core::matrix4 Transform;
bool Initialized;
};
struct SMaterialReference
{
video::SMaterial Material;
video::E_VERTEX_TYPE VertexType;
u32 BufferIndex;
};
struct SMaterialReference
{
video::SMaterial Material;
video::E_VERTEX_TYPE VertexType;
u32 BufferIndex;
};
struct SDestBufferReference
{
IMeshBuffer* Buffer;
video::E_VERTEX_TYPE VertexType;
u32 VertexCount;
u32 IndexCount;
bool IsDirty;
};
struct SDestBufferReference
{
IMeshBuffer* Buffer;
video::E_VERTEX_TYPE VertexType;
u32 VertexCount;
u32 IndexCount;
bool IsDirty;
};
//! Source mesh buffers, these are locked
core::array<IMeshBuffer*> SourceBuffers;
//! Source mesh buffers, these are locked
core::array<IMeshBuffer*> SourceBuffers;
core::array<SBufferReference> BufferReferences;
core::array<SMaterialReference> MaterialReferences;
core::array<SDestBufferReference> DestBuffers;
core::array<SBufferReference> BufferReferences;
core::array<SMaterialReference> MaterialReferences;
core::array<SDestBufferReference> DestBuffers;
//! bounding containing all destination buffers
core::aabbox3d<f32> Box;
//! bounding containing all destination buffers
core::aabbox3d<f32> Box;
//! does it require an update?
bool IsDirty;
//! does it require an update?
bool IsDirty;
//! can it be changed?
bool IsFinal;
//! can it be changed?
bool IsFinal;
};
} // namespace scene

View File

@@ -558,21 +558,21 @@ void DisplaceProvider::OnSetConstants(IMaterialRendererServices *srv, int)
void DisplaceProvider::update()
{
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
const float speed = World::getWorld()->getTrack()->getDisplacementSpeed();
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
const float speed = World::getWorld()->getTrack()->getDisplacementSpeed();
float strength = time;
strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.002f;
float strength = time;
strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.002f;
vector3df wind = irr_driver->getWind() * strength * speed;
m_dir[0] += wind.X;
m_dir[1] += wind.Z;
vector3df wind = irr_driver->getWind() * strength * speed;
m_dir[0] += wind.X;
m_dir[1] += wind.Z;
strength = time * 0.56f + sinf(time);
strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.0025f;
strength = time * 0.56f + sinf(time);
strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.0025f;
wind = irr_driver->getWind() * strength * speed;
wind.rotateXZBy(cosf(time));
m_dir2[0] += wind.X;
m_dir2[1] += wind.Z;
}
wind = irr_driver->getWind() * strength * speed;
wind.rotateXZBy(cosf(time));
m_dir2[0] += wind.X;
m_dir2[1] += wind.Z;
}

View File

@@ -121,15 +121,15 @@ public:
m_amplitude = amp;
}
float getSpeed() const
{
return m_speed;
}
float getSpeed() const
{
return m_speed;
}
float getAmplitude() const
{
return m_amplitude;
}
float getAmplitude() const
{
return m_amplitude;
}
private:
float m_amplitude, m_speed;
@@ -327,20 +327,20 @@ public:
m_color[2] = b;
}
float getRed() const
{
return m_color[0];
}
float getRed() const
{
return m_color[0];
}
float getGreen() const
{
return m_color[1];
}
float getGreen() const
{
return m_color[1];
}
float getBlue() const
{
return m_color[2];
}
float getBlue() const
{
return m_color[2];
}
private:
float m_color[3];
@@ -555,27 +555,27 @@ public:
m_dir[0] = m_dir[1] = m_dir2[0] = m_dir2[1] = 0;
}
void update();
void update();
float getDirX() const
{
return m_dir[0];
}
float getDirX() const
{
return m_dir[0];
}
float getDirY() const
{
return m_dir[1];
}
float getDirY() const
{
return m_dir[1];
}
float getDir2X() const
{
return m_dir2[0];
}
float getDir2X() const
{
return m_dir2[0];
}
float getDir2Y() const
{
return m_dir2[1];
}
float getDir2Y() const
{
return m_dir2[1];
}
private:
float m_screen[2];

View File

@@ -1,60 +0,0 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Lauri Kasanen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/glow.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/material.hpp"
#include "graphics/rtts.hpp"
#include "graphics/shaders.hpp"
using namespace video;
using namespace scene;
using namespace core;
IMesh * GlowNode::sphere = NULL;
SMaterial GlowNode::mat;
aabbox3df GlowNode::box;
GlowNode::GlowNode(scene::ISceneManager* mgr, float radius): ISceneNode(mgr->getRootSceneNode(), mgr, -1)
{
if (!sphere)
{
sphere = mgr->getGeometryCreator()->createSphereMesh(1, 4, 4);
box = sphere->getBoundingBox();
}
setScale(vector3df(radius));
}
GlowNode::~GlowNode()
{
}
void GlowNode::render()
{
}
void GlowNode::OnRegisterSceneNode()
{
}

View File

@@ -1,53 +0,0 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Lauri Kasanen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_GLOW_HPP
#define HEADER_GLOW_HPP
#include <ISceneNode.h>
#include <IMesh.h>
using namespace irr;
// The actual node
class GlowNode: public scene::ISceneNode
{
public:
GlowNode(scene::ISceneManager* mgr, float radius);
~GlowNode();
virtual void render();
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return box;
}
virtual void OnRegisterSceneNode();
virtual u32 getMaterialCount() const { return 1; }
virtual video::SMaterial& getMaterial(u32 i) { return mat; }
private:
static video::SMaterial mat;
static core::aabbox3df box;
static scene::IMesh *sphere;
};
#endif

View File

@@ -46,6 +46,7 @@ PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation;
PFNGLBLENDEQUATIONPROC glBlendEquation;
PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced;
PFNGLDELETEBUFFERSPROC glDeleteBuffers;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
@@ -58,6 +59,7 @@ PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture;
PFNGLTEXIMAGE3DPROC glTexImage3D;
PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
#endif
@@ -183,6 +185,7 @@ void initGL()
glBlendEquation = (PFNGLBLENDEQUATIONPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquation");
glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)IRR_OGL_LOAD_EXTENSION("glVertexAttribDivisor");
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC)IRR_OGL_LOAD_EXTENSION("glDrawArraysInstanced");
glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC)IRR_OGL_LOAD_EXTENSION("glDrawElementsInstanced");
glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glDeleteBuffers");
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)IRR_OGL_LOAD_EXTENSION("glGenVertexArrays");
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)IRR_OGL_LOAD_EXTENSION("glBindVertexArray");
@@ -196,13 +199,15 @@ void initGL()
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glBindFramebuffer");
glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture");
glTexImage3D = (PFNGLTEXIMAGE3DPROC)IRR_OGL_LOAD_EXTENSION("glTexImage3D");
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)IRR_OGL_LOAD_EXTENSION("glGenerateMipmap");
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatus");
#ifdef DEBUG
glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC)IRR_OGL_LOAD_EXTENSION("glDebugMessageCallbackARB");
#endif
#endif
#ifdef ARB_DEBUG_OUTPUT
glDebugMessageCallbackARB((GLDEBUGPROCARB)debugCallback, NULL);
if (glDebugMessageCallbackARB)
glDebugMessageCallbackARB((GLDEBUGPROCARB)debugCallback, NULL);
#endif
}
@@ -288,6 +293,26 @@ GLuint getDepthTexture(irr::video::ITexture *tex)
return static_cast<irr::video::COpenGLFBOTexture*>(tex)->DepthBufferTexture;
}
std::set<irr::video::ITexture *> AlreadyTransformedTexture;
void transformTexturesTosRGB(irr::video::ITexture *tex)
{
if (AlreadyTransformedTexture.find(tex) != AlreadyTransformedTexture.end())
return;
AlreadyTransformedTexture.insert(tex);
size_t w = tex->getSize().Width, h = tex->getSize().Height;
char *data = new char[w * h * 4];
memcpy(data, tex->lock(), w * h * 4);
tex->unlock();
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex));
if (tex->hasAlpha())
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)data);
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, (GLvoid *)data);
glGenerateMipmap(GL_TEXTURE_2D);
delete[] data;
}
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF)
{
glActiveTexture(GL_TEXTURE0 + TextureUnit);
@@ -360,14 +385,112 @@ void drawTexQuad(const video::ITexture *texture, float width, float height,
}
}
static void
getSize(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect,
float &width, float &height,
float &center_pos_x, float &center_pos_y,
float &tex_width, float &tex_height,
float &tex_center_pos_x, float &tex_center_pos_y
)
{
core::dimension2d<u32> frame_size =
irr_driver->getVideoDriver()->getCurrentRenderTargetSize();
const int screen_w = frame_size.Width;
const int screen_h = frame_size.Height;
center_pos_x = destRect.UpperLeftCorner.X + destRect.LowerRightCorner.X;
center_pos_x /= screen_w;
center_pos_x -= 1.;
center_pos_y = destRect.UpperLeftCorner.Y + destRect.LowerRightCorner.Y;
center_pos_y /= screen_h;
center_pos_y = 1. - center_pos_y;
width = destRect.LowerRightCorner.X - destRect.UpperLeftCorner.X;
width /= screen_w;
height = destRect.LowerRightCorner.Y - destRect.UpperLeftCorner.Y;
height /= screen_h;
const core::dimension2d<u32>& ss = texture->getOriginalSize();
tex_center_pos_x = sourceRect.UpperLeftCorner.X + sourceRect.LowerRightCorner.X;
tex_center_pos_x /= ss.Width * 2.;
tex_center_pos_y = sourceRect.UpperLeftCorner.Y + sourceRect.LowerRightCorner.Y;
tex_center_pos_y /= ss.Height * 2.;
tex_width = sourceRect.LowerRightCorner.X - sourceRect.UpperLeftCorner.X;
tex_width /= ss.Width * 2.;
tex_height = sourceRect.LowerRightCorner.Y - sourceRect.UpperLeftCorner.Y;
tex_height /= ss.Height * 2.;
if (texture->isRenderTarget())
{
tex_height = -tex_height;
}
const f32 invW = 1.f / static_cast<f32>(ss.Width);
const f32 invH = 1.f / static_cast<f32>(ss.Height);
const core::rect<f32> tcoords(
sourceRect.UpperLeftCorner.X * invW,
sourceRect.UpperLeftCorner.Y * invH,
sourceRect.LowerRightCorner.X * invW,
sourceRect.LowerRightCorner.Y *invH);
}
void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
const video::SColor &colors, bool useAlphaChannelOfTexture)
{
video::SColor duplicatedArray[4] = {
colors, colors, colors, colors
};
draw2DImage(texture, destRect, sourceRect, clipRect, duplicatedArray, useAlphaChannelOfTexture);
if (!irr_driver->isGLSL()) {
video::SColor duplicatedArray[4] = {
colors, colors, colors, colors
};
draw2DImage(texture, destRect, sourceRect, clipRect, duplicatedArray, useAlphaChannelOfTexture);
return;
}
float width, height,
center_pos_x, center_pos_y,
tex_width, tex_height,
tex_center_pos_x, tex_center_pos_y;
getSize(texture, destRect, sourceRect, width, height, center_pos_x, center_pos_y,
tex_width, tex_height, tex_center_pos_x, tex_center_pos_y);
if (useAlphaChannelOfTexture)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
{
glDisable(GL_BLEND);
}
if (clipRect)
{
if (!clipRect->isValid())
return;
glEnable(GL_SCISSOR_TEST);
const core::dimension2d<u32>& renderTargetSize = irr_driver->getVideoDriver()->getCurrentRenderTargetSize();
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y,
clipRect->getWidth(), clipRect->getHeight());
}
glUseProgram(UIShader::UniformColoredTextureRectShader::Program);
glBindVertexArray(UIShader::UniformColoredTextureRectShader::vao);
setTexture(0, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName(), GL_LINEAR, GL_LINEAR);
UIShader::UniformColoredTextureRectShader::setUniforms(center_pos_x, center_pos_y, width, height, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height,colors, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (clipRect)
glDisable(GL_SCISSOR_TEST);
glUseProgram(0);
GLenum glErr = glGetError();
if (glErr != GL_NO_ERROR)
{
Log::warn("IrrDriver", "GLWrap : OpenGL error %i\n", glErr);
}
}
void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
@@ -380,46 +503,13 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect
return;
}
core::dimension2d<u32> frame_size =
irr_driver->getVideoDriver()->getCurrentRenderTargetSize();
const int screen_w = frame_size.Width;
const int screen_h = frame_size.Height;
float center_pos_x = destRect.UpperLeftCorner.X + destRect.LowerRightCorner.X;
center_pos_x /= screen_w;
center_pos_x -= 1.;
float center_pos_y = destRect.UpperLeftCorner.Y + destRect.LowerRightCorner.Y;
center_pos_y /= screen_h;
center_pos_y = 1. - center_pos_y;
float width = destRect.LowerRightCorner.X - destRect.UpperLeftCorner.X;
width /= screen_w;
float height = destRect.LowerRightCorner.Y - destRect.UpperLeftCorner.Y;
height /= screen_h;
float width, height,
center_pos_x, center_pos_y,
tex_width, tex_height,
tex_center_pos_x, tex_center_pos_y;
const core::dimension2d<u32>& ss = texture->getOriginalSize();
float tex_center_pos_x = sourceRect.UpperLeftCorner.X + sourceRect.LowerRightCorner.X;
tex_center_pos_x /= ss.Width * 2.;
//tex_center_pos_x -= 1.;
float tex_center_pos_y = sourceRect.UpperLeftCorner.Y + sourceRect.LowerRightCorner.Y;
tex_center_pos_y /= ss.Height * 2.;
//tex_center_pos_y -= 1.;
float tex_width = sourceRect.LowerRightCorner.X - sourceRect.UpperLeftCorner.X;
tex_width /= ss.Width * 2.;
float tex_height = sourceRect.LowerRightCorner.Y - sourceRect.UpperLeftCorner.Y;
tex_height /= ss.Height * 2.;
if (texture->isRenderTarget())
{
tex_height = - tex_height;
}
const f32 invW = 1.f / static_cast<f32>(ss.Width);
const f32 invH = 1.f / static_cast<f32>(ss.Height);
const core::rect<f32> tcoords(
sourceRect.UpperLeftCorner.X * invW,
sourceRect.UpperLeftCorner.Y * invH,
sourceRect.LowerRightCorner.X * invW,
sourceRect.LowerRightCorner.Y *invH);
getSize(texture, destRect, sourceRect, width, height, center_pos_x, center_pos_y,
tex_width, tex_height, tex_center_pos_x, tex_center_pos_y);
if (useAlphaChannelOfTexture)
{

View File

@@ -64,6 +64,7 @@ extern PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation;
extern PFNGLBLENDEQUATIONPROC glBlendEquation;
extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced;
extern PFNGLDELETEBUFFERSPROC glDeleteBuffers;
extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
@@ -75,6 +76,7 @@ extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture;
extern PFNGLTEXIMAGE3DPROC glTexImage3D;
extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
#ifdef DEBUG
extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB;
@@ -102,6 +104,19 @@ void loadAndAttach(GLint ProgramID, GLint ShaderType, const char *filepath, Type
loadAndAttach(ProgramID, args...);
}
template<typename ...Types>
void printFileList()
{
return;
}
template<typename ...Types>
void printFileList(GLint ShaderType, const char *filepath, Types ... args)
{
Log::error("GLWrapp", filepath);
printFileList(args...);
}
template<typename ... Types>
GLint LoadProgram(Types ... args)
{
@@ -113,10 +128,12 @@ GLint LoadProgram(Types ... args)
int InfoLogLength;
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
if (Result == GL_FALSE) {
Log::error("GLWrapp", "Error when linking these shaders :");
printFileList(args...);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
char *ErrorMessage = new char[InfoLogLength];
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, ErrorMessage);
printf(ErrorMessage);
Log::error("GLWrapp", ErrorMessage);
delete[] ErrorMessage;
}
@@ -135,6 +152,7 @@ GLint LoadProgram(Types ... args)
GLuint getTextureGLuint(irr::video::ITexture *tex);
GLuint getDepthTexture(irr::video::ITexture *tex);
void transformTexturesTosRGB(irr::video::ITexture *tex);
void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect<s32>& destRect,
const irr::core::rect<s32>& sourceRect, const irr::core::rect<s32>* clipRect,

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +1,70 @@
#ifndef GPUPARTICLES_H
#define GPUPARTICLES_H
#ifndef GPUPARTICLES_H
#define GPUPARTICLES_H
#include "graphics/glwrap.hpp"
#include "graphics/glwrap.hpp"
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
#include <ISceneManager.h>
#include <IParticleSystemSceneNode.h>
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
#include <ISceneManager.h>
#include <IParticleSystemSceneNode.h>
namespace irr { namespace video{ class ITexture; } }
namespace irr { namespace video{ class ITexture; } }
class ParticleSystemProxy : public scene::CParticleSystemSceneNode
{
protected:
GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer;
GLuint current_simulation_vao, non_current_simulation_vao;
GLuint current_rendering_vao, non_current_rendering_vao;
bool m_alpha_additive, has_height_map, flip;
float size_increase_factor, track_x, track_z, track_x_len, track_z_len;
float m_color_from[3];
float m_color_to[3];
class ParticleSystemProxy : public scene::CParticleSystemSceneNode
{
protected:
GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer;
GLuint current_simulation_vao, non_current_simulation_vao;
GLuint current_rendering_vao, non_current_rendering_vao;
bool m_alpha_additive, has_height_map, flip;
float size_increase_factor, track_x, track_z, track_x_len, track_z_len;
float m_color_from[3];
float m_color_to[3];
static GLuint quad_vertex_buffer;
static GLuint quad_vertex_buffer;
GLuint texture;
unsigned count;
static void SimpleParticleVAOBind(GLuint PositionBuffer);
static void FlipParticleVAOBind(GLuint PositionBuffer, GLuint QuaternionBuffer);
static void SimpleSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
static void HeightmapSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
GLuint texture;
unsigned count;
static void SimpleParticleVAOBind(GLuint PositionBuffer);
static void FlipParticleVAOBind(GLuint PositionBuffer, GLuint QuaternionBuffer);
static void SimpleSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
static void HeightmapSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
void generateVAOs();
void generateVAOs();
void simulateHeightmap();
void simulateNoHeightmap();
void drawFlip();
void drawNotFlip();
virtual void simulate();
virtual void draw();
void generateParticlesFromPointEmitter(scene::IParticlePointEmitter *);
void generateParticlesFromBoxEmitter(scene::IParticleBoxEmitter *);
void generateParticlesFromSphereEmitter(scene::IParticleSphereEmitter *);
public:
static IParticleSystemSceneNode *addParticleNode(
bool withDefaultEmitter = true, ISceneNode* parent = 0, s32 id = -1,
const core::vector3df& position = core::vector3df(0, 0, 0),
const core::vector3df& rotation = core::vector3df(0, 0, 0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
void simulateHeightmap();
void simulateNoHeightmap();
void drawFlip();
void drawNotFlip();
virtual void simulate();
virtual void draw();
void generateParticlesFromPointEmitter(scene::IParticlePointEmitter *);
void generateParticlesFromBoxEmitter(scene::IParticleBoxEmitter *);
void generateParticlesFromSphereEmitter(scene::IParticleSphereEmitter *);
public:
static IParticleSystemSceneNode *addParticleNode(
bool withDefaultEmitter = true, ISceneNode* parent = 0, s32 id = -1,
const core::vector3df& position = core::vector3df(0, 0, 0),
const core::vector3df& rotation = core::vector3df(0, 0, 0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
ParticleSystemProxy(bool createDefaultEmitter,
ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale);
~ParticleSystemProxy();
ParticleSystemProxy(bool createDefaultEmitter,
ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale);
~ParticleSystemProxy();
virtual void setEmitter(scene::IParticleEmitter* emitter);
virtual void render();
virtual void OnRegisterSceneNode();
void setAlphaAdditive(bool val) { m_alpha_additive = val; }
void setIncreaseFactor(float val) { size_increase_factor = val; }
void setColorFrom(float r, float g, float b) { m_color_from[0] = r; m_color_from[1] = g; m_color_from[2] = b; }
void setColorTo(float r, float g, float b) { m_color_to[0] = r; m_color_to[1] = g; m_color_to[2] = b; }
const float* getColorFrom() const { return m_color_from; }
const float* getColorTo() const { return m_color_to; }
void setHeightmap(const std::vector<std::vector<float> >&, float, float, float, float);
void setFlip();
};
virtual void setEmitter(scene::IParticleEmitter* emitter);
virtual void render();
virtual void OnRegisterSceneNode();
void setAlphaAdditive(bool val) { m_alpha_additive = val; }
void setIncreaseFactor(float val) { size_increase_factor = val; }
void setColorFrom(float r, float g, float b) { m_color_from[0] = r; m_color_from[1] = g; m_color_from[2] = b; }
void setColorTo(float r, float g, float b) { m_color_to[0] = r; m_color_to[1] = g; m_color_to[2] = b; }
const float* getColorFrom() const { return m_color_from; }
const float* getColorTo() const { return m_color_to; }
void setHeightmap(const std::vector<std::vector<float> >&, float, float, float, float);
void setFlip();
};
#endif // GPUPARTICLES_H
#endif // GPUPARTICLES_H

View File

@@ -155,7 +155,7 @@ STKRenderingPass IrrDriver::getPhase() const
void IrrDriver::IncreaseObjectCount()
{
object_count[m_phase]++;
object_count[m_phase]++;
}
core::array<video::IRenderTarget> &IrrDriver::getMainSetup()
@@ -424,10 +424,10 @@ void IrrDriver::initDevice()
GLMajorVersion = 2;
GLMinorVersion = 1;
glGetIntegerv(GL_MAJOR_VERSION, &GLMajorVersion);
glGetIntegerv(GL_MAJOR_VERSION, &GLMajorVersion);
glGetIntegerv(GL_MINOR_VERSION, &GLMinorVersion);
Log::info("IrrDriver", "OPENGL VERSION IS %d.%d", GLMajorVersion, GLMinorVersion);
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1)) && UserConfigParams::m_pixel_shaders;
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1)) && UserConfigParams::m_pixel_shaders;
// This remaps the window, so it has to be done before the clear to avoid flicker
m_device->setResizable(false);
@@ -458,7 +458,7 @@ void IrrDriver::initDevice()
m_mrt.push_back(m_rtts->getRTT(RTT_COLOR));
m_mrt.push_back(m_rtts->getRTT(RTT_NORMAL_AND_DEPTH));
irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver();
irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver();
gl_driver->extGlGenQueries(1, &m_lensflare_query);
m_query_issued = false;
@@ -595,7 +595,7 @@ core::position2di IrrDriver::getMouseLocation()
bool IrrDriver::moveWindow(const int x, const int y)
{
#ifdef WIN32
const video::SExposedVideoData& videoData =
const video::SExposedVideoData& videoData =
m_video_driver->getExposedVideoData();
// this should work even if using DirectX in theory,
// because the HWnd is always third pointer in the struct,
@@ -964,17 +964,17 @@ scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size,
video::ITexture *texture,
scene::ISceneNode* parent, bool alphaTesting)
{
scene::IBillboardSceneNode* node;
if (isGLSL())
{
if (!parent)
parent = m_scene_manager->getRootSceneNode();
scene::IBillboardSceneNode* node;
if (isGLSL())
{
if (!parent)
parent = m_scene_manager->getRootSceneNode();
node = new STKBillboard(parent, m_scene_manager, -1, vector3df(0., 0., 0.), size);
node->drop();
}
else
node = m_scene_manager->addBillboardSceneNode(parent, size);
node = new STKBillboard(parent, m_scene_manager, -1, vector3df(0., 0., 0.), size);
node->drop();
}
else
node = m_scene_manager->addBillboardSceneNode(parent, size);
assert(node->getMaterialCount() > 0);
node->setMaterialTexture(0, texture);
if(alphaTesting)
@@ -1150,7 +1150,7 @@ scene::ISceneNode *IrrDriver::addSkyDome(video::ITexture *texture,
float texture_percent,
float sphere_percent)
{
Log::error("skybox", "Using deprecated SkyDome");
Log::error("skybox", "Using deprecated SkyDome");
return m_scene_manager->addSkyDomeSceneNode(texture, hori_res, vert_res,
texture_percent,
sphere_percent);
@@ -1171,9 +1171,8 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*>
&texture)
{
assert(texture.size() == 6);
SkyboxTextures = texture;
SkyboxTextures = texture;
SkyboxCubeMap = 0;
ConvolutedSkyboxCubeMap = 0;
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
texture[2], texture[3],
texture[4], texture[5]);
@@ -1181,11 +1180,10 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*>
void IrrDriver::suppressSkyBox()
{
SkyboxTextures.clear();
glDeleteTextures(1, &SkyboxCubeMap);
glDeleteTextures(1, &ConvolutedSkyboxCubeMap);
SkyboxTextures.clear();
if (SkyboxCubeMap)
glDeleteTextures(1, &SkyboxCubeMap);
SkyboxCubeMap = 0;
ConvolutedSkyboxCubeMap = 0;
}
// ----------------------------------------------------------------------------
@@ -1518,9 +1516,9 @@ void IrrDriver::displayFPS()
{
sprintf(buffer, "FPS: %i/%i/%i - Objects (P1:%d P2:%d T:%d) KTris - LightDst : ~%d",
min, fps, max, object_count[SOLID_NORMAL_AND_DEPTH_PASS], object_count[SOLID_NORMAL_AND_DEPTH_PASS], object_count[TRANSPARENT_PASS], m_last_light_bucket_distance);
object_count[SOLID_NORMAL_AND_DEPTH_PASS] = 0;
object_count[SOLID_NORMAL_AND_DEPTH_PASS] = 0;
object_count[TRANSPARENT_PASS] = 0;
object_count[SOLID_NORMAL_AND_DEPTH_PASS] = 0;
object_count[SOLID_NORMAL_AND_DEPTH_PASS] = 0;
object_count[TRANSPARENT_PASS] = 0;
}
else
{
@@ -2017,7 +2015,7 @@ void IrrDriver::RTTProvider::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
m_rtt_main_node->getMaterial(n).SpecularColor.set(255,50,50,50);
m_rtt_main_node->getMaterial(n).DiffuseColor.set(255,150,150,150);
m_rtt_main_node->getMaterial(n).setFlag(video::EMF_GOURAUD_SHADING ,
m_rtt_main_node->getMaterial(n).setFlag(video::EMF_GOURAUD_SHADING ,
true);
}
@@ -2216,7 +2214,7 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos, float energy,
}
else
{
return m_scene_manager->addLightSceneNode(m_scene_manager->getRootSceneNode(),
return m_scene_manager->addLightSceneNode(m_scene_manager->getRootSceneNode(),
pos, video::SColorf(1.0f, r, g, b));
}
}

View File

@@ -65,13 +65,13 @@ class ShadowImportance;
enum STKRenderingPass
{
SOLID_NORMAL_AND_DEPTH_PASS,
SOLID_LIT_PASS,
TRANSPARENT_PASS,
GLOW_PASS,
DISPLACEMENT_PASS,
SHADOW_PASS,
PASS_COUNT,
SOLID_NORMAL_AND_DEPTH_PASS,
SOLID_LIT_PASS,
TRANSPARENT_PASS,
GLOW_PASS,
DISPLACEMENT_PASS,
SHADOW_PASS,
PASS_COUNT,
};
/**
@@ -115,7 +115,7 @@ private:
/** Matrixes used in several places stored here to avoid recomputation. */
core::matrix4 m_ViewMatrix, m_InvViewMatrix, m_ProjMatrix, m_InvProjMatrix, m_ProjViewMatrix, m_InvProjViewMatrix;
std::vector<video::ITexture *> SkyboxTextures;
std::vector<video::ITexture *> SkyboxTextures;
float blueSHCoeff[9];
float greenSHCoeff[9];
@@ -131,7 +131,7 @@ private:
RES_CHANGE_CANCEL} m_resolution_changing;
public:
GLuint SkyboxCubeMap, ConvolutedSkyboxCubeMap;
GLuint SkyboxCubeMap;
/** A simple class to store video resolutions. */
class VideoMode
{
@@ -183,9 +183,9 @@ private:
bool m_shadowviz;
bool m_lightviz;
bool m_distortviz;
/** Performance stats */
/** Performance stats */
unsigned m_last_light_bucket_distance;
unsigned object_count[PASS_COUNT];
unsigned object_count[PASS_COUNT];
u32 m_renderpass;
u32 m_lensflare_query;
bool m_query_issued;
@@ -208,7 +208,7 @@ private:
std::vector<scene::ISceneNode *> m_background;
STKRenderingPass m_phase;
STKRenderingPass m_phase;
#ifdef DEBUG
/** Used to visualise skeletons. */
@@ -244,13 +244,13 @@ public:
void reset();
void generateSkyboxCubemap();
void renderSkybox();
void setPhase(STKRenderingPass);
STKRenderingPass getPhase() const;
void setPhase(STKRenderingPass);
STKRenderingPass getPhase() const;
const std::vector<core::matrix4> &getShadowViewProj() const
{
return sun_ortho_matrix;
}
void IncreaseObjectCount();
void IncreaseObjectCount();
core::array<video::IRenderTarget> &getMainSetup();
void updateConfigIfRelevant();
void setAllMaterialFlags(scene::IMesh *mesh) const;
@@ -261,7 +261,7 @@ public:
void displayFPS();
bool OnEvent(const irr::SEvent &event);
void setAmbientLight(const video::SColor &light);
video::ITexture *getTexture(FileManager::AssetType type,
video::ITexture *getTexture(FileManager::AssetType type,
const std::string &filename,
bool is_premul=false,
bool is_prediv=false,
@@ -297,7 +297,7 @@ public:
int vert_res, float texture_percent,
float sphere_percent);
scene::ISceneNode *addSkyBox(const std::vector<video::ITexture*> &texture_names);
void suppressSkyBox();
void suppressSkyBox();
void removeNode(scene::ISceneNode *node);
void removeMeshFromCache(scene::IMesh *mesh);
void removeTexture(video::ITexture *t);
@@ -369,7 +369,7 @@ public:
char *detail=NULL)
{
if(!detail)
return getTexture(filename, std::string(error_message),
return getTexture(filename, std::string(error_message),
std::string(""));
return getTexture(filename, std::string(error_message),
@@ -384,7 +384,7 @@ public:
*/
const std::string &getTextureErrorMessage()
{
return m_texture_error_message;
return m_texture_error_message;
} // getTextureErrorMessage
// ------------------------------------------------------------------------
@@ -420,7 +420,7 @@ public:
// -----------------------------------------------------------------------
inline void updateShaders() {m_shaders->loadShaders();}
// ------------------------------------------------------------------------
inline video::IShaderConstantSetCallBack* getCallback(const ShaderType num)
inline video::IShaderConstantSetCallBack* getCallback(const ShaderType num)
{
return (m_shaders == NULL ? NULL : m_shaders->m_callbacks[num]);
}

View File

@@ -13,43 +13,43 @@ namespace irr
{
namespace scene
{
//! A SMeshBuffer with 32-bit indices
class LargeMeshBuffer : public SMeshBuffer
{
public:
//! Get type of index data which is stored in this meshbuffer.
/** \return Index type of this buffer. */
virtual video::E_INDEX_TYPE getIndexType() const
{
return video::EIT_32BIT;
}
//! A SMeshBuffer with 32-bit indices
class LargeMeshBuffer : public SMeshBuffer
{
public:
//! Get type of index data which is stored in this meshbuffer.
/** \return Index type of this buffer. */
virtual video::E_INDEX_TYPE getIndexType() const
{
return video::EIT_32BIT;
}
//! Get pointer to indices
/** \return Pointer to indices. */
virtual const u16* getIndices() const
{
return (u16 *) Indices.const_pointer();
}
//! Get pointer to indices
/** \return Pointer to indices. */
virtual const u16* getIndices() const
{
return (u16 *) Indices.const_pointer();
}
//! Get pointer to indices
/** \return Pointer to indices. */
virtual u16* getIndices()
{
return (u16 *) Indices.pointer();
}
//! Get pointer to indices
/** \return Pointer to indices. */
virtual u16* getIndices()
{
return (u16 *) Indices.pointer();
}
//! Get number of indices
/** \return Number of indices. */
virtual u32 getIndexCount() const
{
return Indices.size();
}
//! Get number of indices
/** \return Number of indices. */
virtual u32 getIndexCount() const
{
return Indices.size();
}
//! Indices into the vertices of this buffer.
core::array<u32> Indices;
};
//! Indices into the vertices of this buffer.
core::array<u32> Indices;
};
} // end namespace scene
} // end namespace irr

View File

@@ -86,7 +86,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
else if (s=="" || s=="none")
m_adjust_image = ADJ_NONE;
else
Log::warn("material",
Log::warn("material",
"Incorrect adjust-image specification: '%s' - ignored.",
s.c_str());
node->get("alpha", &m_alpha_blending );
@@ -121,7 +121,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else if (creaction.size() > 0)
{
Log::warn("Material","Unknown collision reaction '%s'",
Log::warn("Material","Unknown collision reaction '%s'",
creaction.c_str());
}
@@ -239,7 +239,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else if (s != "")
{
Log::warn("material",
Log::warn("material",
"Invalid graphical effect specification: '%s' - ignored.",
s.c_str());
}
@@ -261,7 +261,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else
{
Log::warn("material",
Log::warn("material",
"Could not find normal map image in materials.xml");
}
@@ -650,22 +650,22 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
// materials.xml, if you want to set flags for all surfaces, see
// 'MaterialManager::setAllMaterialFlags'
if (m_deprecated ||
(m->getTexture(0) != NULL &&
if (m_deprecated ||
(m->getTexture(0) != NULL &&
((core::stringc)m->getTexture(0)->getName()).find("deprecated") != -1))
{
Log::warn("material", "Track uses deprecated texture '%s'",
Log::warn("material", "Track uses deprecated texture '%s'",
m_texname.c_str());
}
int modes = 0;
if (!m_lighting && irr_driver->isGLSL() && !m_alpha_blending && !m_add)
{
m->MaterialType = irr_driver->getShader(ES_OBJECT_UNLIT);
modes++;
}
if (!m_lighting && irr_driver->isGLSL() && !m_alpha_blending && !m_add)
{
m->MaterialType = irr_driver->getShader(ES_OBJECT_UNLIT);
modes++;
}
if (m_alpha_testing)
{
@@ -765,8 +765,8 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
if (irr_driver->isGLSL())
{
if (mb->getVertexType() != video::EVT_TANGENTS)
Log::error("material", "Requiring normal map without tangent enabled mesh");
if (mb->getVertexType() != video::EVT_TANGENTS)
Log::error("material", "Requiring normal map without tangent enabled mesh");
ITexture* tex = irr_driver->getTexture(m_normal_map_tex);
if (m_is_heightmap)
{

View File

@@ -107,7 +107,7 @@ private:
/** If a kart is rescued when driving on this surface. */
bool m_drive_reset;
/** True if this is a texture that will start the jump animatoin when
/** True if this is a texture that will start the jump animatoin when
* leaving it and being in the air. */
bool m_is_jump_texture;
@@ -179,8 +179,8 @@ private:
float m_slowdown_time;
/** Maximum speed at which no more slow down occurs. */
float m_max_speed_fraction;
/** Minimum speed on this terrain. This is used for zippers on a ramp to
* guarantee the right jump distance. A negative value indicates no
/** Minimum speed on this terrain. This is used for zippers on a ramp to
* guarantee the right jump distance. A negative value indicates no
* minimum speed. */
float m_zipper_min_speed;
/** The minimum speed at which a special sfx is started to be played. */
@@ -346,9 +346,9 @@ public:
void onMadeVisible(scene::IMeshBuffer* who);
void onHidden(scene::IMeshBuffer* who);
void isInitiallyHidden(scene::IMeshBuffer* who);
/** For particle system : specify if the particle should be additively blended
*/
bool isAlphaAdditive() const { return !m_alpha_blending; }
/** For particle system : specify if the particle should be additively blended
*/
bool isAlphaAdditive() const { return !m_alpha_blending; }
} ;

View File

@@ -183,7 +183,7 @@ void MaterialManager::loadMaterial()
// Use temp material for reading, but then set the shared
// material index later, so that these materials are not popped
//
addSharedMaterial(file_manager->getAssetChecked(FileManager::TEXTURE,
addSharedMaterial(file_manager->getAssetChecked(FileManager::TEXTURE,
"materials.xml", true));
std::string deprecated = file_manager->getAssetChecked(FileManager::TEXTURE,
"deprecated/materials.xml");

View File

@@ -390,21 +390,21 @@ void ParticleEmitter::setCreationRateAbsolute(float f)
if (f <= 0.0f && m_node->getEmitter())
{
m_node->clearParticles();
m_node->clearParticles();
}
else if (m_node->getEmitter() == NULL)
{
m_node->setEmitter(m_emitter);
}
#endif
/* if (f <= 0.0f)
{
m_node->setVisible(false);
}
else
{
m_node->setVisible(true);
}*/
/* if (f <= 0.0f)
{
m_node->setVisible(false);
}
else
{
m_node->setVisible(true);
}*/
} // setCreationRateAbsolute
//-----------------------------------------------------------------------------
@@ -520,7 +520,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
case EMITTER_POINT:
{
m_emitter = m_node->createPointEmitter(velocity,
type->getMinRate(), type->getMaxRate(),
type->getMinRate(), type->getMaxRate(),
type->getMinColor(), type->getMinColor(),
lifeTimeMin, lifeTimeMax,
m_particle_type->getAngleSpread() /* angle */
@@ -680,7 +680,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
if (flips)
{
if (m_is_glsl)
static_cast<ParticleSystemProxy *>(m_node)->setFlip();
static_cast<ParticleSystemProxy *>(m_node)->setFlip();
}
}
} // setParticleType

View File

@@ -58,11 +58,11 @@ PostProcessing::PostProcessing(IVideoDriver* video_driver)
io::IReadFile *areamap = irr_driver->getDevice()->getFileSystem()->
createMemoryReadFile((void *) AreaMap33, sizeof(AreaMap33),
"AreaMap33", false);
if (!areamap)
{
Log::fatal("postprocessing", "Failed to load the areamap");
return;
}
if (!areamap)
{
Log::fatal("postprocessing", "Failed to load the areamap");
return;
}
m_areamap = irr_driver->getVideoDriver()->getTexture(areamap);
areamap->drop();
@@ -207,77 +207,64 @@ void PostProcessing::update(float dt)
static
void renderBloom(ITexture *in)
{
const float threshold = World::getWorld()->getTrack()->getBloomThreshold();
glUseProgram(FullScreenShader::BloomShader::Program);
glBindVertexArray(FullScreenShader::BloomShader::vao);
glUniform1f(FullScreenShader::BloomShader::uniform_low, threshold);
const float threshold = World::getWorld()->getTrack()->getBloomThreshold();
glUseProgram(FullScreenShader::BloomShader::Program);
glBindVertexArray(FullScreenShader::BloomShader::vao);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::BloomShader::uniform_texture, 0);
setTexture(0, getTextureGLuint(in), GL_NEAREST, GL_NEAREST);
FullScreenShader::BloomShader::setUniforms(0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
static
void renderBloomBlend(ITexture *in)
{
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_DEPTH_TEST);
glUseProgram(FullScreenShader::BloomBlendShader::Program);
glBindVertexArray(FullScreenShader::BloomBlendShader::vao);
glUseProgram(FullScreenShader::BloomBlendShader::Program);
glBindVertexArray(FullScreenShader::BloomBlendShader::vao);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::BloomBlendShader::uniform_texture, 0);
setTexture(0, getTextureGLuint(in), GL_LINEAR, GL_LINEAR);
FullScreenShader::BloomBlendShader::setUniforms(0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
static
void renderColorLevel(ITexture *in)
{
core::vector3df m_inlevel = World::getWorld()->getTrack()->getColorLevelIn();
core::vector2df m_outlevel = World::getWorld()->getTrack()->getColorLevelOut();
core::vector3df m_inlevel = World::getWorld()->getTrack()->getColorLevelIn();
core::vector2df m_outlevel = World::getWorld()->getTrack()->getColorLevelOut();
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glUseProgram(FullScreenShader::ColorLevelShader::Program);
glBindVertexArray(FullScreenShader::ColorLevelShader::vao);
glUniform3f(FullScreenShader::ColorLevelShader::uniform_inlevel, m_inlevel.X, m_inlevel.Y, m_inlevel.Z);
glUniform2f(FullScreenShader::ColorLevelShader::uniform_outlevel, m_outlevel.X, m_outlevel.Y);
glUseProgram(FullScreenShader::ColorLevelShader::Program);
glBindVertexArray(FullScreenShader::ColorLevelShader::vao);
glUniform3f(FullScreenShader::ColorLevelShader::uniform_inlevel, m_inlevel.X, m_inlevel.Y, m_inlevel.Z);
glUniform2f(FullScreenShader::ColorLevelShader::uniform_outlevel, m_outlevel.X, m_outlevel.Y);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in));
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::ColorLevelShader::uniform_tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::ColorLevelShader::uniform_tex, 0);
glUniform1i(FullScreenShader::ColorLevelShader::uniform_dtex, 1);
setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_LOG_LUMINANCE)), GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST);
glUniform1i(FullScreenShader::ColorLevelShader::uniform_logluminancetex, 2);
glUniformMatrix4fv(FullScreenShader::ColorLevelShader::uniform_invprojm, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderDiffuseEnvMap(const float *bSHCoeff, const float *gSHCoeff, const float *rSHCoeff)
@@ -349,103 +336,98 @@ void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &su
void PostProcessing::renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height)
{
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
{
irr_driver->getVideoDriver()->setRenderTarget(temprtt, false, false);
glUseProgram(FullScreenShader::Gaussian3VBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian3VBlurShader::vao);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
{
irr_driver->getVideoDriver()->setRenderTarget(temprtt, false, false);
glUseProgram(FullScreenShader::Gaussian3VBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian3VBlurShader::vao);
glUniform2f(FullScreenShader::Gaussian3VBlurShader::uniform_pixel, inv_width, inv_height);
glUniform2f(FullScreenShader::Gaussian3VBlurShader::uniform_pixel, inv_width, inv_height);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian3VBlurShader::uniform_tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian3VBlurShader::uniform_tex, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
{
irr_driver->getVideoDriver()->setRenderTarget(in, false, false);
glUseProgram(FullScreenShader::Gaussian3HBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian3HBlurShader::vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
{
irr_driver->getVideoDriver()->setRenderTarget(in, false, false);
glUseProgram(FullScreenShader::Gaussian3HBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian3HBlurShader::vao);
glUniform2f(FullScreenShader::Gaussian3HBlurShader::uniform_pixel, inv_width, inv_height);
glUniform2f(FullScreenShader::Gaussian3HBlurShader::uniform_pixel, inv_width, inv_height);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(temprtt));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian3HBlurShader::uniform_tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian3HBlurShader::uniform_tex, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderGaussian6Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height)
{
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
{
irr_driver->getVideoDriver()->setRenderTarget(temprtt, false, false);
glUseProgram(FullScreenShader::Gaussian6VBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian6VBlurShader::vao);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
{
irr_driver->getVideoDriver()->setRenderTarget(temprtt, false, false);
glUseProgram(FullScreenShader::Gaussian6VBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian6VBlurShader::vao);
glUniform2f(FullScreenShader::Gaussian6VBlurShader::uniform_pixel, inv_width, inv_height);
glUniform2f(FullScreenShader::Gaussian6VBlurShader::uniform_pixel, inv_width, inv_height);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian6VBlurShader::uniform_tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian6VBlurShader::uniform_tex, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
{
irr_driver->getVideoDriver()->setRenderTarget(in, false, false);
glUseProgram(FullScreenShader::Gaussian6HBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian6HBlurShader::vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
{
irr_driver->getVideoDriver()->setRenderTarget(in, false, false);
glUseProgram(FullScreenShader::Gaussian6HBlurShader::Program);
glBindVertexArray(FullScreenShader::Gaussian6HBlurShader::vao);
glUniform2f(FullScreenShader::Gaussian6HBlurShader::uniform_pixel, inv_width, inv_height);
glUniform2f(FullScreenShader::Gaussian6HBlurShader::uniform_pixel, inv_width, inv_height);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(temprtt));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian6HBlurShader::uniform_tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::Gaussian6HBlurShader::uniform_tex, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderPassThrough(ITexture *tex)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
glUseProgram(FullScreenShader::PassThroughShader::Program);
glBindVertexArray(FullScreenShader::PassThroughShader::vao);
glUseProgram(FullScreenShader::PassThroughShader::Program);
glBindVertexArray(FullScreenShader::PassThroughShader::vao);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::PassThroughShader::uniform_texture, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::PassThroughShader::uniform_texture, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
void PostProcessing::renderPassThrough(GLuint tex)
@@ -471,85 +453,85 @@ void PostProcessing::renderPassThrough(GLuint tex)
void PostProcessing::renderGlow(ITexture *tex)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
glUseProgram(FullScreenShader::GlowShader::Program);
glBindVertexArray(FullScreenShader::GlowShader::vao);
glUseProgram(FullScreenShader::GlowShader::Program);
glBindVertexArray(FullScreenShader::GlowShader::vao);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::GlowShader::uniform_tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(FullScreenShader::GlowShader::uniform_tex, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
}
ITexture *noise_tex = 0;
void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
if (!noise_tex)
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str());
if (!noise_tex)
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str());
glUseProgram(FullScreenShader::SSAOShader::Program);
glBindVertexArray(FullScreenShader::SSAOShader::vao);
glUseProgram(FullScreenShader::SSAOShader::Program);
glBindVertexArray(FullScreenShader::SSAOShader::vao);
setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST);
setTexture(1, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_LINEAR, GL_LINEAR);
setTexture(2, getTextureGLuint(noise_tex), GL_NEAREST, GL_NEAREST);
FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2);
FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderFog(const core::matrix4 &ipvmat)
{
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
const Track * const track = World::getWorld()->getTrack();
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
const Track * const track = World::getWorld()->getTrack();
// This function is only called once per frame - thus no need for setters.
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const SColor tmpcol = track->getFogColor();
// This function is only called once per frame - thus no need for setters.
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const SColor tmpcol = track->getFogColor();
core::vector3df col( tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f );
core::vector3df col( tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f );
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUseProgram(FullScreenShader::FogShader::Program);
glBindVertexArray(FullScreenShader::FogShader::vao);
glUseProgram(FullScreenShader::FogShader::Program);
glBindVertexArray(FullScreenShader::FogShader::vao);
setTexture(0, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
}
void PostProcessing::renderMotionBlur(unsigned cam, ITexture *in, ITexture *out)
@@ -623,6 +605,76 @@ static void renderGodRay(GLuint tex, const core::vector2df &sunpos)
glEnable(GL_DEPTH_TEST);
}
static void averageTexture(GLuint tex)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glGenerateMipmap(GL_TEXTURE_2D);
}
static void computeLogLuminance(GLuint tex)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
IVideoDriver *const drv = irr_driver->getVideoDriver();
drv->setRenderTarget(irr_driver->getRTT(RTT_LOG_LUMINANCE), false, false);
glUseProgram(FullScreenShader::LogLuminanceShader::Program);
glBindVertexArray(FullScreenShader::LogLuminanceShader::vao);
setTexture(0, tex, GL_LINEAR, GL_LINEAR);
FullScreenShader::LogLuminanceShader::setUniforms(0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
averageTexture(getTextureGLuint(irr_driver->getRTT(RTT_LOG_LUMINANCE)));
}
void PostProcessing::applyMLAA(video::ITexture *in, video::ITexture *out)
{
const core::vector2df &PIXEL_SIZE = core::vector2df(1.0f / UserConfigParams::m_width, 1.0f / UserConfigParams::m_height);
IVideoDriver *const drv = irr_driver->getVideoDriver();
glEnable(GL_STENCIL_TEST);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// Pass 1: color edge detection
setTexture(0, getTextureGLuint(in), GL_NEAREST, GL_NEAREST);
glUseProgram(FullScreenShader::MLAAColorEdgeDetectionSHader::Program);
FullScreenShader::MLAAColorEdgeDetectionSHader::setUniforms(PIXEL_SIZE, 0);
glBindVertexArray(FullScreenShader::MLAAColorEdgeDetectionSHader::vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glStencilFunc(GL_EQUAL, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Pass 2: blend weights
drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false);
glUseProgram(FullScreenShader::MLAABlendWeightSHader::Program);
setTexture(0, getTextureGLuint(out), GL_LINEAR, GL_LINEAR);
setTexture(1, getTextureGLuint(m_areamap), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAABlendWeightSHader::setUniforms(PIXEL_SIZE, 0, 1);
glBindVertexArray(FullScreenShader::MLAABlendWeightSHader::vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Pass 3: gather
drv->setRenderTarget(in, false, false);
glUseProgram(FullScreenShader::MLAAGatherSHader::Program);
setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_TMP3)), GL_NEAREST, GL_NEAREST);
setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_COLOR)), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAAGatherSHader::setUniforms(PIXEL_SIZE, 1, 0);
glBindVertexArray(FullScreenShader::MLAAGatherSHader::vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Done.
glDisable(GL_STENCIL_TEST);
}
// ----------------------------------------------------------------------------
/** Render the post-processed scene */
void PostProcessing::render()
@@ -647,57 +699,53 @@ void PostProcessing::render()
mocb->setCurrentCamera(cam);
ITexture *in = irr_driver->getRTT(RTT_COLOR);
ITexture *out = irr_driver->getRTT(RTT_TMP1);
// Each effect uses these as named, and sets them up for the next effect.
// This allows chaining effects where some may be disabled.
// Each effect uses these as named, and sets them up for the next effect.
// This allows chaining effects where some may be disabled.
// As the original color shouldn't be touched, the first effect can't be disabled.
// As the original color shouldn't be touched, the first effect can't be disabled.
PROFILER_PUSH_CPU_MARKER("- Bloom", 0xFF, 0x00, 0x00);
if (1) // bloom
{
// Blit the base to tmp1
drv->setRenderTarget(out, true, false);
renderPassThrough(in);
// Blit the base to tmp1
drv->setRenderTarget(out, true, false);
renderPassThrough(in);
const bool globalbloom = World::getWorld()->getTrack()->getBloom();
if (globalbloom)
{
drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false);
renderBloom(in);
}
drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false);
renderBloom(in);
if (globalbloom)
{
// Clear the alpha to a suitable value, stencil
glClearColor(0, 0, 0, 0.1f);
glColorMask(0, 0, 0, 1);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
glColorMask(1, 1, 1, 1);
glClear(GL_STENCIL_BUFFER_BIT);
// To half
drv->setRenderTarget(irr_driver->getRTT(RTT_HALF1), true, false);
renderPassThrough(irr_driver->getRTT(RTT_TMP3));
renderPassThrough(irr_driver->getRTT(RTT_TMP3));
// To quarter
drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), true, false);
renderPassThrough(irr_driver->getRTT(RTT_HALF1));
drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), true, false);
renderPassThrough(irr_driver->getRTT(RTT_HALF1));
// To eighth
drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), true, false);
renderPassThrough(irr_driver->getRTT(RTT_QUARTER1));
drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), true, false);
renderPassThrough(irr_driver->getRTT(RTT_QUARTER1));
// Blur it for distribution.
renderGaussian6Blur(irr_driver->getRTT(RTT_EIGHTH1), irr_driver->getRTT(RTT_EIGHTH2), 8.f / UserConfigParams::m_width, 8.f / UserConfigParams::m_height);
renderGaussian6Blur(irr_driver->getRTT(RTT_HALF1), irr_driver->getRTT(RTT_HALF2), 2.f / UserConfigParams::m_width, 2.f / UserConfigParams::m_height);
renderGaussian6Blur(irr_driver->getRTT(RTT_QUARTER1), irr_driver->getRTT(RTT_QUARTER2), 4.f / UserConfigParams::m_width, 4.f / UserConfigParams::m_height);
renderGaussian6Blur(irr_driver->getRTT(RTT_EIGHTH1), irr_driver->getRTT(RTT_EIGHTH2), 8.f / UserConfigParams::m_width, 8.f / UserConfigParams::m_height);
// Additively blend on top of tmp1
drv->setRenderTarget(out, false, false);
renderBloomBlend(irr_driver->getRTT(RTT_EIGHTH1));
drv->setRenderTarget(out, false, false);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glBlendEquation(GL_FUNC_ADD);
renderPassThrough(irr_driver->getRTT(RTT_HALF1));
renderPassThrough(irr_driver->getRTT(RTT_QUARTER1));
renderPassThrough(irr_driver->getRTT(RTT_EIGHTH1));
} // end if bloom
in = irr_driver->getRTT(RTT_TMP1);
@@ -708,6 +756,8 @@ void PostProcessing::render()
PROFILER_PUSH_CPU_MARKER("- Godrays", 0xFF, 0x00, 0x00);
if (m_sunpixels > 30)//World::getWorld()->getTrack()->hasGodRays() && ) // god rays
{
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
// Grab the sky
drv->setRenderTarget(out, true, false);
// irr_driver->getSceneManager()->drawAll(ESNRP_SKY_BOX);
@@ -735,7 +785,7 @@ void PostProcessing::render()
// Blur
renderGaussian3Blur(irr_driver->getRTT(RTT_QUARTER1),
renderGaussian3Blur(irr_driver->getRTT(RTT_QUARTER1),
irr_driver->getRTT(RTT_QUARTER2),
4.f / UserConfigParams::m_width,
4.f / UserConfigParams::m_height);
@@ -796,71 +846,28 @@ void PostProcessing::render()
if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter.
{
PROFILER_PUSH_CPU_MARKER("- MLAA", 0xFF, 0x00, 0x00);
glDisable(GL_BLEND);
drv->setRenderTarget(irr_driver->getRTT(RTT_FINAL_COLOR), false, false);
renderPassThrough(in);
drv->setRenderTarget(out, false, false);
glEnable(GL_STENCIL_TEST);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// Pass 1: color edge detection
m_material.setFlag(EMF_BILINEAR_FILTER, false);
m_material.setFlag(EMF_TRILINEAR_FILTER, false);
m_material.MaterialType = irr_driver->getShader(ES_MLAA_COLOR1);
m_material.setTexture(0, in);
drawQuad(cam, m_material);
m_material.setFlag(EMF_BILINEAR_FILTER, true);
m_material.setFlag(EMF_TRILINEAR_FILTER, true);
glStencilFunc(GL_EQUAL, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Pass 2: blend weights
drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false);
m_material.MaterialType = irr_driver->getShader(ES_MLAA_BLEND2);
m_material.setTexture(0, out);
m_material.setTexture(1, m_areamap);
m_material.TextureLayer[1].BilinearFilter = false;
m_material.TextureLayer[1].TrilinearFilter = false;
drawQuad(cam, m_material);
m_material.TextureLayer[1].BilinearFilter = true;
m_material.TextureLayer[1].TrilinearFilter = true;
m_material.setTexture(1, 0);
// Pass 3: gather
drv->setRenderTarget(in, false, false);
m_material.setFlag(EMF_BILINEAR_FILTER, false);
m_material.setFlag(EMF_TRILINEAR_FILTER, false);
m_material.MaterialType = irr_driver->getShader(ES_MLAA_NEIGH3);
m_material.setTexture(0, irr_driver->getRTT(RTT_TMP3));
m_material.setTexture(1, irr_driver->getRTT(RTT_COLOR));
drawQuad(cam, m_material);
m_material.setFlag(EMF_BILINEAR_FILTER, true);
m_material.setFlag(EMF_TRILINEAR_FILTER, true);
m_material.setTexture(1, 0);
// Done.
glDisable(GL_STENCIL_TEST);
applyMLAA(irr_driver->getRTT(RTT_FINAL_COLOR), out);
in = irr_driver->getRTT(RTT_FINAL_COLOR);
PROFILER_POP_CPU_MARKER();
}
computeLogLuminance(getTextureGLuint(in));
// Final blit
// TODO : Use glBlitFramebuffer
drv->setRenderTarget(ERT_FRAME_BUFFER, false, false);
// TODO : Use glBlitFramebuffer
drv->setRenderTarget(ERT_FRAME_BUFFER, false, false);
glEnable(GL_FRAMEBUFFER_SRGB);
if (irr_driver->getNormals())
renderPassThrough(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
renderPassThrough(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
else if (irr_driver->getSSAOViz())
renderPassThrough(irr_driver->getRTT(RTT_SSAO));
renderPassThrough(irr_driver->getRTT(RTT_SSAO));
else
renderColorLevel(in);
renderColorLevel(in);
glDisable(GL_FRAMEBUFFER_SRGB);
}
} // render

View File

@@ -72,24 +72,25 @@ public:
void begin();
void update(float dt);
/** Generate diffuse and specular map */
void renderSunlight();
/** Generate diffuse and specular map */
void renderSunlight();
void renderShadowedSunlight(const std::vector<core::matrix4> &sun_ortho_matrix, unsigned depthtex);
void renderFog(const core::matrix4 &ipvmat);
void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm);
void renderFog(const core::matrix4 &ipvmat);
void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm);
void renderDiffuseEnvMap(const float *bSHCoeff, const float *gSHCoeff, const float *rSHCoeff);
/** Blur the in texture */
void renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height);
void renderGaussian6Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height);
/** Blur the in texture */
void renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height);
void renderGaussian6Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height);
/** Render tex. Used for blit/texture resize */
void renderPassThrough(video::ITexture *tex);
/** Render tex. Used for blit/texture resize */
void renderPassThrough(video::ITexture *tex);
void renderPassThrough(unsigned tex);
void applyMLAA(video::ITexture *in, video::ITexture *out);
void renderMotionBlur(unsigned cam, video::ITexture *in, video::ITexture *out);
void renderGlow(video::ITexture *tex);
void renderGlow(video::ITexture *tex);
/** Render the post-processed scene */
void render();

View File

@@ -21,7 +21,6 @@
#include "config/user_config.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/camera.hpp"
#include "graphics/glow.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/lens_flare.hpp"
#include "graphics/light.hpp"
@@ -36,6 +35,7 @@
#include "graphics/shaders.hpp"
#include "graphics/shadow_importance.hpp"
#include "graphics/stkmeshscenenode.hpp"
#include "graphics/stkinstancedscenenode.hpp"
#include "graphics/wind.hpp"
#include "io/file_manager.hpp"
#include "items/item.hpp"
@@ -50,6 +50,8 @@
#include <algorithm>
STKInstancedSceneNode *InstancedBox = 0;
void IrrDriver::renderGLSL(float dt)
{
World *world = World::getWorld(); // Never NULL.
@@ -74,24 +76,11 @@ void IrrDriver::renderGLSL(float dt)
// Get a list of all glowing things. The driver's list contains the static ones,
// here we add items, as they may disappear each frame.
std::vector<GlowData> glows = m_glowing;
std::vector<GlowNode *> transparent_glow_nodes;
ItemManager * const items = ItemManager::get();
const u32 itemcount = items->getNumberOfItems();
u32 i;
// For each static node, give it a glow representation
const u32 staticglows = glows.size();
for (i = 0; i < staticglows; i++)
{
scene::ISceneNode * const node = glows[i].node;
const float radius = (node->getBoundingBox().getExtent().getLength() / 2) * 2.0f;
GlowNode * const repnode = new GlowNode(irr_driver->getSceneManager(), radius);
repnode->setPosition(node->getTransformedBoundingBox().getCenter());
transparent_glow_nodes.push_back(repnode);
}
for (i = 0; i < itemcount; i++)
{
Item * const item = items->getItem(i);
@@ -124,12 +113,6 @@ void IrrDriver::renderGLSL(float dt)
dat.b = c.getBlue();
glows.push_back(dat);
// Push back its representation too
const float radius = (node->getBoundingBox().getExtent().getLength() / 2) * 2.0f;
GlowNode * const repnode = new GlowNode(irr_driver->getSceneManager(), radius);
repnode->setPosition(node->getTransformedBoundingBox().getCenter());
transparent_glow_nodes.push_back(repnode);
}
// Start the RTT for post-processing.
@@ -203,7 +186,6 @@ void IrrDriver::renderGLSL(float dt)
irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION));
irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW));
irr_driver->genProjViewMatrix();
PROFILER_POP_CPU_MARKER();
// Todo : reenable glow and shadows
@@ -245,31 +227,28 @@ void IrrDriver::renderGLSL(float dt)
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
m_scene_manager->drawAll(m_renderpass);
PROFILER_POP_CPU_MARKER();
if (World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(irr_driver->getInvProjMatrix());
PROFILER_POP_CPU_MARKER();
}
if (World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(irr_driver->getInvProjMatrix());
PROFILER_POP_CPU_MARKER();
}
PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF);
renderSkybox();
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0xFF, 0x00);
// Render anything glowing.
if (!m_mipviz && !m_wireframe)
{
irr_driver->setPhase(GLOW_PASS);
renderGlow(overridemat, glows, cambox, cam);
} // end glow
// Render anything glowing.
if (!m_mipviz && !m_wireframe)
{
irr_driver->setPhase(GLOW_PASS);
renderGlow(overridemat, glows, cambox, cam);
} // end glow
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF);
renderSkybox();
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("- Lensflare/godray", 0x00, 0xFF, 0xFF);
// Is the lens flare enabled & visible? Check last frame's query.
const bool hasflare = World::getWorld()->getTrack()->hasLensFlare();
@@ -335,14 +314,6 @@ void IrrDriver::renderGLSL(float dt)
}
PROFILER_POP_CPU_MARKER();
// Drawing for this cam done, cleanup
const u32 glowrepcount = transparent_glow_nodes.size();
for (i = 0; i < glowrepcount; i++)
{
transparent_glow_nodes[i]->remove();
transparent_glow_nodes[i]->drop();
}
PROFILER_POP_CPU_MARKER();
// Note that drawAll must be called before rendering
@@ -1025,9 +996,10 @@ static void projectSH(float *color[], size_t width, size_t height,
// Constant obtained by projecting unprojected ref values
float solidangle = 2.75 / (wh * pow(d, 1.5f));
float b = color[face][4 * height * i + 4 * j] / 255.;
float g = color[face][4 * height * i + 4 * j + 1] / 255.;
float r = color[face][4 * height * i + 4 * j + 2] / 255.;
// pow(., 2.2) to convert from srgb
float b = pow(color[face][4 * height * i + 4 * j] / 255., 2.2);
float g = pow(color[face][4 * height * i + 4 * j + 1] / 255., 2.2);
float r = pow(color[face][4 * height * i + 4 * j + 2] / 255., 2.2);
assert(b >= 0.);
@@ -1212,7 +1184,6 @@ void IrrDriver::generateSkyboxCubemap()
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glGenTextures(1, &SkyboxCubeMap);
glGenTextures(1, &ConvolutedSkyboxCubeMap);
GLint w = 0, h = 0;
for (unsigned i = 0; i < 6; i++)
@@ -1241,19 +1212,19 @@ void IrrDriver::generateSkyboxCubemap()
image->drop();
glBindTexture(GL_TEXTURE_CUBE_MAP, SkyboxCubeMap);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_COMPRESSED_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
}
testSH(rgba, w, h, blueSHCoeff, greenSHCoeff, redSHCoeff);
for (unsigned i = 0; i < 6; i++)
/*for (unsigned i = 0; i < 6; i++)
{
glBindTexture(GL_TEXTURE_CUBE_MAP, ConvolutedSkyboxCubeMap);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
}
for (unsigned i = 0; i < 6; i++)
delete[] rgba[i];
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);*/
}
@@ -1280,11 +1251,11 @@ void IrrDriver::renderSkybox()
transform.getInverse(invtransform);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, ConvolutedSkyboxCubeMap);
glBindTexture(GL_TEXTURE_CUBE_MAP, SkyboxCubeMap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glUseProgram(MeshShader::SkyboxShader::Program);
MeshShader::SkyboxShader::setUniforms(transform, invtransform, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0);
MeshShader::SkyboxShader::setUniforms(transform, invtransform, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0);
glDrawElements(GL_TRIANGLES, 6 * 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}

View File

@@ -53,46 +53,35 @@ RTT::RTT()
// Optionally, the collapse ones use a smaller format.
bool stencil = true;
rtts[RTT_TMP1] = drv->addRenderTargetTexture(res, "rtt.tmp1", ECF_A8R8G8B8, stencil);
if(!rtts[RTT_TMP1])
{
// Work around for intel hd3000 cards :(
stencil = false;
rtts[RTT_TMP1] = drv->addRenderTargetTexture(res, "rtt.tmp1", ECF_A8R8G8B8, stencil);
Log::error("rtts", "Stencils for rtt not available, most likely a driver bug.");
if(UserConfigParams::m_pixel_shaders)
{
Log::error("rtts", "This requires pixel shaders to be disabled.");
UserConfigParams::m_pixel_shaders = false;
}
irr_driver->disableGLSL();
}
rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A8R8G8B8, stencil);
rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A8R8G8B8, stencil);
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R8, stencil);
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_G16R16F, stencil);
rtts[RTT_TMP1] = drv->addRenderTargetTexture(res, "rtt.tmp1", ECF_A16B16G16R16F, stencil);
rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A16B16G16R16F, stencil);
rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A16B16G16R16F, stencil);
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R16F, stencil);
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_G16R16F, stencil);
rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A16B16G16R16F, stencil);
rtts[RTT_FINAL_COLOR] = drv->addRenderTargetTexture(res, "rtt.finalcolor", ECF_A8R8G8B8, stencil);
rtts[RTT_LOG_LUMINANCE] = drv->addRenderTargetTexture(shadowsize0, "rtt.logluminance", ECF_R16F, stencil);
rtts[RTT_HALF1] = drv->addRenderTargetTexture(half, "rtt.half1", ECF_A8R8G8B8, stencil);
rtts[RTT_HALF2] = drv->addRenderTargetTexture(half, "rtt.half2", ECF_A8R8G8B8, stencil);
rtts[RTT_HALF1] = drv->addRenderTargetTexture(half, "rtt.half1", ECF_A16B16G16R16F, stencil);
rtts[RTT_HALF2] = drv->addRenderTargetTexture(half, "rtt.half2", ECF_A16B16G16R16F, stencil);
rtts[RTT_QUARTER1] = drv->addRenderTargetTexture(quarter, "rtt.q1", ECF_A8R8G8B8, stencil);
rtts[RTT_QUARTER2] = drv->addRenderTargetTexture(quarter, "rtt.q2", ECF_A8R8G8B8, stencil);
rtts[RTT_QUARTER3] = drv->addRenderTargetTexture(quarter, "rtt.q3", ECF_A8R8G8B8, stencil);
rtts[RTT_QUARTER4] = drv->addRenderTargetTexture(quarter, "rtt.q4", ECF_R8, stencil);
rtts[RTT_QUARTER1] = drv->addRenderTargetTexture(quarter, "rtt.q1", ECF_A16B16G16R16F, stencil);
rtts[RTT_QUARTER2] = drv->addRenderTargetTexture(quarter, "rtt.q2", ECF_A16B16G16R16F, stencil);
rtts[RTT_QUARTER3] = drv->addRenderTargetTexture(quarter, "rtt.q3", ECF_A16B16G16R16F, stencil);
rtts[RTT_QUARTER4] = drv->addRenderTargetTexture(quarter, "rtt.q4", ECF_R16F, stencil);
rtts[RTT_EIGHTH1] = drv->addRenderTargetTexture(eighth, "rtt.e1", ECF_A8R8G8B8, stencil);
rtts[RTT_EIGHTH2] = drv->addRenderTargetTexture(eighth, "rtt.e2", ECF_A8R8G8B8, stencil);
rtts[RTT_EIGHTH1] = drv->addRenderTargetTexture(eighth, "rtt.e1", ECF_A16B16G16R16F, stencil);
rtts[RTT_EIGHTH2] = drv->addRenderTargetTexture(eighth, "rtt.e2", ECF_A16B16G16R16F, stencil);
rtts[RTT_SIXTEENTH1] = drv->addRenderTargetTexture(sixteenth, "rtt.s1", ECF_A8R8G8B8, stencil);
rtts[RTT_SIXTEENTH2] = drv->addRenderTargetTexture(sixteenth, "rtt.s2", ECF_A8R8G8B8, stencil);
rtts[RTT_SIXTEENTH1] = drv->addRenderTargetTexture(sixteenth, "rtt.s1", ECF_A16B16G16R16F, stencil);
rtts[RTT_SIXTEENTH2] = drv->addRenderTargetTexture(sixteenth, "rtt.s2", ECF_A16B16G16R16F, stencil);
rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R8, stencil);
rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R16F, stencil);
rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil);
rtts[RTT_WARPH] = drv->addRenderTargetTexture(warphsize, "rtt.warph", ECF_A8R8G8B8, stencil);
rtts[RTT_DISPLACE] = drv->addRenderTargetTexture(res, "rtt.displace", ECF_A8R8G8B8, stencil);
rtts[RTT_DISPLACE] = drv->addRenderTargetTexture(res, "rtt.displace", ECF_A16B16G16R16F, stencil);
if (((COpenGLDriver *) drv)->queryOpenGLFeature(COpenGLDriver::IRR_ARB_texture_rg))
{

View File

@@ -33,6 +33,7 @@ enum TypeRTT
RTT_TMP4,
RTT_NORMAL_AND_DEPTH,
RTT_COLOR,
RTT_LOG_LUMINANCE,
RTT_HALF1,
RTT_HALF2,
@@ -61,6 +62,7 @@ enum TypeRTT
RTT_HALF_SOFT,
RTT_DISPLACE,
RTT_FINAL_COLOR,
RTT_COUNT
};

View File

@@ -23,8 +23,8 @@ const u16 ScreenQuad::indices[4] = {0, 1, 2, 3};
static const SColor white(255, 255, 255, 255);
const S3DVertex ScreenQuad::vertices[4] = {
S3DVertex(-1, 1, 0, 0, 1, 0, white, 0, 1),
S3DVertex(1, 1, 0, 0, 1, 0, white, 1, 1),
S3DVertex(-1, -1, 0, 0, 1, 0, white, 0, 0),
S3DVertex(1, -1, 0, 0, 1, 0, white, 1, 0),
};
S3DVertex(-1, 1, 0, 0, 1, 0, white, 0, 1),
S3DVertex(1, 1, 0, 0, 1, 0, white, 1, 1),
S3DVertex(-1, -1, 0, 0, 1, 0, white, 0, 0),
S3DVertex(1, -1, 0, 0, 1, 0, white, 1, 0),
};

View File

@@ -229,11 +229,11 @@ void Shaders::loadShaders()
m_shaders[ES_SUNLIGHT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag");
m_shaders[ES_MLAA_COLOR1] = glsl(dir + "mlaa_offset.vert", dir + "mlaa_color1.frag",
m_shaders[ES_MLAA_COLOR1] = glsl(dir + "pass.vert", dir + "pass.frag",
m_callbacks[ES_MLAA_COLOR1]);
m_shaders[ES_MLAA_BLEND2] = glsl(dir + "pass.vert", dir + "mlaa_blend2.frag",
m_shaders[ES_MLAA_BLEND2] = glsl(dir + "pass.vert", dir + "pass.frag",
m_callbacks[ES_MLAA_BLEND2]);
m_shaders[ES_MLAA_NEIGH3] = glsl(dir + "mlaa_offset.vert", dir + "mlaa_neigh3.frag",
m_shaders[ES_MLAA_NEIGH3] = glsl(dir + "pass.vert", dir + "pass.frag",
m_callbacks[ES_MLAA_NEIGH3]);
m_shaders[ES_SHADOWPASS] = glsl(dir + "pass.vert", dir + "pass.frag",
@@ -314,11 +314,21 @@ void Shaders::loadShaders()
FullScreenShader::MotionBlurShader::init();
FullScreenShader::GodFadeShader::init();
FullScreenShader::GodRayShader::init();
FullScreenShader::LogLuminanceShader::init();
FullScreenShader::MLAAColorEdgeDetectionSHader::init();
FullScreenShader::MLAABlendWeightSHader::init();
FullScreenShader::MLAAGatherSHader::init();
MeshShader::ColorizeShader::init();
MeshShader::NormalMapShader::init();
MeshShader::ObjectPass1Shader::init();
MeshShader::ObjectRefPass1Shader::init();
MeshShader::InstancedObjectPass1Shader::init();
MeshShader::InstancedObjectRefPass1Shader::init();
MeshShader::InstancedGrassPass1Shader::init();
MeshShader::ObjectPass2Shader::init();
MeshShader::InstancedObjectPass2Shader::init();
MeshShader::InstancedObjectRefPass2Shader::init();
MeshShader::InstancedGrassPass2Shader::init();
MeshShader::DetailledObjectPass2Shader::init();
MeshShader::ObjectRimLimitShader::init();
MeshShader::UntexturedObjectShader::init();
@@ -337,7 +347,9 @@ void Shaders::loadShaders()
MeshShader::DisplaceShader::init();
MeshShader::DisplaceMaskShader::init();
MeshShader::ShadowShader::init();
MeshShader::InstancedShadowShader::init();
MeshShader::RefShadowShader::init();
MeshShader::InstancedRefShadowShader::init();
MeshShader::GrassShadowShader::init();
MeshShader::SkyboxShader::init();
ParticleShader::FlipParticleRender::init();
@@ -347,6 +359,7 @@ void Shaders::loadShaders()
UIShader::ColoredRectShader::init();
UIShader::ColoredTextureRectShader::init();
UIShader::TextureRectShader::init();
UIShader::UniformColoredTextureRectShader::init();
}
Shaders::~Shaders()
@@ -388,7 +401,7 @@ namespace MeshShader
void ObjectPass1Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass1.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -415,7 +428,7 @@ namespace MeshShader
void ObjectRefPass1Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/objectref_pass1.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -448,7 +461,7 @@ namespace MeshShader
void GrassPass1Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass1.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -500,6 +513,114 @@ namespace MeshShader
glUniform1i(uniform_normalMap, TU_normalMap);
}
GLuint InstancedObjectPass1Shader::Program;
GLuint InstancedObjectPass1Shader::attrib_position;
GLuint InstancedObjectPass1Shader::attrib_normal;
GLuint InstancedObjectPass1Shader::attrib_orientation;
GLuint InstancedObjectPass1Shader::attrib_origin;
GLuint InstancedObjectPass1Shader::attrib_scale;
GLuint InstancedObjectPass1Shader::uniform_MP;
GLuint InstancedObjectPass1Shader::uniform_VM;
void InstancedObjectPass1Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_position = glGetAttribLocation(Program, "Position");
attrib_scale = glGetAttribLocation(Program, "Scale");
attrib_normal = glGetAttribLocation(Program, "Normal");
uniform_MP = glGetUniformLocation(Program, "ViewProjectionMatrix");
uniform_VM = glGetUniformLocation(Program, "InverseViewMatrix");
}
void InstancedObjectPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ViewMatrix)
{
glUniformMatrix4fv(uniform_MP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_VM, 1, GL_FALSE, ViewMatrix.pointer());
}
GLuint InstancedObjectRefPass1Shader::Program;
GLuint InstancedObjectRefPass1Shader::attrib_position;
GLuint InstancedObjectRefPass1Shader::attrib_normal;
GLuint InstancedObjectRefPass1Shader::attrib_texcoord;
GLuint InstancedObjectRefPass1Shader::attrib_orientation;
GLuint InstancedObjectRefPass1Shader::attrib_origin;
GLuint InstancedObjectRefPass1Shader::attrib_scale;
GLuint InstancedObjectRefPass1Shader::uniform_MP;
GLuint InstancedObjectRefPass1Shader::uniform_VM;
GLuint InstancedObjectRefPass1Shader::uniform_tex;
void InstancedObjectRefPass1Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_position = glGetAttribLocation(Program, "Position");
attrib_scale = glGetAttribLocation(Program, "Scale");
attrib_normal = glGetAttribLocation(Program, "Normal");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MP = glGetUniformLocation(Program, "ViewProjectionMatrix");
uniform_VM = glGetUniformLocation(Program, "InverseViewMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
}
void InstancedObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex)
{
glUniformMatrix4fv(uniform_MP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_VM, 1, GL_FALSE, ViewMatrix.pointer());
glUniform1i(uniform_tex, TU_tex);
}
GLuint InstancedGrassPass1Shader::Program;
GLuint InstancedGrassPass1Shader::attrib_position;
GLuint InstancedGrassPass1Shader::attrib_normal;
GLuint InstancedGrassPass1Shader::attrib_origin;
GLuint InstancedGrassPass1Shader::attrib_orientation;
GLuint InstancedGrassPass1Shader::attrib_scale;
GLuint InstancedGrassPass1Shader::attrib_texcoord;
GLuint InstancedGrassPass1Shader::attrib_color;
GLuint InstancedGrassPass1Shader::uniform_MP;
GLuint InstancedGrassPass1Shader::uniform_IVM;
GLuint InstancedGrassPass1Shader::uniform_windDir;
GLuint InstancedGrassPass1Shader::uniform_tex;
void InstancedGrassPass1Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_grass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_scale = glGetAttribLocation(Program, "Scale");
attrib_position = glGetAttribLocation(Program, "Position");
attrib_normal = glGetAttribLocation(Program, "Normal");
attrib_color = glGetAttribLocation(Program, "Color");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MP = glGetUniformLocation(Program, "ViewProjectionMatrix");
uniform_IVM = glGetUniformLocation(Program, "InverseViewMatrix");
uniform_windDir = glGetUniformLocation(Program, "windDir");
uniform_tex = glGetUniformLocation(Program, "tex");
}
void InstancedGrassPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::vector3df &windDir, unsigned TU_tex)
{
glUniformMatrix4fv(uniform_MP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_IVM, 1, GL_FALSE, InverseViewMatrix.pointer());
glUniform3f(uniform_windDir, windDir.X, windDir.Y, windDir.Z);
glUniform1i(uniform_tex, TU_tex);
}
// Solid Lit pass shaders
GLuint ObjectPass2Shader::Program;
@@ -514,7 +635,7 @@ namespace MeshShader
void ObjectPass2Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -546,6 +667,108 @@ namespace MeshShader
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint InstancedObjectPass2Shader::Program;
GLuint InstancedObjectPass2Shader::attrib_position;
GLuint InstancedObjectPass2Shader::attrib_texcoord;
GLuint InstancedObjectPass2Shader::attrib_origin;
GLuint InstancedObjectPass2Shader::attrib_orientation;
GLuint InstancedObjectPass2Shader::attrib_scale;
GLuint InstancedObjectPass2Shader::uniform_VP;
GLuint InstancedObjectPass2Shader::uniform_TM;
GLuint InstancedObjectPass2Shader::uniform_screen;
GLuint InstancedObjectPass2Shader::uniform_ambient;
GLuint InstancedObjectPass2Shader::TU_Albedo;
void InstancedObjectPass2Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_scale = glGetAttribLocation(Program, "Scale");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ambient = glGetUniformLocation(Program, "ambient");
TU_Albedo = 3;
glUseProgram(Program);
glUniform1i(uniform_DiffuseMap, 0);
glUniform1i(uniform_SpecularMap, 1);
glUniform1i(uniform_SSAO, 2);
glUniform1i(uniform_Albedo, TU_Albedo);
glUseProgram(0);
}
void InstancedObjectPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
glUniformMatrix4fv(uniform_VP, 1, GL_FALSE, ViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint InstancedObjectRefPass2Shader::Program;
GLuint InstancedObjectRefPass2Shader::attrib_position;
GLuint InstancedObjectRefPass2Shader::attrib_texcoord;
GLuint InstancedObjectRefPass2Shader::attrib_origin;
GLuint InstancedObjectRefPass2Shader::attrib_orientation;
GLuint InstancedObjectRefPass2Shader::attrib_scale;
GLuint InstancedObjectRefPass2Shader::uniform_VP;
GLuint InstancedObjectRefPass2Shader::uniform_TM;
GLuint InstancedObjectRefPass2Shader::uniform_screen;
GLuint InstancedObjectRefPass2Shader::uniform_ambient;
GLuint InstancedObjectRefPass2Shader::TU_Albedo;
void InstancedObjectRefPass2Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_scale = glGetAttribLocation(Program, "Scale");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ambient = glGetUniformLocation(Program, "ambient");
TU_Albedo = 3;
glUseProgram(Program);
glUniform1i(uniform_DiffuseMap, 0);
glUniform1i(uniform_SpecularMap, 1);
glUniform1i(uniform_SSAO, 2);
glUniform1i(uniform_Albedo, TU_Albedo);
glUseProgram(0);
}
void InstancedObjectRefPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
glUniformMatrix4fv(uniform_VP, 1, GL_FALSE, ViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint DetailledObjectPass2Shader::Program;
GLuint DetailledObjectPass2Shader::attrib_position;
GLuint DetailledObjectPass2Shader::attrib_texcoord;
@@ -559,7 +782,7 @@ namespace MeshShader
void DetailledObjectPass2Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -602,7 +825,7 @@ namespace MeshShader
void ObjectUnlitShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
@@ -719,7 +942,7 @@ namespace MeshShader
{
initGL();
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -764,7 +987,7 @@ namespace MeshShader
void GrassPass2Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -797,6 +1020,74 @@ namespace MeshShader
glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
}
GLuint InstancedGrassPass2Shader::Program;
GLuint InstancedGrassPass2Shader::attrib_position;
GLuint InstancedGrassPass2Shader::attrib_texcoord;
GLuint InstancedGrassPass2Shader::attrib_color;
GLuint InstancedGrassPass2Shader::attrib_normal;
GLuint InstancedGrassPass2Shader::attrib_origin;
GLuint InstancedGrassPass2Shader::attrib_orientation;
GLuint InstancedGrassPass2Shader::attrib_scale;
GLuint InstancedGrassPass2Shader::uniform_VP;
GLuint InstancedGrassPass2Shader::uniform_screen;
GLuint InstancedGrassPass2Shader::uniform_ambient;
GLuint InstancedGrassPass2Shader::uniform_windDir;
GLuint InstancedGrassPass2Shader::uniform_invproj;
GLuint InstancedGrassPass2Shader::uniform_IVM;
GLuint InstancedGrassPass2Shader::uniform_SunDir;
GLuint InstancedGrassPass2Shader::TU_Albedo;
GLuint InstancedGrassPass2Shader::TU_dtex;
void InstancedGrassPass2Shader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_grass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_color = glGetAttribLocation(Program, "Color");
attrib_normal = glGetAttribLocation(Program, "Normal");
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_scale = glGetAttribLocation(Program, "Scale");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix");
GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
GLuint uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ambient = glGetUniformLocation(Program, "ambient");
uniform_windDir = glGetUniformLocation(Program, "windDir");
uniform_invproj = glGetUniformLocation(Program, "invproj");
uniform_IVM = glGetUniformLocation(Program, "InverseViewMatrix");
uniform_SunDir = glGetUniformLocation(Program, "SunDir");
TU_Albedo = 3;
TU_dtex = 4;
glUseProgram(Program);
glUniform1i(uniform_DiffuseMap, 0);
glUniform1i(uniform_SpecularMap, 1);
glUniform1i(uniform_SSAO, 2);
glUniform1i(uniform_Albedo, TU_Albedo);
glUniform1i(uniform_dtex, TU_dtex);
glUseProgram(0);
}
void InstancedGrassPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::matrix4 &invproj, const core::vector3df &windDirection, const core::vector3df &SunDir)
{
glUniformMatrix4fv(uniform_VP, 1, GL_FALSE, ViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, invproj.pointer());
glUniformMatrix4fv(uniform_IVM, 1, GL_FALSE, InverseViewMatrix.pointer());
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
glUniform3f(uniform_SunDir, SunDir.X, SunDir.Y, SunDir.Z);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
}
GLuint SphereMapShader::Program;
GLuint SphereMapShader::attrib_position;
GLuint SphereMapShader::attrib_normal;
@@ -810,7 +1101,7 @@ namespace MeshShader
void SphereMapShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass1.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_normal = glGetAttribLocation(Program, "Normal");
@@ -908,7 +1199,7 @@ namespace MeshShader
void CausticsShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/caustics.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
@@ -1093,7 +1384,7 @@ namespace MeshShader
void ColorizeShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colorize.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
@@ -1108,7 +1399,8 @@ namespace MeshShader
GLuint ShadowShader::Program;
GLuint ShadowShader::attrib_position;
GLuint ShadowShader::uniform_MVP;
GLuint ShadowShader::uniform_VP;
GLuint ShadowShader::uniform_MM;
void ShadowShader::init()
{
@@ -1123,24 +1415,65 @@ namespace MeshShader
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix[0]");
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
}
void ShadowShader::setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix)
void ShadowShader::setUniforms(const core::matrix4 &ModelMatrix, const std::vector<core::matrix4> &ViewProjectionMatrix)
{
size_t size = ModelViewProjectionMatrix.size();
size_t size = ViewProjectionMatrix.size();
float *tmp = new float[16 * size];
for (unsigned i = 0; i < size; i++) {
memcpy(&tmp[16 * i], ModelViewProjectionMatrix[i].pointer(), 16 * sizeof(float));
memcpy(&tmp[16 * i], ViewProjectionMatrix[i].pointer(), 16 * sizeof(float));
}
glUniformMatrix4fv(uniform_MVP, size, GL_FALSE, tmp);
glUniformMatrix4fv(uniform_VP, size, GL_FALSE, tmp);
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
delete[] tmp;
}
GLuint InstancedShadowShader::Program;
GLuint InstancedShadowShader::attrib_position;
GLuint InstancedShadowShader::attrib_origin;
GLuint InstancedShadowShader::attrib_orientation;
GLuint InstancedShadowShader::attrib_scale;
GLuint InstancedShadowShader::uniform_VP;
void InstancedShadowShader::init()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
{
attrib_position = -1;
return;
}
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_scale = glGetAttribLocation(Program, "Scale");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix[0]");
}
void InstancedShadowShader::setUniforms(const std::vector<core::matrix4> &ViewProjectionMatrix)
{
size_t size = ViewProjectionMatrix.size();
float *tmp = new float[16 * size];
for (unsigned i = 0; i < size; i++) {
memcpy(&tmp[16 * i], ViewProjectionMatrix[i].pointer(), 16 * sizeof(float));
}
glUniformMatrix4fv(uniform_VP, size, GL_FALSE, tmp);
delete[] tmp;
}
GLuint RefShadowShader::Program;
GLuint RefShadowShader::attrib_position;
GLuint RefShadowShader::attrib_texcoord;
GLuint RefShadowShader::uniform_MVP;
GLuint RefShadowShader::uniform_VP;
GLuint RefShadowShader::uniform_MM;
GLuint RefShadowShader::uniform_tex;
void RefShadowShader::init()
@@ -1158,18 +1491,64 @@ namespace MeshShader
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix[0]");
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
}
void RefShadowShader::setUniforms(const core::matrix4 &ModelMatrix, const std::vector<core::matrix4> &ViewProjectionMatrix, unsigned TU_tex)
{
size_t size = ViewProjectionMatrix.size();
float *tmp = new float[16 * size];
for (unsigned i = 0; i < size; i++) {
memcpy(&tmp[16 * i], ViewProjectionMatrix[i].pointer(), 16 * sizeof(float));
}
glUniformMatrix4fv(uniform_VP, size, GL_FALSE, tmp);
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
glUniform1i(uniform_tex, TU_tex);
delete[] tmp;
}
GLuint InstancedRefShadowShader::Program;
GLuint InstancedRefShadowShader::attrib_position;
GLuint InstancedRefShadowShader::attrib_texcoord;
GLuint InstancedRefShadowShader::attrib_origin;
GLuint InstancedRefShadowShader::attrib_orientation;
GLuint InstancedRefShadowShader::attrib_scale;
GLuint InstancedRefShadowShader::uniform_VP;
GLuint InstancedRefShadowShader::uniform_tex;
void InstancedRefShadowShader::init()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
{
attrib_position = -1;
attrib_texcoord = -1;
return;
}
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation");
attrib_scale = glGetAttribLocation(Program, "Scale");
uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix[0]");
uniform_tex = glGetUniformLocation(Program, "tex");
}
void RefShadowShader::setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix, unsigned TU_tex)
void InstancedRefShadowShader::setUniforms(const std::vector<core::matrix4> &ViewProjectionMatrix, unsigned TU_tex)
{
size_t size = ModelViewProjectionMatrix.size();
size_t size = ViewProjectionMatrix.size();
float *tmp = new float[16 * size];
for (unsigned i = 0; i < size; i++) {
memcpy(&tmp[16 * i], ModelViewProjectionMatrix[i].pointer(), 16 * sizeof(float));
memcpy(&tmp[16 * i], ViewProjectionMatrix[i].pointer(), 16 * sizeof(float));
}
glUniformMatrix4fv(uniform_MVP, size, GL_FALSE, tmp);
glUniformMatrix4fv(uniform_VP, size, GL_FALSE, tmp);
glUniform1i(uniform_tex, TU_tex);
delete[] tmp;
}
@@ -1185,7 +1564,7 @@ namespace MeshShader
void GrassShadowShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
@@ -1274,7 +1653,7 @@ namespace MeshShader
void SkyboxShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass2.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sky.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
@@ -1588,21 +1967,24 @@ namespace FullScreenShader
{
GLuint BloomShader::Program;
GLuint BloomShader::uniform_texture;
GLuint BloomShader::uniform_low;
GLuint BloomShader::vao;
void BloomShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloom.frag").c_str());
uniform_texture = glGetUniformLocation(Program, "tex");
uniform_low = glGetUniformLocation(Program, "low");
vao = createVAO(Program);
}
void BloomShader::setUniforms(unsigned TU_tex)
{
glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex);
}
GLuint BloomBlendShader::Program;
GLuint BloomBlendShader::uniform_texture;
GLuint BloomBlendShader::uniform_low;
GLuint BloomBlendShader::vao;
void BloomBlendShader::init()
{
@@ -1613,8 +1995,14 @@ namespace FullScreenShader
vao = createVAO(Program);
}
void BloomBlendShader::setUniforms(unsigned TU_tex)
{
glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex);
}
GLuint ColorLevelShader::Program;
GLuint ColorLevelShader::uniform_tex;
GLuint ColorLevelShader::uniform_logluminancetex;
GLuint ColorLevelShader::uniform_inlevel;
GLuint ColorLevelShader::uniform_outlevel;
GLuint ColorLevelShader::vao;
@@ -1624,8 +2012,11 @@ namespace FullScreenShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getRGBfromCIEXxy.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/color_levels.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_logluminancetex = glGetUniformLocation(Program, "logluminancetex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_inlevel = glGetUniformLocation(Program, "inlevel");
uniform_outlevel = glGetUniformLocation(Program, "outlevel");
@@ -2144,6 +2535,93 @@ namespace FullScreenShader
glUniform2f(uniform_sunpos, sunpos.X, sunpos.Y);
glUniform1i(uniform_tex, TU_tex);
}
GLuint LogLuminanceShader::Program;
GLuint LogLuminanceShader::uniform_tex;
GLuint LogLuminanceShader::vao;
void LogLuminanceShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/logluminance.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
vao = createVAO(Program);
}
void LogLuminanceShader::setUniforms(unsigned TU_tex)
{
glUniform1i(uniform_tex, TU_tex);
}
GLuint MLAAColorEdgeDetectionSHader::Program;
GLuint MLAAColorEdgeDetectionSHader::uniform_colorMapG;
GLuint MLAAColorEdgeDetectionSHader::uniform_PIXEL_SIZE;
GLuint MLAAColorEdgeDetectionSHader::vao;
void MLAAColorEdgeDetectionSHader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/mlaa_offset.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/mlaa_color1.frag").c_str());
uniform_colorMapG = glGetUniformLocation(Program, "colorMapG");
uniform_PIXEL_SIZE = glGetUniformLocation(Program, "PIXEL_SIZE");
vao = createVAO(Program);
}
void MLAAColorEdgeDetectionSHader::setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colorMapG)
{
glUniform1i(uniform_colorMapG, TU_colorMapG);
glUniform2f(uniform_PIXEL_SIZE, PIXEL_SIZE.X, PIXEL_SIZE.Y);
}
GLuint MLAABlendWeightSHader::Program;
GLuint MLAABlendWeightSHader::uniform_edgesMap;
GLuint MLAABlendWeightSHader::uniform_areaMap;
GLuint MLAABlendWeightSHader::uniform_PIXEL_SIZE;
GLuint MLAABlendWeightSHader::vao;
void MLAABlendWeightSHader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/mlaa_color1.frag").c_str());
uniform_edgesMap = glGetUniformLocation(Program, "edgesMap");
uniform_areaMap = glGetUniformLocation(Program, "areaMap");
uniform_PIXEL_SIZE = glGetUniformLocation(Program, "PIXEL_SIZE");
vao = createVAO(Program);
}
void MLAABlendWeightSHader::setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_edgesMap, unsigned TU_areaMap)
{
glUniform1i(uniform_edgesMap, TU_edgesMap);
glUniform1i(uniform_areaMap, TU_areaMap);
glUniform2f(uniform_PIXEL_SIZE, PIXEL_SIZE.X, PIXEL_SIZE.Y);
}
GLuint MLAAGatherSHader::Program;
GLuint MLAAGatherSHader::uniform_colorMap;
GLuint MLAAGatherSHader::uniform_blendMap;
GLuint MLAAGatherSHader::uniform_PIXEL_SIZE;
GLuint MLAAGatherSHader::vao;
void MLAAGatherSHader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/mlaa_offset.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/mlaa_neigh3.frag").c_str());
uniform_colorMap = glGetUniformLocation(Program, "colorMap");
uniform_blendMap = glGetUniformLocation(Program, "blendMap");
uniform_PIXEL_SIZE = glGetUniformLocation(Program, "PIXEL_SIZE");
vao = createVAO(Program);
}
void MLAAGatherSHader::setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colormap, unsigned TU_blendmap)
{
glUniform1i(uniform_colorMap, TU_colormap);
glUniform1i(uniform_blendMap, TU_blendmap);
glUniform2f(uniform_PIXEL_SIZE, PIXEL_SIZE.X, PIXEL_SIZE.Y);
}
}
namespace UIShader
@@ -2190,6 +2668,51 @@ namespace UIShader
glUniform2f(uniform_texsize, tex_width, tex_height);
}
GLuint UniformColoredTextureRectShader::Program;
GLuint UniformColoredTextureRectShader::attrib_position;
GLuint UniformColoredTextureRectShader::attrib_texcoord;
GLuint UniformColoredTextureRectShader::uniform_tex;
GLuint UniformColoredTextureRectShader::uniform_color;
GLuint UniformColoredTextureRectShader::uniform_center;
GLuint UniformColoredTextureRectShader::uniform_size;
GLuint UniformColoredTextureRectShader::uniform_texcenter;
GLuint UniformColoredTextureRectShader::uniform_texsize;
GLuint UniformColoredTextureRectShader::vao;
void UniformColoredTextureRectShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/texturedquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/uniformcolortexturedquad.frag").c_str());
attrib_position = glGetAttribLocation(Program, "position");
attrib_texcoord = glGetAttribLocation(Program, "texcoord");
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_color = glGetUniformLocation(Program, "color");
uniform_center = glGetUniformLocation(Program, "center");
uniform_size = glGetUniformLocation(Program, "size");
uniform_texcenter = glGetUniformLocation(Program, "texcenter");
uniform_texsize = glGetUniformLocation(Program, "texsize");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(attrib_position);
glEnableVertexAttribArray(attrib_texcoord);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float)));
glBindVertexArray(0);
}
void UniformColoredTextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, const SColor &color, unsigned TU_tex)
{
glUniform1i(uniform_tex, TU_tex);
glUniform2f(uniform_center, center_pos_x, center_pos_y);
glUniform2f(uniform_size, width, height);
glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y);
glUniform2f(uniform_texsize, tex_width, tex_height);
glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
GLuint ColoredTextureRectShader::Program;
GLuint ColoredTextureRectShader::attrib_position;
GLuint ColoredTextureRectShader::attrib_texcoord;

View File

@@ -21,7 +21,7 @@
#include <IMeshSceneNode.h>
#include <vector>
typedef unsigned int GLuint;
typedef unsigned int GLuint;
using namespace irr;
class ParticleSystemProxy;
@@ -36,22 +36,22 @@ namespace MeshShader
class ObjectPass1Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal;
static GLuint uniform_MVP, uniform_TIMV;
static GLuint Program;
static GLuint attrib_position, attrib_normal;
static GLuint uniform_MVP, uniform_TIMV;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
};
class ObjectRefPass1Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord;
static GLuint uniform_MVP, uniform_TM, uniform_TIMV, uniform_tex;
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord;
static GLuint uniform_MVP, uniform_TM, uniform_TIMV, uniform_tex;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_texture);
};
@@ -77,111 +77,180 @@ public:
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_normalMap);
};
class InstancedObjectPass1Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_MP, uniform_VM;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &ViewMatrix);
};
class InstancedObjectRefPass1Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_MP, uniform_VM, uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex);
};
class InstancedGrassPass1Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_origin, attrib_orientation, attrib_scale, attrib_color, attrib_texcoord;
static GLuint uniform_MP, uniform_IVM, uniform_windDir, uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::vector3df &windDir, unsigned TU_tex);
};
class ObjectPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient;
static GLuint TU_Albedo;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
};
class InstancedObjectPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_VP, uniform_TM, uniform_screen, uniform_ambient;
static GLuint TU_Albedo;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix);
};
class InstancedObjectRefPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_VP, uniform_TM, uniform_screen, uniform_ambient;
static GLuint TU_Albedo;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix);
};
class DetailledObjectPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint uniform_MVP, uniform_screen, uniform_ambient;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint uniform_MVP, uniform_screen, uniform_ambient;
static GLuint TU_Albedo, TU_detail;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
};
class ObjectRimLimitShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord;
static GLuint uniform_MVP, uniform_TIMV, uniform_TM, uniform_screen, uniform_ambient;
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord;
static GLuint uniform_MVP, uniform_TIMV, uniform_TM, uniform_screen, uniform_ambient;
static GLuint TU_Albedo;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix);
};
class UntexturedObjectShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_color;
static GLuint uniform_MVP, uniform_screen, uniform_ambient;
static GLuint Program;
static GLuint attrib_position, attrib_color;
static GLuint uniform_MVP, uniform_screen, uniform_ambient;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
};
class ObjectUnlitShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP;
static GLuint TU_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
};
class ObjectRefPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient;
static GLuint TU_Albedo;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
};
class GrassPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_MVP, uniform_screen, uniform_ambient, uniform_windDir;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_MVP, uniform_screen, uniform_ambient, uniform_windDir;
static GLuint TU_Albedo;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection);
};
class InstancedGrassPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_normal, attrib_color, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_VP, uniform_TM, uniform_IVM, uniform_screen, uniform_ambient, uniform_windDir, uniform_invproj, uniform_SunDir;
static GLuint TU_Albedo, TU_dtex;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::matrix4 &invproj, const core::vector3df &windDirection, const core::vector3df &SunDir);
};
class SphereMapShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal;
static GLuint Program;
static GLuint attrib_position, attrib_normal;
static GLuint uniform_MVP, uniform_TIMV, uniform_TVM, uniform_invproj, uniform_screen;
static GLuint TU_tex;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeViewMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &InvProj, const core::vector2df& screen);
};
class SplattingShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint uniform_MVP, uniform_screen, uniform_ambient;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint uniform_MVP, uniform_screen, uniform_ambient;
static GLuint TU_tex_layout, TU_tex_detail0, TU_tex_detail1, TU_tex_detail2, TU_tex_detail3;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
};
class CausticsShader
@@ -199,22 +268,22 @@ public:
class BubbleShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_tex, uniform_time, uniform_transparency;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency);
};
class TransparentShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_MVP, uniform_TM, uniform_tex;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_MVP, uniform_TM, uniform_tex;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex);
};
@@ -232,24 +301,24 @@ public:
class BillboardShader
{
public:
static GLuint Program;
static GLuint attrib_corner, attrib_texcoord;
static GLuint uniform_MV, uniform_P, uniform_tex, uniform_Position, uniform_Size;
static GLuint Program;
static GLuint attrib_corner, attrib_texcoord;
static GLuint uniform_MV, uniform_P, uniform_tex, uniform_Position, uniform_Size;
static void init();
static void setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d<float> &size, unsigned TU_tex);
static void init();
static void setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d<float> &size, unsigned TU_tex);
};
class ColorizeShader
{
public:
static GLuint Program;
static GLuint attrib_position;
static GLuint uniform_MVP, uniform_col;
static GLuint Program;
static GLuint attrib_position;
static GLuint uniform_MVP, uniform_col;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b);
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b);
};
class ShadowShader
@@ -257,10 +326,21 @@ class ShadowShader
public:
static GLuint Program;
static GLuint attrib_position;
static GLuint uniform_MVP;
static GLuint uniform_VP, uniform_MM;
static void init();
static void setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix);
static void setUniforms(const core::matrix4 &ModelMatrix, const std::vector<core::matrix4> &ViewProjectionMatrix);
};
class InstancedShadowShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_VP;
static void init();
static void setUniforms(const std::vector<core::matrix4> &ViewProjectionMatrix);
};
class RefShadowShader
@@ -268,7 +348,18 @@ class RefShadowShader
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_tex;
static GLuint uniform_VP, uniform_MM, uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const std::vector<core::matrix4> &ModelViewProjectionMatrix, unsigned TU_tex);
};
class InstancedRefShadowShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_VP, uniform_tex;
static void init();
static void setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix, unsigned TU_tex);
@@ -299,11 +390,11 @@ public:
class DisplaceShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint uniform_MVP, uniform_MV, uniform_displacement_tex, uniform_mask_tex, uniform_color_tex, uniform_screen, uniform_dir, uniform_dir2;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex);
};
@@ -359,11 +450,11 @@ namespace ParticleShader
class SimpleSimulationShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_velocity, attrib_lifetime, attrib_initial_position, attrib_initial_velocity, attrib_initial_lifetime, attrib_size, attrib_initial_size;
static GLuint uniform_sourcematrix, uniform_dt, uniform_level, uniform_size_increase_factor;
static GLuint Program;
static GLuint attrib_position, attrib_velocity, attrib_lifetime, attrib_initial_position, attrib_initial_velocity, attrib_initial_lifetime, attrib_size, attrib_initial_size;
static GLuint uniform_sourcematrix, uniform_dt, uniform_level, uniform_size_increase_factor;
static void init();
static void init();
};
@@ -371,23 +462,23 @@ public:
class HeightmapSimulationShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_velocity, attrib_lifetime, attrib_initial_position, attrib_initial_velocity, attrib_initial_lifetime, attrib_size, attrib_initial_size;
static GLuint uniform_sourcematrix, uniform_dt, uniform_level, uniform_size_increase_factor;
static GLuint uniform_track_x, uniform_track_z, uniform_track_x_len, uniform_track_z_len, uniform_heightmap;
static GLuint Program;
static GLuint attrib_position, attrib_velocity, attrib_lifetime, attrib_initial_position, attrib_initial_velocity, attrib_initial_lifetime, attrib_size, attrib_initial_size;
static GLuint uniform_sourcematrix, uniform_dt, uniform_level, uniform_size_increase_factor;
static GLuint uniform_track_x, uniform_track_z, uniform_track_x_len, uniform_track_z_len, uniform_heightmap;
static void init();
static void init();
};
class SimpleParticleRender
{
public:
static GLuint Program;
static GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_dtex, uniform_screen, uniform_invproj, uniform_color_from, uniform_color_to;
static GLuint Program;
static GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_dtex, uniform_screen, uniform_invproj, uniform_color_from, uniform_color_to;
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix,
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix,
const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex,
unsigned TU_normal_and_depth, const ParticleSystemProxy* particle_system);
};
@@ -395,12 +486,12 @@ public:
class FlipParticleRender
{
public:
static GLuint Program;
static GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz, attrib_rotationvec, attrib_anglespeed;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_dtex, uniform_screen, uniform_invproj;
static GLuint Program;
static GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz, attrib_rotationvec, attrib_anglespeed;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_dtex, uniform_screen, uniform_invproj;
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth);
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth);
};
}
@@ -410,42 +501,44 @@ namespace FullScreenShader
class BloomShader
{
public:
static GLuint Program;
static GLuint uniform_texture, uniform_low;
static GLuint vao;
static GLuint Program;
static GLuint uniform_texture;
static GLuint vao;
static void init();
static void init();
static void setUniforms(unsigned TU_tex);
};
class BloomBlendShader
{
public:
static GLuint Program;
static GLuint uniform_texture, uniform_low;
static GLuint vao;
static GLuint Program;
static GLuint uniform_texture;
static GLuint vao;
static void init();
static void init();
static void setUniforms(unsigned TU_tex);
};
class ColorLevelShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_invprojm, uniform_dtex, uniform_inlevel, uniform_outlevel;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex, uniform_invprojm, uniform_dtex, uniform_inlevel, uniform_outlevel, uniform_logluminancetex;
static GLuint vao;
static void init();
static void init();
};
class SunLightShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj;
static GLuint vao;
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj;
static GLuint vao;
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
};
class DiffuseEnvMapShader
@@ -473,41 +566,41 @@ public:
class Gaussian6HBlurShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static void init();
static void init();
};
class Gaussian3HBlurShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static void init();
static void init();
};
class Gaussian6VBlurShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static void init();
static void init();
};
class Gaussian3VBlurShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex, uniform_pixel;
static GLuint vao;
static void init();
static void init();
};
class PenumbraHShader
@@ -546,44 +639,44 @@ public:
class PassThroughShader
{
public:
static GLuint Program;
static GLuint uniform_texture;
static GLuint vao;
static GLuint Program;
static GLuint uniform_texture;
static GLuint vao;
static void init();
static void init();
};
class GlowShader
{
public:
static GLuint Program;
static GLuint uniform_tex;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex;
static GLuint vao;
static void init();
static void init();
};
class SSAOShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
static GLuint vao;
static float SSAOSamples[64];
static void init();
static void setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
static GLuint vao;
static float SSAOSamples[64];
static void init();
static void setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
};
class FogShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_ipvmat;
static GLuint vao;
static GLuint Program;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_ipvmat;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
static void init();
static void setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
};
class MotionBlurShader
@@ -619,6 +712,52 @@ public:
static void setUniforms(const core::vector2df &sunpos, unsigned TU_tex);
};
class LogLuminanceShader
{
public:
static GLuint Program;
static GLuint uniform_tex;
static GLuint vao;
static void init();
static void setUniforms(unsigned TU_tex);
};
class MLAAColorEdgeDetectionSHader
{
public:
static GLuint Program;
static GLuint uniform_colorMapG, uniform_PIXEL_SIZE;
static GLuint vao;
static void init();
static void setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colorMapG);
};
class MLAABlendWeightSHader
{
public:
static GLuint Program;
static GLuint uniform_PIXEL_SIZE, uniform_edgesMap, uniform_areaMap;
static GLuint vao;
static void init();
static void setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_edgesMap, unsigned TU_areaMap);
};
class MLAAGatherSHader
{
public:
static GLuint Program;
static GLuint uniform_PIXEL_SIZE, uniform_colorMap, uniform_blendMap;
static GLuint vao;
static void init();
static void setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colormap, unsigned TU_blendmap);
};
}
namespace UIShader
@@ -626,38 +765,50 @@ namespace UIShader
class TextureRectShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_tex, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint vao;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_tex, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex);
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex);
};
class UniformColoredTextureRectShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_tex, uniform_color, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, const video::SColor &color, unsigned TU_tex);
};
class ColoredTextureRectShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_tex, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint colorvbo;
static GLuint vao;
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_tex, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint colorvbo;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex);
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex);
};
class ColoredRectShader
{
public:
static GLuint Program;
static GLuint attrib_position;
static GLuint uniform_center, uniform_size, uniform_color;
static GLuint vao;
static GLuint Program;
static GLuint attrib_position;
static GLuint uniform_center, uniform_size, uniform_color;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color);
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color);
};
}
@@ -678,7 +829,7 @@ public:
ACT(ES_GAUSSIAN3V) \
ACT(ES_MIPVIZ) \
ACT(ES_COLORIZE) \
ACT(ES_OBJECT_UNLIT) \
ACT(ES_OBJECT_UNLIT) \
ACT(ES_OBJECTPASS) \
ACT(ES_OBJECTPASS_REF) \
ACT(ES_SUNLIGHT) \

View File

@@ -16,18 +16,42 @@ const core::vector3df& rotation,
const core::vector3df& scale) :
CAnimatedMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
{
firstTime = true;
firstTime = true;
}
void STKAnimatedMesh::cleanGLMeshes()
{
for (u32 i = 0; i < GLmeshes.size(); ++i)
{
GLMesh mesh = GLmeshes[i];
if (!mesh.vertex_buffer)
continue;
if (mesh.vao_first_pass)
glDeleteVertexArrays(1, &(mesh.vao_first_pass));
if (mesh.vao_second_pass)
glDeleteVertexArrays(1, &(mesh.vao_second_pass));
if (mesh.vao_glow_pass)
glDeleteVertexArrays(1, &(mesh.vao_glow_pass));
if (mesh.vao_displace_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_pass));
if (mesh.vao_displace_mask_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass));
if (mesh.vao_shadow_pass)
glDeleteVertexArrays(1, &(mesh.vao_shadow_pass));
glDeleteBuffers(1, &(mesh.vertex_buffer));
glDeleteBuffers(1, &(mesh.index_buffer));
}
}
void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh)
{
firstTime = true;
GLmeshes.clear();
firstTime = true;
GLmeshes.clear();
for (unsigned i = 0; i < FPSM_COUNT; i++)
GeometricMesh[i].clear();
for (unsigned i = 0; i < SM_COUNT; i++)
ShadedMesh[i].clear();
CAnimatedMeshSceneNode::setMesh(mesh);
CAnimatedMeshSceneNode::setMesh(mesh);
}
void STKAnimatedMesh::drawSolidPass1(const GLMesh &mesh, GeometricMaterial type)
@@ -73,26 +97,26 @@ void STKAnimatedMesh::drawSolidPass2(const GLMesh &mesh, ShadedMaterial type)
void STKAnimatedMesh::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
video::IVideoDriver* driver = SceneManager->getVideoDriver();
bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
++PassCount;
++PassCount;
scene::IMesh* m = getMeshForCurrentFrame();
scene::IMesh* m = getMeshForCurrentFrame();
if (m)
{
Box = m->getBoundingBox();
}
else
{
Log::error("animated mesh", "Animated Mesh returned no mesh to render.");
return;
}
if (m)
{
Box = m->getBoundingBox();
}
else
{
Log::error("animated mesh", "Animated Mesh returned no mesh to render.");
return;
}
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
if (firstTime)
{
@@ -133,7 +157,7 @@ void STKAnimatedMesh::render()
}
}
}
firstTime = false;
firstTime = false;
for (u32 i = 0; i<m->getMeshBufferCount(); ++i)
{

View File

@@ -10,14 +10,15 @@
class STKAnimatedMesh : public irr::scene::CAnimatedMeshSceneNode
{
protected:
bool firstTime;
bool firstTime;
std::vector<GLMesh *> GeometricMesh[FPSM_COUNT];
std::vector<GLMesh *> ShadedMesh[SM_COUNT];
std::vector<GLMesh *> TransparentMesh[TM_COUNT];
std::vector<GLMesh> GLmeshes;
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
void drawSolidPass1(const GLMesh &mesh, GeometricMaterial type);
void drawSolidPass2(const GLMesh &mesh, ShadedMaterial type);
void cleanGLMeshes();
public:
STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent,
irr::scene::ISceneManager* mgr, irr::s32 id,

View File

@@ -9,36 +9,38 @@ static GLuint billboardvao = 0;
static void createbillboardvao()
{
glGenVertexArrays(1, &billboardvao);
glBindVertexArray(billboardvao);
glGenVertexArrays(1, &billboardvao);
glBindVertexArray(billboardvao);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::billboardvbo);
glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_corner);
glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_texcoord);
glVertexAttribPointer(MeshShader::BillboardShader::attrib_corner, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(MeshShader::BillboardShader::attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*) (2 * sizeof(float)));
glBindVertexArray(0);
glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_corner);
glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_texcoord);
glVertexAttribPointer(MeshShader::BillboardShader::attrib_corner, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(MeshShader::BillboardShader::attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*) (2 * sizeof(float)));
glBindVertexArray(0);
}
STKBillboard::STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop, irr::video::SColor colorBottom) :
CBillboardSceneNode(parent, mgr, id, position, size, colorTop, colorBottom), IBillboardSceneNode(parent, mgr, id, position)
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop, irr::video::SColor colorBottom) :
CBillboardSceneNode(parent, mgr, id, position, size, colorTop, colorBottom), IBillboardSceneNode(parent, mgr, id, position)
{
if (!billboardvao)
createbillboardvao();
if (!billboardvao)
createbillboardvao();
}
void STKBillboard::render()
{
if (irr_driver->getPhase() != TRANSPARENT_PASS)
return;
core::vector3df pos = getAbsolutePosition();
glBindVertexArray(billboardvao);
GLuint texid = getTextureGLuint(Material.getTexture(0));
setTexture(0, texid, GL_LINEAR, GL_LINEAR);
glUseProgram(MeshShader::BillboardShader::Program);
MeshShader::BillboardShader::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
return;
core::vector3df pos = getAbsolutePosition();
glBindVertexArray(billboardvao);
video::ITexture *tex = Material.getTexture(0);
transformTexturesTosRGB(tex);
GLuint texid = getTextureGLuint(tex);
setTexture(0, texid, GL_LINEAR, GL_LINEAR);
glUseProgram(MeshShader::BillboardShader::Program);
MeshShader::BillboardShader::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
return;
}

View File

@@ -8,12 +8,12 @@
class STKBillboard : public irr::scene::CBillboardSceneNode
{
public:
STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop = irr::video::SColor(0xFFFFFFFF),
irr::video::SColor colorBottom = irr::video::SColor(0xFFFFFFFF));
STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop = irr::video::SColor(0xFFFFFFFF),
irr::video::SColor colorBottom = irr::video::SColor(0xFFFFFFFF));
virtual void render();
virtual void render();
};
#endif
#endif

View File

@@ -0,0 +1,360 @@
#include "stkinstancedscenenode.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/callbacks.hpp"
STKInstancedSceneNode::STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position,
const irr::core::vector3df& rotation,
const irr::core::vector3df& scale) :
CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
{
createGLMeshes();
setAutomaticCulling(0);
}
void STKInstancedSceneNode::cleanGL()
{
for (u32 i = 0; i < GLmeshes.size(); ++i)
{
GLMesh mesh = GLmeshes[i];
if (!mesh.vertex_buffer)
continue;
if (mesh.vao_first_pass)
glDeleteVertexArrays(1, &(mesh.vao_first_pass));
if (mesh.vao_second_pass)
glDeleteVertexArrays(1, &(mesh.vao_second_pass));
if (mesh.vao_glow_pass)
glDeleteVertexArrays(1, &(mesh.vao_glow_pass));
if (mesh.vao_displace_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_pass));
if (mesh.vao_displace_mask_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass));
if (mesh.vao_shadow_pass)
glDeleteVertexArrays(1, &(mesh.vao_shadow_pass));
glDeleteBuffers(1, &(mesh.vertex_buffer));
glDeleteBuffers(1, &(mesh.index_buffer));
}
glDeleteBuffers(1, &instances_vbo);
}
STKInstancedSceneNode::~STKInstancedSceneNode()
{
cleanGL();
}
void STKInstancedSceneNode::createGLMeshes()
{
for (u32 i = 0; i<Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
GLmeshes.push_back(allocateMeshBuffer(mb));
}
isMaterialInitialized = false;
}
template<typename T>
void setInstanceAttribPointer()
{
glEnableVertexAttribArray(T::attrib_origin);
glVertexAttribPointer(T::attrib_origin, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 0);
glVertexAttribDivisor(T::attrib_origin, 1);
glEnableVertexAttribArray(T::attrib_orientation);
glVertexAttribPointer(T::attrib_orientation, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(3 * sizeof(float)));
glVertexAttribDivisor(T::attrib_orientation, 1);
glEnableVertexAttribArray(T::attrib_scale);
glVertexAttribPointer(T::attrib_scale, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(6 * sizeof(float)));
glVertexAttribDivisor(T::attrib_scale, 1);
}
void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat)
{
switch (GeoMat)
{
case FPSM_DEFAULT:
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::InstancedObjectPass1Shader::attrib_position, -1, -1, MeshShader::InstancedObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
glGenBuffers(1, &instances_vbo);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
setInstanceAttribPointer<MeshShader::InstancedObjectPass1Shader>();
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::InstancedShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
setInstanceAttribPointer<MeshShader::InstancedShadowShader>();
break;
case FPSM_ALPHA_REF_TEXTURE:
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::InstancedObjectRefPass1Shader::attrib_position, MeshShader::InstancedObjectRefPass1Shader::attrib_texcoord, -1, MeshShader::InstancedObjectRefPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
glGenBuffers(1, &instances_vbo);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
setInstanceAttribPointer<MeshShader::InstancedObjectRefPass1Shader>();
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::InstancedRefShadowShader::attrib_position, MeshShader::InstancedRefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
setInstanceAttribPointer<MeshShader::InstancedRefShadowShader>();
break;
case FPSM_GRASS:
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::InstancedGrassPass1Shader::attrib_position, MeshShader::InstancedGrassPass1Shader::attrib_texcoord, -1, MeshShader::InstancedGrassPass1Shader::attrib_normal, -1, -1, MeshShader::InstancedGrassPass1Shader::attrib_color, mesh.Stride);
glGenBuffers(1, &instances_vbo);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
setInstanceAttribPointer<MeshShader::InstancedGrassPass1Shader>();
break;
default:
return;
}
switch (ShadedMat)
{
case SM_DEFAULT:
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::InstancedObjectPass2Shader::attrib_position, MeshShader::InstancedObjectPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
setInstanceAttribPointer<MeshShader::InstancedObjectPass2Shader>();
break;
case SM_ALPHA_REF_TEXTURE:
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::InstancedObjectRefPass2Shader::attrib_position, MeshShader::InstancedObjectRefPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
setInstanceAttribPointer<MeshShader::InstancedObjectRefPass2Shader>();
break;
case SM_GRASS:
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::InstancedGrassPass2Shader::attrib_position, MeshShader::InstancedGrassPass2Shader::attrib_texcoord, -1, MeshShader::InstancedGrassPass2Shader::attrib_normal, -1, -1, MeshShader::InstancedGrassPass2Shader::attrib_color, mesh.Stride);
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
setInstanceAttribPointer<MeshShader::InstancedGrassPass2Shader>();
break;
default:
return;
}
glBindVertexArray(0);
}
void STKInstancedSceneNode::setFirstTimeMaterial()
{
if (isMaterialInitialized)
return;
for (u32 i = 0; i<Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
GLMesh &mesh = GLmeshes[i];
GeometricMaterial GeometricType = MaterialTypeToGeometricMaterial(type);
ShadedMaterial ShadedType = MaterialTypeToShadedMaterial(type, mesh.textures);
initinstancedvaostate(mesh, GeometricType, ShadedType);
if (mesh.vao_first_pass)
GeometricMesh[GeometricType].push_back(&mesh);
if (mesh.vao_second_pass)
ShadedMesh[ShadedType].push_back(&mesh);
}
isMaterialInitialized = true;
}
void STKInstancedSceneNode::addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale)
{
instance_pos.push_back(origin.X);
instance_pos.push_back(origin.Y);
instance_pos.push_back(origin.Z);
instance_pos.push_back(orientation.X);
instance_pos.push_back(orientation.Y);
instance_pos.push_back(orientation.Z);
instance_pos.push_back(scale.X);
instance_pos.push_back(scale.Y);
instance_pos.push_back(scale.Z);
}
static void drawFSPMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
core::matrix4 InverseViewMatrix;
irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW).getInverse(InverseViewMatrix);
MeshShader::InstancedObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, InverseViewMatrix);
glBindVertexArray(mesh.vao_first_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawShadowDefault(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
std::vector<core::matrix4> ShadowMVP(irr_driver->getShadowViewProj());
MeshShader::InstancedShadowShader::setUniforms(ShadowMVP);
assert(mesh.vao_shadow_pass);
glBindVertexArray(mesh.vao_shadow_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawFSPMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
core::matrix4 InverseViewMatrix;
irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW).getInverse(InverseViewMatrix);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, InverseViewMatrix, 0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawShadowAlphaRefTexture(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
std::vector<core::matrix4> ShadowMVP(irr_driver->getShadowViewProj());
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedRefShadowShader::setUniforms(ShadowMVP, 0);
assert(mesh.vao_shadow_pass);
glBindVertexArray(mesh.vao_shadow_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawFSPMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDir, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
core::matrix4 InverseViewMatrix;
irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW).getInverse(InverseViewMatrix);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedGrassPass1Shader::setUniforms(ModelViewProjectionMatrix, InverseViewMatrix, windDir, 0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawSMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(MeshShader::InstancedObjectPass2Shader::TU_Albedo, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
glBindVertexArray(mesh.vao_second_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawSMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(MeshShader::InstancedObjectRefPass2Shader::TU_Albedo, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
glBindVertexArray(mesh.vao_second_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawSMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDir, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(MeshShader::InstancedGrassPass2Shader::TU_Albedo, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::InstancedGrassPass2Shader::TU_dtex, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST);
SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT);
MeshShader::InstancedGrassPass2Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), irr_driver->getInvProjMatrix(), windDir, cb->getPosition());
glBindVertexArray(mesh.vao_second_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
void STKInstancedSceneNode::render()
{
setFirstTimeMaterial();
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
{
ModelViewProjectionMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION);
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
if (!GeometricMesh[FPSM_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++)
drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::InstancedObjectRefPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
windDir = getWind();
if (!GeometricMesh[FPSM_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++)
drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], ModelViewProjectionMatrix, windDir, instance_pos.size() / 9);
return;
}
if (irr_driver->getPhase() == SOLID_LIT_PASS)
{
if (!ShadedMesh[SM_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[FPSM_DEFAULT].size(); i++)
drawSMDefault(*ShadedMesh[FPSM_DEFAULT][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::InstancedObjectRefPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++)
drawSMAlphaRefTexture(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
if (!ShadedMesh[SM_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_GRASS].size(); i++)
drawSMGrass(*ShadedMesh[SM_GRASS][i], ModelViewProjectionMatrix, windDir, instance_pos.size() / 9);
return;
}
if (irr_driver->getPhase() == SHADOW_PASS)
{
if (!GeometricMesh[FPSM_DEFAULT].empty())
glUseProgram(MeshShader::InstancedShadowShader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++)
drawShadowDefault(*GeometricMesh[FPSM_DEFAULT][i], instance_pos.size() / 9);
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::InstancedRefShadowShader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawShadowAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9);
return;
}
}

View File

@@ -0,0 +1,31 @@
#ifndef STKINSTANCEDSCENENODE_HPP
#define STKINSTANCEDSCENENODE_HPP
#include "stkmesh.hpp"
class STKInstancedSceneNode : public irr::scene::CMeshSceneNode
{
protected:
std::vector<GLMesh *> GeometricMesh[FPSM_COUNT];
std::vector<GLMesh *> ShadedMesh[SM_COUNT];
std::vector<GLMesh> GLmeshes;
std::vector<float> instance_pos;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
GLuint instances_vbo;
void createGLMeshes();
bool isMaterialInitialized;
void setFirstTimeMaterial();
void initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat);
void cleanGL();
core::vector3df windDir;
public:
STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0),
const irr::core::vector3df& rotation = irr::core::vector3df(0, 0, 0),
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f));
~STKInstancedSceneNode();
virtual void render();
void addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale);
};
#endif

View File

@@ -102,7 +102,6 @@ GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_t
glVertexAttribPointer(attrib_color, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, (GLvoid*)24);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx);
glBindVertexArray(0);
return vao;
}
@@ -181,8 +180,11 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb)
for (unsigned i = 0; i < 6; i++)
{
tex = mb->getMaterial().getTexture(i);
if (tex)
result.textures[i] = getTextureGLuint(tex);
if (tex)
{
transformTexturesTosRGB(tex);
result.textures[i] = getTextureGLuint(tex);
}
else
result.textures[i] = 0;
}
@@ -206,6 +208,16 @@ void computeTIMV(core::matrix4 &TransposeInverseModelView)
TransposeInverseModelView = TransposeInverseModelView.getTransposed();
}
core::vector3df getWind()
{
const core::vector3df pos = irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD).getTranslation();
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
GrassShaderProvider *gsp = (GrassShaderProvider *)irr_driver->getCallback(ES_GRASS);
float m_speed = gsp->getSpeed(), m_amplitude = gsp->getAmplitude();
return m_speed * vector3df(1., 0., 0.) * cos(time);
}
void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
irr_driver->IncreaseObjectCount();
@@ -654,11 +666,9 @@ void drawShadowRef(const GLMesh &mesh)
size_t count = mesh.IndexCount;
std::vector<core::matrix4> ShadowMVP(irr_driver->getShadowViewProj());
for (unsigned i = 0; i < ShadowMVP.size(); i++)
ShadowMVP[i] *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::RefShadowShader::setUniforms(ShadowMVP, 0);
MeshShader::RefShadowShader::setUniforms(irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD), ShadowMVP, 0);
assert(mesh.vao_shadow_pass);
glBindVertexArray(mesh.vao_shadow_pass);
@@ -673,8 +683,6 @@ void drawShadow(const GLMesh &mesh)
size_t count = mesh.IndexCount;
std::vector<core::matrix4> ShadowMVP(irr_driver->getShadowViewProj());
for (unsigned i = 0; i < ShadowMVP.size(); i++)
ShadowMVP[i] *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
/* if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
{
@@ -683,7 +691,7 @@ void drawShadow(const GLMesh &mesh)
MeshShader::GrassShadowShader::setUniforms(ShadowMVP, windDir, 0);
}*/
MeshShader::ShadowShader::setUniforms(ShadowMVP);
MeshShader::ShadowShader::setUniforms(irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD), ShadowMVP);
assert(mesh.vao_shadow_pass);
glBindVertexArray(mesh.vao_shadow_pass);

View File

@@ -40,19 +40,19 @@ enum TransparentMaterial
};
struct GLMesh {
GLuint vao_first_pass;
GLuint vao_second_pass;
GLuint vao_glow_pass;
GLuint vao_displace_pass;
GLuint vao_first_pass;
GLuint vao_second_pass;
GLuint vao_glow_pass;
GLuint vao_displace_pass;
GLuint vao_displace_mask_pass;
GLuint vao_shadow_pass;
GLuint vertex_buffer;
GLuint index_buffer;
GLuint textures[6];
GLenum PrimitiveType;
GLenum IndexType;
size_t IndexCount;
size_t Stride;
GLuint vertex_buffer;
GLuint index_buffer;
GLuint textures[6];
GLenum PrimitiveType;
GLenum IndexType;
size_t IndexCount;
size_t Stride;
core::matrix4 TextureMatrix;
};
@@ -64,6 +64,8 @@ void computeMVP(core::matrix4 &ModelViewProjectionMatrix);
void computeTIMV(core::matrix4 &TransposeInverseModelView);
bool isObject(video::E_MATERIAL_TYPE type);
core::vector3df getWind();
// Pass 1 shader (ie shaders that outputs normals and depth)
void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);

View File

@@ -10,22 +10,6 @@
#include "graphics/camera.hpp"
#include "modes/world.hpp"
static
core::vector3df getWind()
{
const core::vector3df pos = irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD).getTranslation();
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
GrassShaderProvider *gsp = (GrassShaderProvider *)irr_driver->getCallback(ES_GRASS);
float m_speed = gsp->getSpeed(), m_amplitude = gsp->getAmplitude();
float strength = (pos.X + pos.Y + pos.Z) * 1.2f + time * m_speed;
strength = noise2d(strength / 10.0f) * m_amplitude * 5;
// * 5 is to work with the existing amplitude values.
// Pre-multiply on the cpu
return irr_driver->getWind() * strength;
}
STKMeshSceneNode::STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position,
const irr::core::vector3df& rotation,
@@ -105,6 +89,10 @@ void STKMeshSceneNode::cleanGLMeshes()
glDeleteVertexArrays(1, &(mesh.vao_glow_pass));
if (mesh.vao_displace_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_pass));
if (mesh.vao_displace_mask_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass));
if (mesh.vao_shadow_pass)
glDeleteVertexArrays(1, &(mesh.vao_shadow_pass));
glDeleteBuffers(1, &(mesh.vertex_buffer));
glDeleteBuffers(1, &(mesh.index_buffer));
}

View File

@@ -24,14 +24,14 @@ using core::vector3df;
class Wind
{
public:
Wind();
Wind();
vector3df getWind() const;
void update();
vector3df getWind() const;
void update();
private:
vector3df m_wind;
float m_seed;
vector3df m_wind;
float m_seed;
};
#endif

View File

@@ -795,7 +795,7 @@ namespace GUIEngine
return Private::small_font_height;
} // getSmallFontHeight
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
int getLargeFontHeight()
{

View File

@@ -89,7 +89,7 @@ void ModalDialog::doInit()
pointer_was_shown = irr_driver->isPointerShown();
irr_driver->showPointer();
const core::dimension2d<u32>& frame_size =
const core::dimension2d<u32>& frame_size =
GUIEngine::getDriver()->getCurrentRenderTargetSize();
const int w = (int)(frame_size.Width* m_percent_width);
@@ -131,7 +131,7 @@ void ModalDialog::doInit()
}
modalWindow = this;
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area,
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area,
true /* modal */);
GUIEngine::getSkin()->m_dialog = true;

View File

@@ -856,7 +856,7 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect,
int step = ratingBar->getStepsOfStar(i);
const core::recti source_area(texture_w * step, 0,
const core::recti source_area(texture_w * step, 0,
texture_w * (step + 1), texture_h);
draw2DImage(texture,
@@ -2097,7 +2097,7 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor,
core::recti innerArea = borderArea;
innerArea.UpperLeftCorner += position2d< s32 >( 3, 3 );
innerArea.LowerRightCorner -= position2d< s32 >( 3, 3 );
GL32_draw2DRectangle(focused ? bg_color_focused : bg_color, innerArea);
GL32_draw2DRectangle(focused ? bg_color_focused : bg_color, innerArea);
return;
}
else if (type == WTYPE_LIST)
@@ -2161,7 +2161,7 @@ void Skin::drawBGFadeColor()
SColor color = SkinConfig::m_colors["dialog_background::neutral"];
if (m_dialog_size < 1.0f)
color.setAlpha( (unsigned int)(color.getAlpha()*m_dialog_size ));
GL32_draw2DRectangle(color,
GL32_draw2DRectangle(color,
core::recti(position2d< s32 >(0,0),
GUIEngine::getDriver()->getCurrentRenderTargetSize()) );
} // drawBGFadeColor
@@ -2211,7 +2211,7 @@ void Skin::draw3DMenuPane (IGUIElement *element, const core::recti &rect,
const core::recti *clip)
{
SColor color = SColor(150, 96, 74, 196);
GL32_draw2DRectangle(color, rect);
GL32_draw2DRectangle(color, rect);
} // draw3DMenuPane
// -----------------------------------------------------------------------------

View File

@@ -16,155 +16,155 @@
using namespace irr;
using namespace gui;
class CGUIEditBox : public IGUIEditBox
{
public:
class CGUIEditBox : public IGUIEditBox
{
public:
LEAK_CHECK()
//! constructor
CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle, bool is_rtl);
//! constructor
CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle, bool is_rtl);
//! destructor
virtual ~CGUIEditBox();
//! destructor
virtual ~CGUIEditBox();
//! Sets another skin independent font.
virtual void setOverrideFont(IGUIFont* font=0);
//! Sets another skin independent font.
virtual void setOverrideFont(IGUIFont* font=0);
//! Sets another color for the text.
virtual void setOverrideColor(video::SColor color);
//! Sets another color for the text.
virtual void setOverrideColor(video::SColor color);
//! Gets the override color
virtual video::SColor getOverrideColor() const;
//! Gets the override color
virtual video::SColor getOverrideColor() const;
//! Sets if the text should use the overide color or the
//! color in the gui skin.
virtual void enableOverrideColor(bool enable);
//! Sets if the text should use the overide color or the
//! color in the gui skin.
virtual void enableOverrideColor(bool enable);
//! Checks if an override color is enabled
/** \return true if the override color is enabled, false otherwise */
virtual bool isOverrideColorEnabled(void) const;
//! Checks if an override color is enabled
/** \return true if the override color is enabled, false otherwise */
virtual bool isOverrideColorEnabled(void) const;
//! Turns the border on or off
virtual void setDrawBorder(bool border);
//! Turns the border on or off
virtual void setDrawBorder(bool border);
//! Enables or disables word wrap for using the edit box as multiline text editor.
virtual void setWordWrap(bool enable);
//! Enables or disables word wrap for using the edit box as multiline text editor.
virtual void setWordWrap(bool enable);
//! Checks if word wrap is enabled
//! \return true if word wrap is enabled, false otherwise
virtual bool isWordWrapEnabled() const;
//! Checks if word wrap is enabled
//! \return true if word wrap is enabled, false otherwise
virtual bool isWordWrapEnabled() const;
//! Enables or disables newlines.
/** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
instead a newline character will be inserted. */
virtual void setMultiLine(bool enable);
//! Enables or disables newlines.
/** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
instead a newline character will be inserted. */
virtual void setMultiLine(bool enable);
//! Checks if multi line editing is enabled
//! \return true if mult-line is enabled, false otherwise
virtual bool isMultiLineEnabled() const;
//! Checks if multi line editing is enabled
//! \return true if mult-line is enabled, false otherwise
virtual bool isMultiLineEnabled() const;
//! Enables or disables automatic scrolling with cursor position
//! \param enable: If set to true, the text will move around with the cursor position
virtual void setAutoScroll(bool enable);
//! Enables or disables automatic scrolling with cursor position
//! \param enable: If set to true, the text will move around with the cursor position
virtual void setAutoScroll(bool enable);
//! Checks to see if automatic scrolling is enabled
//! \return true if automatic scrolling is enabled, false if not
virtual bool isAutoScrollEnabled() const;
//! Checks to see if automatic scrolling is enabled
//! \return true if automatic scrolling is enabled, false if not
virtual bool isAutoScrollEnabled() const;
//! Gets the size area of the text in the edit box
//! \return Returns the size in pixels of the text
virtual core::dimension2du getTextDimension();
//! Gets the size area of the text in the edit box
//! \return Returns the size in pixels of the text
virtual core::dimension2du getTextDimension();
//! Sets text justification
virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
//! Sets text justification
virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! draws the element and its children
virtual void draw();
//! Sets the new caption of this element.
virtual void setText(const wchar_t* text);
//! Sets the new caption of this element.
virtual void setText(const wchar_t* text);
//! Sets the maximum amount of characters which may be entered in the box.
//! \param max: Maximum amount of characters. If 0, the character amount is
//! infinity.
virtual void setMax(u32 max);
//! Sets the maximum amount of characters which may be entered in the box.
//! \param max: Maximum amount of characters. If 0, the character amount is
//! infinity.
virtual void setMax(u32 max);
//! Returns maximum amount of characters, previously set by setMax();
virtual u32 getMax() const;
//! Returns maximum amount of characters, previously set by setMax();
virtual u32 getMax() const;
//! Sets whether the edit box is a password box. Setting this to true will
/** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
\param passwordBox: true to enable password, false to disable
\param passwordChar: the character that is displayed instead of letters */
virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
//! Sets whether the edit box is a password box. Setting this to true will
/** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
\param passwordBox: true to enable password, false to disable
\param passwordChar: the character that is displayed instead of letters */
virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
//! Returns true if the edit box is currently a password box.
virtual bool isPasswordBox() const;
//! Returns true if the edit box is currently a password box.
virtual bool isPasswordBox() const;
//! Updates the absolute position, splits text if required
virtual void updateAbsolutePosition();
//! Updates the absolute position, splits text if required
virtual void updateAbsolutePosition();
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
virtual irr::gui::IGUIFont* getOverrideFont() const { return NULL; }
virtual irr::gui::IGUIFont* getActiveFont() const { return NULL; }
virtual void setDrawBackground(bool) { }
protected:
//! Breaks the single text line.
void breakText();
//! sets the area of the given line
void setTextRect(s32 line);
//! returns the line number that the cursor is on
s32 getLineFromPos(s32 pos);
//! adds a letter to the edit box
void inputChar(wchar_t c);
//! calculates the current scroll position
void calculateScrollPos();
//! send some gui event to parent
void sendGuiEvent(EGUI_EVENT_TYPE type);
//! set text markers
void setTextMarkers(s32 begin, s32 end);
protected:
//! Breaks the single text line.
void breakText();
//! sets the area of the given line
void setTextRect(s32 line);
//! returns the line number that the cursor is on
s32 getLineFromPos(s32 pos);
//! adds a letter to the edit box
void inputChar(wchar_t c);
//! calculates the current scroll position
void calculateScrollPos();
//! send some gui event to parent
void sendGuiEvent(EGUI_EVENT_TYPE type);
//! set text markers
void setTextMarkers(s32 begin, s32 end);
bool processKey(const SEvent& event);
bool processMouse(const SEvent& event);
s32 getCursorPos(s32 x, s32 y);
bool processKey(const SEvent& event);
bool processMouse(const SEvent& event);
s32 getCursorPos(s32 x, s32 y);
bool MouseMarking;
bool Border;
bool OverrideColorEnabled;
s32 MarkBegin;
s32 MarkEnd;
bool MouseMarking;
bool Border;
bool OverrideColorEnabled;
s32 MarkBegin;
s32 MarkEnd;
video::SColor OverrideColor;
gui::IGUIFont *OverrideFont, *LastBreakFont;
IOSOperator* Operator;
video::SColor OverrideColor;
gui::IGUIFont *OverrideFont, *LastBreakFont;
IOSOperator* Operator;
StkTime::TimeType BlinkStartTime;
s32 CursorPos;
s32 HScrollPos, VScrollPos; // scroll position in characters
u32 Max;
s32 CursorPos;
s32 HScrollPos, VScrollPos; // scroll position in characters
u32 Max;
bool m_rtl;
bool WordWrap, MultiLine, AutoScroll, PasswordBox;
wchar_t PasswordChar;
EGUI_ALIGNMENT HAlign, VAlign;
bool WordWrap, MultiLine, AutoScroll, PasswordBox;
wchar_t PasswordChar;
EGUI_ALIGNMENT HAlign, VAlign;
core::array< core::stringw > BrokenText;
core::array< s32 > BrokenTextPositions;
core::array< core::stringw > BrokenText;
core::array< s32 > BrokenTextPositions;
core::rect<s32> CurrentTextRect, FrameRect; // temporary values
};
core::rect<s32> CurrentTextRect, FrameRect; // temporary values
};

View File

@@ -21,59 +21,59 @@ namespace gui
//! constructor
CGUISTKListBox::CGUISTKListBox(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool clip,
bool drawBack, bool moveOverSelect)
s32 id, core::rect<s32> rectangle, bool clip,
bool drawBack, bool moveOverSelect)
: IGUIElement(EGUIET_LIST_BOX, environment, parent, id, rectangle), Selected(-1),
ItemHeight(0),ItemHeightOverride(0),
TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0),
ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack),
MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true)
ItemHeight(0),ItemHeightOverride(0),
TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0),
ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack),
MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true)
{
#ifdef _DEBUG
setDebugName("CGUISTKListBox");
#endif
#ifdef _DEBUG
setDebugName("CGUISTKListBox");
#endif
IGUISkin* skin = Environment->getSkin();
const s32 s = skin->getSize(EGDS_SCROLLBAR_SIZE);
IGUISkin* skin = Environment->getSkin();
const s32 s = skin->getSize(EGDS_SCROLLBAR_SIZE);
ScrollBar = Environment->addScrollBar(false,
core::rect<s32>(RelativeRect.getWidth() - s, 0,
ScrollBar = Environment->addScrollBar(false,
core::rect<s32>(RelativeRect.getWidth() - s, 0,
RelativeRect.getWidth(), RelativeRect.getHeight()), this, -1);
ScrollBar->grab();
ScrollBar->setSubElement(true);
ScrollBar->setTabStop(false);
ScrollBar->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
ScrollBar->setVisible(false);
ScrollBar->setPos(0);
ScrollBar->setSubElement(true);
ScrollBar->setTabStop(false);
ScrollBar->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
ScrollBar->setVisible(false);
ScrollBar->setPos(0);
setNotClipped(!clip);
setNotClipped(!clip);
// this element can be tabbed to
setTabStop(true);
setTabOrder(-1);
// this element can be tabbed to
setTabStop(true);
setTabOrder(-1);
updateAbsolutePosition();
updateAbsolutePosition();
}
//! destructor
CGUISTKListBox::~CGUISTKListBox()
{
if (ScrollBar)
ScrollBar->drop();
if (ScrollBar)
ScrollBar->drop();
if (Font)
Font->drop();
if (Font)
Font->drop();
if (IconBank)
IconBank->drop();
if (IconBank)
IconBank->drop();
}
//! returns amount of list items
u32 CGUISTKListBox::getItemCount() const
{
return Items.size();
return Items.size();
}
@@ -84,7 +84,7 @@ const wchar_t* CGUISTKListBox::getCellText(u32 row_num, u32 col_num) const
return 0;
if ( col_num >= Items[row_num].m_contents.size() )
return 0;
return Items[row_num].m_contents[col_num].m_text.c_str();
return Items[row_num].m_contents[col_num].m_text.c_str();
}
CGUISTKListBox::ListItem CGUISTKListBox::getItem(u32 id) const
@@ -105,109 +105,109 @@ s32 CGUISTKListBox::getIcon(u32 row_num, u32 col_num) const
void CGUISTKListBox::removeItem(u32 id)
{
if (id >= Items.size())
return;
if (id >= Items.size())
return;
if ((u32)Selected==id)
{
Selected = -1;
}
else if ((u32)Selected > id)
{
Selected -= 1;
selectTime = (u32)StkTime::getTimeSinceEpoch();
}
if ((u32)Selected==id)
{
Selected = -1;
}
else if ((u32)Selected > id)
{
Selected -= 1;
selectTime = (u32)StkTime::getTimeSinceEpoch();
}
Items.erase(id);
Items.erase(id);
recalculateItemHeight();
recalculateItemHeight();
}
s32 CGUISTKListBox::getItemAt(s32 xpos, s32 ypos) const
{
if ( xpos < AbsoluteRect.UpperLeftCorner.X || xpos >= AbsoluteRect.LowerRightCorner.X
|| ypos < AbsoluteRect.UpperLeftCorner.Y || ypos >= AbsoluteRect.LowerRightCorner.Y
)
return -1;
if ( xpos < AbsoluteRect.UpperLeftCorner.X || xpos >= AbsoluteRect.LowerRightCorner.X
|| ypos < AbsoluteRect.UpperLeftCorner.Y || ypos >= AbsoluteRect.LowerRightCorner.Y
)
return -1;
if ( ItemHeight == 0 )
return -1;
if ( ItemHeight == 0 )
return -1;
s32 item = ((ypos - AbsoluteRect.UpperLeftCorner.Y - 1) + ScrollBar->getPos()) / ItemHeight;
if ( item < 0 || item >= (s32)Items.size())
return -1;
s32 item = ((ypos - AbsoluteRect.UpperLeftCorner.Y - 1) + ScrollBar->getPos()) / ItemHeight;
if ( item < 0 || item >= (s32)Items.size())
return -1;
return item;
return item;
}
//! clears the list
void CGUISTKListBox::clear()
{
Items.clear();
ItemsIconWidth = 0;
Selected = -1;
Items.clear();
ItemsIconWidth = 0;
Selected = -1;
if (ScrollBar)
ScrollBar->setPos(0);
if (ScrollBar)
ScrollBar->setPos(0);
recalculateItemHeight();
recalculateItemHeight();
}
void CGUISTKListBox::recalculateItemHeight()
{
IGUISkin* skin = Environment->getSkin();
IGUISkin* skin = Environment->getSkin();
if (Font != skin->getFont())
{
if (Font)
Font->drop();
if (Font != skin->getFont())
{
if (Font)
Font->drop();
Font = skin->getFont();
if ( 0 == ItemHeightOverride )
ItemHeight = 0;
Font = skin->getFont();
if ( 0 == ItemHeightOverride )
ItemHeight = 0;
if (Font)
{
if ( 0 == ItemHeightOverride )
ItemHeight = Font->getDimension(L"A").Height + 4;
if (Font)
{
if ( 0 == ItemHeightOverride )
ItemHeight = Font->getDimension(L"A").Height + 4;
Font->grab();
}
}
Font->grab();
}
}
TotalItemHeight = ItemHeight * Items.size();
ScrollBar->setMax( core::max_(0, TotalItemHeight - AbsoluteRect.getHeight()) );
s32 minItemHeight = ItemHeight > 0 ? ItemHeight : 1;
ScrollBar->setSmallStep ( minItemHeight );
ScrollBar->setLargeStep ( 2*minItemHeight );
TotalItemHeight = ItemHeight * Items.size();
ScrollBar->setMax( core::max_(0, TotalItemHeight - AbsoluteRect.getHeight()) );
s32 minItemHeight = ItemHeight > 0 ? ItemHeight : 1;
ScrollBar->setSmallStep ( minItemHeight );
ScrollBar->setLargeStep ( 2*minItemHeight );
if ( TotalItemHeight <= AbsoluteRect.getHeight() )
ScrollBar->setVisible(false);
else
ScrollBar->setVisible(true);
if ( TotalItemHeight <= AbsoluteRect.getHeight() )
ScrollBar->setVisible(false);
else
ScrollBar->setVisible(true);
}
//! returns id of selected item. returns -1 if no item is selected.
s32 CGUISTKListBox::getSelected() const
{
return Selected;
return Selected;
}
//! sets the selected item. Set this to -1 if no item should be selected
void CGUISTKListBox::setSelected(s32 id)
{
if ((u32)id>=Items.size())
Selected = -1;
else
Selected = id;
if ((u32)id>=Items.size())
Selected = -1;
else
Selected = id;
selectTime = (u32)StkTime::getTimeSinceEpoch();
selectTime = (u32)StkTime::getTimeSinceEpoch();
recalculateScrollPos();
recalculateScrollPos();
}
s32 CGUISTKListBox::getRowByCellText(const wchar_t * text)
@@ -249,184 +249,184 @@ s32 CGUISTKListBox::getRowByInternalName(const std::string & text) const
//! called if an event happened.
bool CGUISTKListBox::OnEvent(const SEvent& event)
{
if (isEnabled())
{
switch(event.EventType)
{
case EET_KEY_INPUT_EVENT:
if (event.KeyInput.PressedDown &&
(event.KeyInput.Key == KEY_DOWN ||
event.KeyInput.Key == KEY_UP ||
event.KeyInput.Key == KEY_HOME ||
event.KeyInput.Key == KEY_END ||
event.KeyInput.Key == KEY_NEXT ||
event.KeyInput.Key == KEY_PRIOR ) )
{
s32 oldSelected = Selected;
switch (event.KeyInput.Key)
{
case KEY_DOWN:
Selected += 1;
break;
case KEY_UP:
Selected -= 1;
break;
case KEY_HOME:
Selected = 0;
break;
case KEY_END:
Selected = (s32)Items.size()-1;
break;
case KEY_NEXT:
Selected += AbsoluteRect.getHeight() / ItemHeight;
break;
case KEY_PRIOR:
Selected -= AbsoluteRect.getHeight() / ItemHeight;
break;
default:
break;
}
if (Selected >= (s32)Items.size())
Selected = Items.size() - 1;
else
if (Selected<0)
Selected = 0;
if (isEnabled())
{
switch(event.EventType)
{
case EET_KEY_INPUT_EVENT:
if (event.KeyInput.PressedDown &&
(event.KeyInput.Key == KEY_DOWN ||
event.KeyInput.Key == KEY_UP ||
event.KeyInput.Key == KEY_HOME ||
event.KeyInput.Key == KEY_END ||
event.KeyInput.Key == KEY_NEXT ||
event.KeyInput.Key == KEY_PRIOR ) )
{
s32 oldSelected = Selected;
switch (event.KeyInput.Key)
{
case KEY_DOWN:
Selected += 1;
break;
case KEY_UP:
Selected -= 1;
break;
case KEY_HOME:
Selected = 0;
break;
case KEY_END:
Selected = (s32)Items.size()-1;
break;
case KEY_NEXT:
Selected += AbsoluteRect.getHeight() / ItemHeight;
break;
case KEY_PRIOR:
Selected -= AbsoluteRect.getHeight() / ItemHeight;
break;
default:
break;
}
if (Selected >= (s32)Items.size())
Selected = Items.size() - 1;
else
if (Selected<0)
Selected = 0;
recalculateScrollPos();
recalculateScrollPos();
// post the news
// post the news
if (oldSelected != Selected && Parent && !Selecting && !MoveOverSelect)
{
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_LISTBOX_CHANGED;
Parent->OnEvent(e);
}
if (oldSelected != Selected && Parent && !Selecting && !MoveOverSelect)
{
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_LISTBOX_CHANGED;
Parent->OnEvent(e);
}
return true;
}
else
if (!event.KeyInput.PressedDown && ( event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE ) )
{
if (Parent)
{
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_LISTBOX_SELECTED_AGAIN;
Parent->OnEvent(e);
}
return true;
}
break;
return true;
}
else
if (!event.KeyInput.PressedDown && ( event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE ) )
{
if (Parent)
{
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_LISTBOX_SELECTED_AGAIN;
Parent->OnEvent(e);
}
return true;
}
break;
case EET_GUI_EVENT:
switch(event.GUIEvent.EventType)
{
case gui::EGET_SCROLL_BAR_CHANGED:
if (event.GUIEvent.Caller == ScrollBar)
return true;
break;
case gui::EGET_ELEMENT_FOCUS_LOST:
{
if (event.GUIEvent.Caller == this)
Selecting = false;
break;
}
case EET_GUI_EVENT:
switch(event.GUIEvent.EventType)
{
case gui::EGET_SCROLL_BAR_CHANGED:
if (event.GUIEvent.Caller == ScrollBar)
return true;
break;
case gui::EGET_ELEMENT_FOCUS_LOST:
{
if (event.GUIEvent.Caller == this)
Selecting = false;
break;
}
default:
break;
}
break;
default:
break;
}
break;
case EET_MOUSE_INPUT_EVENT:
{
core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
case EET_MOUSE_INPUT_EVENT:
{
core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
switch(event.MouseInput.Event)
{
case EMIE_MOUSE_WHEEL:
ScrollBar->setPos(ScrollBar->getPos() + (event.MouseInput.Wheel < 0 ? -1 : 1)*-ItemHeight/2);
return true;
switch(event.MouseInput.Event)
{
case EMIE_MOUSE_WHEEL:
ScrollBar->setPos(ScrollBar->getPos() + (event.MouseInput.Wheel < 0 ? -1 : 1)*-ItemHeight/2);
return true;
case EMIE_LMOUSE_PRESSED_DOWN:
{
Selecting = true;
return true;
}
case EMIE_LMOUSE_PRESSED_DOWN:
{
Selecting = true;
return true;
}
case EMIE_LMOUSE_LEFT_UP:
{
Selecting = false;
case EMIE_LMOUSE_LEFT_UP:
{
Selecting = false;
if (isPointInside(p))
selectNew(event.MouseInput.Y);
if (isPointInside(p))
selectNew(event.MouseInput.Y);
return true;
}
return true;
}
case EMIE_MOUSE_MOVED:
if (Selecting || MoveOverSelect)
{
if (isPointInside(p))
{
selectNew(event.MouseInput.Y, true);
return true;
}
}
default:
break;
}
}
break;
case EET_LOG_TEXT_EVENT:
case EET_USER_EVENT:
case EET_JOYSTICK_INPUT_EVENT:
case EGUIET_FORCE_32_BIT:
break;
}
}
case EMIE_MOUSE_MOVED:
if (Selecting || MoveOverSelect)
{
if (isPointInside(p))
{
selectNew(event.MouseInput.Y, true);
return true;
}
}
default:
break;
}
}
break;
case EET_LOG_TEXT_EVENT:
case EET_USER_EVENT:
case EET_JOYSTICK_INPUT_EVENT:
case EGUIET_FORCE_32_BIT:
break;
}
}
return IGUIElement::OnEvent(event);
return IGUIElement::OnEvent(event);
}
void CGUISTKListBox::selectNew(s32 ypos, bool onlyHover)
{
u32 now = (u32)StkTime::getTimeSinceEpoch();
s32 oldSelected = Selected;
u32 now = (u32)StkTime::getTimeSinceEpoch();
s32 oldSelected = Selected;
Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos);
if (Selected<0 && !Items.empty())
Selected = 0;
Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos);
if (Selected<0 && !Items.empty())
Selected = 0;
recalculateScrollPos();
recalculateScrollPos();
gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < selectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED;
selectTime = now;
// post the news
if (Parent && !onlyHover)
{
SEvent event;
event.EventType = EET_GUI_EVENT;
event.GUIEvent.Caller = this;
event.GUIEvent.Element = 0;
event.GUIEvent.EventType = eventType;
Parent->OnEvent(event);
}
gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < selectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED;
selectTime = now;
// post the news
if (Parent && !onlyHover)
{
SEvent event;
event.EventType = EET_GUI_EVENT;
event.GUIEvent.Caller = this;
event.GUIEvent.Element = 0;
event.GUIEvent.EventType = eventType;
Parent->OnEvent(event);
}
}
//! Update the position and size of the listbox, and update the scrollbar
void CGUISTKListBox::updateAbsolutePosition()
{
IGUIElement::updateAbsolutePosition();
IGUIElement::updateAbsolutePosition();
recalculateItemHeight();
recalculateItemHeight();
}
@@ -563,10 +563,10 @@ void CGUISTKListBox::draw()
//! adds an list item with an icon
u32 CGUISTKListBox::addItem(const ListItem & item)
{
Items.push_back(item);
recalculateItemHeight();
recalculateIconWidth();
return Items.size() - 1;
Items.push_back(item);
recalculateItemHeight();
recalculateIconWidth();
return Items.size() - 1;
}
@@ -574,44 +574,44 @@ void CGUISTKListBox::setSpriteBank(IGUISpriteBank* bank)
{
if ( bank == IconBank )
return;
if (IconBank)
IconBank->drop();
if (IconBank)
IconBank->drop();
IconBank = bank;
if (IconBank)
IconBank->grab();
IconBank = bank;
if (IconBank)
IconBank->grab();
}
void CGUISTKListBox::recalculateScrollPos()
{
if (!AutoScroll)
return;
if (!AutoScroll)
return;
const s32 selPos = (Selected == -1 ? TotalItemHeight : Selected * ItemHeight) - ScrollBar->getPos();
const s32 selPos = (Selected == -1 ? TotalItemHeight : Selected * ItemHeight) - ScrollBar->getPos();
if (selPos < 0)
{
ScrollBar->setPos(ScrollBar->getPos() + selPos);
}
else
if (selPos > AbsoluteRect.getHeight() - ItemHeight)
{
ScrollBar->setPos(ScrollBar->getPos() + selPos - AbsoluteRect.getHeight() + ItemHeight);
}
if (selPos < 0)
{
ScrollBar->setPos(ScrollBar->getPos() + selPos);
}
else
if (selPos > AbsoluteRect.getHeight() - ItemHeight)
{
ScrollBar->setPos(ScrollBar->getPos() + selPos - AbsoluteRect.getHeight() + ItemHeight);
}
}
void CGUISTKListBox::setAutoScrollEnabled(bool scroll)
{
AutoScroll = scroll;
AutoScroll = scroll;
}
bool CGUISTKListBox::isAutoScrollEnabled() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return AutoScroll;
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return AutoScroll;
}
void CGUISTKListBox::recalculateIconWidth()
@@ -619,128 +619,128 @@ void CGUISTKListBox::recalculateIconWidth()
for(int x = 0; x < (int)Items.getLast().m_contents.size(); ++x)
{
s32 icon = Items.getLast().m_contents[x].m_icon;
if (IconBank && icon > -1 &&
IconBank->getSprites().size() > (u32)icon &&
IconBank->getSprites()[(u32)icon].Frames.size())
{
u32 rno = IconBank->getSprites()[(u32)icon].Frames[0].rectNumber;
if (IconBank->getPositions().size() > rno)
{
const s32 w = IconBank->getPositions()[rno].getWidth();
if (w > ItemsIconWidth)
ItemsIconWidth = w;
}
}
if (IconBank && icon > -1 &&
IconBank->getSprites().size() > (u32)icon &&
IconBank->getSprites()[(u32)icon].Frames.size())
{
u32 rno = IconBank->getSprites()[(u32)icon].Frames[0].rectNumber;
if (IconBank->getPositions().size() > rno)
{
const s32 w = IconBank->getPositions()[rno].getWidth();
if (w > ItemsIconWidth)
ItemsIconWidth = w;
}
}
}
}
void CGUISTKListBox::setCell(u32 row_num, u32 col_num, const wchar_t* text, s32 icon)
{
if ( row_num >= Items.size() )
return;
if ( row_num >= Items.size() )
return;
if ( col_num >= Items[row_num].m_contents.size() )
return;
Items[row_num].m_contents[col_num].m_text = text;
Items[row_num].m_contents[col_num].m_icon = icon;
recalculateItemHeight();
recalculateIconWidth();
recalculateItemHeight();
recalculateIconWidth();
}
void CGUISTKListBox::swapItems(u32 index1, u32 index2)
{
if ( index1 >= Items.size() || index2 >= Items.size() )
return;
if ( index1 >= Items.size() || index2 >= Items.size() )
return;
ListItem dummmy = Items[index1];
Items[index1] = Items[index2];
Items[index2] = dummmy;
ListItem dummmy = Items[index1];
Items[index1] = Items[index2];
Items[index2] = dummmy;
}
void CGUISTKListBox::setItemOverrideColor(u32 index, video::SColor color)
{
for ( u32 c=0; c < EGUI_LBC_COUNT; ++c )
{
Items[index].OverrideColors[c].Use = true;
Items[index].OverrideColors[c].Color = color;
}
for ( u32 c=0; c < EGUI_LBC_COUNT; ++c )
{
Items[index].OverrideColors[c].Use = true;
Items[index].OverrideColors[c].Color = color;
}
}
void CGUISTKListBox::setItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType, video::SColor color)
{
if ( index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return;
if ( index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return;
Items[index].OverrideColors[colorType].Use = true;
Items[index].OverrideColors[colorType].Color = color;
Items[index].OverrideColors[colorType].Use = true;
Items[index].OverrideColors[colorType].Color = color;
}
void CGUISTKListBox::clearItemOverrideColor(u32 index)
{
for (u32 c=0; c < (u32)EGUI_LBC_COUNT; ++c )
{
Items[index].OverrideColors[c].Use = false;
}
for (u32 c=0; c < (u32)EGUI_LBC_COUNT; ++c )
{
Items[index].OverrideColors[c].Use = false;
}
}
void CGUISTKListBox::clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType)
{
if ( index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return;
if ( index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return;
Items[index].OverrideColors[colorType].Use = false;
Items[index].OverrideColors[colorType].Use = false;
}
bool CGUISTKListBox::hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const
{
if ( index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return false;
if ( index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return false;
return Items[index].OverrideColors[colorType].Use;
return Items[index].OverrideColors[colorType].Use;
}
video::SColor CGUISTKListBox::getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const
{
if ( (u32)index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return video::SColor();
if ( (u32)index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT )
return video::SColor();
return Items[index].OverrideColors[colorType].Color;
return Items[index].OverrideColors[colorType].Color;
}
video::SColor CGUISTKListBox::getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const
{
IGUISkin* skin = Environment->getSkin();
if ( !skin )
return video::SColor();
IGUISkin* skin = Environment->getSkin();
if ( !skin )
return video::SColor();
switch ( colorType )
{
case EGUI_LBC_TEXT:
return skin->getColor(EGDC_BUTTON_TEXT);
case EGUI_LBC_TEXT_HIGHLIGHT:
return skin->getColor(EGDC_HIGH_LIGHT_TEXT);
case EGUI_LBC_ICON:
return skin->getColor(EGDC_ICON);
case EGUI_LBC_ICON_HIGHLIGHT:
return skin->getColor(EGDC_ICON_HIGH_LIGHT);
default:
return video::SColor();
}
switch ( colorType )
{
case EGUI_LBC_TEXT:
return skin->getColor(EGDC_BUTTON_TEXT);
case EGUI_LBC_TEXT_HIGHLIGHT:
return skin->getColor(EGDC_HIGH_LIGHT_TEXT);
case EGUI_LBC_ICON:
return skin->getColor(EGDC_ICON);
case EGUI_LBC_ICON_HIGHLIGHT:
return skin->getColor(EGDC_ICON_HIGH_LIGHT);
default:
return video::SColor();
}
}
//! set global itemHeight
void CGUISTKListBox::setItemHeight( s32 height )
{
ItemHeight = height;
ItemHeightOverride = 1;
ItemHeight = height;
ItemHeightOverride = 1;
}

View File

@@ -17,12 +17,12 @@ namespace irr
{
namespace gui
{
class IGUIFont;
class IGUIScrollBar;
class IGUIFont;
class IGUIScrollBar;
class CGUISTKListBox : public IGUIElement
{
public:
class CGUISTKListBox : public IGUIElement
{
public:
struct ListItem
{
@@ -163,7 +163,7 @@ namespace irr
//! Sets whether to draw the background
virtual void setDrawBackground(bool draw);
private:
private:
void recalculateItemHeight();
void selectNew(s32 ypos, bool onlyHover=false);
@@ -189,7 +189,7 @@ namespace irr
bool MoveOverSelect;
bool AutoScroll;
bool HighlightWhenNotFocused;
};
};
} // end namespace gui

View File

@@ -33,7 +33,7 @@
namespace GUIEngine
{
/**
/**
* \brief A text button widget.
* \ingroup widgetsgroup
*/
@@ -49,7 +49,7 @@ namespace GUIEngine
/** \brief Implement callback from base class Widget */
void add();
/**
/**
* \brief Change the label on the button
* \pre This should only be called after a widget has been add()ed (changing the label
* before the widget is added can be done by editing the 'text' property of Widget).
@@ -63,7 +63,7 @@ namespace GUIEngine
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 4; }
};
};
}
#endif

View File

@@ -33,8 +33,8 @@ namespace GUIEngine
class CheckBoxWidget : public Widget
{
bool m_state;
EventPropagation transmitEvent(Widget* w,
const std::string& originator,
EventPropagation transmitEvent(Widget* w,
const std::string& originator,
const int playerID);
public:
@@ -57,7 +57,7 @@ namespace GUIEngine
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 10; }
};
};
}
#endif

View File

@@ -39,7 +39,7 @@ namespace GUIEngine
{
public:
virtual ~DynamicRibbonHoverListener() {}
virtual void onSelectionChanged(DynamicRibbonWidget* theWidget,
virtual void onSelectionChanged(DynamicRibbonWidget* theWidget,
const std::string& selectionID,
const irr::core::stringw& selectionText,
const int playerID) = 0;
@@ -62,7 +62,7 @@ namespace GUIEngine
unsigned int m_badges;
};
/**
/**
* \brief An extended version of RibbonWidget, with more capabilities.
* A dynamic ribbon builds upon RibbonWidget, adding dynamic contents creation and sizing,
* scrolling, multiple-row layouts.
@@ -221,7 +221,7 @@ namespace GUIEngine
'updateItemDisplay' to update the display. */
void clearItems();
/**
/**
* \brief Register a listener to be notified of selection changes within the ribbon.
* \note The ribbon takes ownership of this listener and will delete it.
* \note The listener will be deleted upon leaving the screen, so you will likely
@@ -248,7 +248,7 @@ namespace GUIEngine
/** Returns a read-only list of items added to this ribbon */
const std::vector<ItemDescription>& getItems() const { return m_items; }
/**
/**
* \brief Select an item from its numerical ID. Only for [1-row] combo ribbons.
*
* \param item_id In range [0 .. number of items added through 'addItem' - 1]
@@ -261,8 +261,8 @@ namespace GUIEngine
*
* \return Whether setting the selection was successful (whether the item exists)
*/
bool setSelection(const std::string &item_codename,
const int playerID, const bool focusIt,
bool setSelection(const std::string &item_codename,
const int playerID, const bool focusIt,
bool evenIfDeactivated=false);
/** \brief Callback from parent class Widget. */

View File

@@ -107,11 +107,11 @@ namespace GUIEngine
* be resized to fit a different aspect ratio.
* \note May safely be called no matter if the widget is add()ed or not
*/
void setImage(const char* path_to_texture,
void setImage(const char* path_to_texture,
IconPathType path_type=ICON_PATH_TYPE_NO_CHANGE);
/** Convenience function taking std::string. */
void setImage(const std::string &path_to_texture,
void setImage(const std::string &path_to_texture,
IconPathType path_type=ICON_PATH_TYPE_NO_CHANGE)
{
setImage(path_to_texture.c_str(), path_type);

View File

@@ -88,7 +88,7 @@ namespace GUIEngine
/** Overloaded function which takes a stringw. */
virtual void setText(const irr::core::stringw &s, bool expandAsNeeded)
{
setText(s.c_str(), expandAsNeeded);
setText(s.c_str(), expandAsNeeded);
}
// --------------------------------------------------------------------
@@ -98,7 +98,7 @@ namespace GUIEngine
// --------------------------------------------------------------------
/**
/**
* \brief Check if the current has been fully scrolled
* \return true if the text has completely scrolled off
* \pre May only be called after this widget has been add()ed

View File

@@ -208,7 +208,7 @@ namespace GUIEngine
/**
* \brief Make an item red to mark an error, for instance
* \pre may only be called after the widget has been added to the screen with add()
*/
*/
void markItemRed(const std::string internalName, bool red=true)
{
const int id = getItemID(internalName);
@@ -224,8 +224,8 @@ namespace GUIEngine
}
/** Override callback from Widget */
virtual EventPropagation transmitEvent(Widget* w,
const std::string& originator,
virtual EventPropagation transmitEvent(Widget* w,
const std::string& originator,
const int playerID);
void setColumnListener(IListWidgetHeaderListener* listener)

View File

@@ -28,7 +28,7 @@
namespace GUIEngine
{
/**
/**
* \brief A progress bar widget.
* \ingroup widgetsgroup
*/
@@ -62,7 +62,7 @@ namespace GUIEngine
/** Get the current value of the widget. */
int getValue() {return m_value; };
};
};
}
#endif

View File

@@ -56,7 +56,7 @@ void RatingBarWidget::add()
// -----------------------------------------------------------------------------
/** Get the current step of the star
*
*
* \param index The index of the star.
* \return The current step of the star.
*/

View File

@@ -29,7 +29,7 @@
namespace GUIEngine
{
/**
/**
* \brief A rating bar widget.
* \ingroup widgetsgroup
*/
@@ -76,7 +76,7 @@ namespace GUIEngine
virtual void onClick();
void allowVoting() { m_allow_voting = true; }
};
};
}
#endif

View File

@@ -305,7 +305,7 @@ void RibbonWidget::add()
(float)m_active_children[i].m_w / (float)m_active_children[i].m_h;
// calculate the size of the image
std::string filename =
std::string filename =
file_manager->getAsset(m_active_children[i].m_properties[PROP_ICON]);
video::ITexture* image =
irr_driver->getTexture((filename).c_str());

View File

@@ -42,8 +42,8 @@ namespace GUIEngine
/** \brief A static text/icons/tabs bar widget.
* The contents of this ribbon are static.
* \ingroup widgetsgroup
* \note items you add to a list are kept after the the ribbon was in
* is removed (i.e. you don't need to add items everytime the
* \note items you add to a list are kept after the the ribbon was in
* is removed (i.e. you don't need to add items everytime the
* screen is shown, only upon loading)
*/
class RibbonWidget : public Widget
@@ -54,7 +54,7 @@ namespace GUIEngine
public:
virtual ~IRibbonListener(){}
virtual void onRibbonWidgetScroll(const int delta_x) = 0;
virtual void onRibbonWidgetFocus(RibbonWidget* emitter,
virtual void onRibbonWidgetFocus(RibbonWidget* emitter,
const int playerID) = 0;
virtual void onSelectionChange() = 0;
};
@@ -68,17 +68,17 @@ namespace GUIEngine
/** The type of this ribbon (toolbar, combo, tabs) */
RibbonType m_ribbon_type;
/** Each item within the ribbon holds a flag saying whether it is
* selected or not. This method updates the flag in all of this
/** Each item within the ribbon holds a flag saying whether it is
* selected or not. This method updates the flag in all of this
* ribbon's children. Called everytime selection changes.*/
void updateSelection();
/** Callbacks */
virtual EventPropagation rightPressed(const int playerID=0);
virtual EventPropagation leftPressed(const int playerID=0);
virtual EventPropagation mouseHovered(Widget* child,
virtual EventPropagation mouseHovered(Widget* child,
const int playerID);
virtual EventPropagation transmitEvent(Widget* w,
virtual EventPropagation transmitEvent(Widget* w,
const std::string& originator,
const int playerID=0);
virtual EventPropagation focused(const int playerID);
@@ -93,15 +93,15 @@ namespace GUIEngine
LEAK_CHECK()
/** Internal identifier of filler items that are added in a ribbon
* widget to filllines when the number of items cannot be divided
* by the number of rows in the grid (mostly used by dynamic ribbon
/** Internal identifier of filler items that are added in a ribbon
* widget to filllines when the number of items cannot be divided
* by the number of rows in the grid (mostly used by dynamic ribbon
* widgets, but the base ribbon needs to know about filler items)
*/
static const char NO_ITEM_ID[];
/** Contains which element within the ribbon is currently focused by
* player 0 (used by the skin to show mouse hovers over items that
* player 0 (used by the skin to show mouse hovers over items that
* are not selected). Only used for COMBO and TAB ribbons. */
Widget* m_mouse_focus;
@@ -112,21 +112,21 @@ namespace GUIEngine
/** Sets a listener that will be notified of changes on this ribbon.
* Does _not_ take ownership of the listener, i.e. will not delete it.
* You may call this with the listener parameter set to NULL to
* You may call this with the listener parameter set to NULL to
* remove the listener. */
void setListener(IRibbonListener* listener) { m_listener = listener; }
// --------------------------------------------------------------------
/** Returns the type of this ribbon (see the GUI module overview page
/** Returns the type of this ribbon (see the GUI module overview page
* for detailed descriptions) */
RibbonType getRibbonType() const { return m_ribbon_type; }
// --------------------------------------------------------------------
/** Returns the numerical ID of the selected item within the ribbon */
int getSelection(const int playerID) const
int getSelection(const int playerID) const
{ return m_selection[playerID]; }
// --------------------------------------------------------------------
// --------------------------------------------------------------------
/** Returns the string ID (internal name) of the selection */
const std::string& getSelectionIDString(const int playerID);
// --------------------------------------------------------------------
// --------------------------------------------------------------------
/** Returns the user-visible text of the selection */
irr::core::stringw getSelectionText(const int playerID)
{
@@ -134,10 +134,10 @@ namespace GUIEngine
if (selection < 0 || selection >= int(m_children.size())) return "";
return m_children[selection].m_text;
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
/** Sets the ID of the selected item within the ribbon */
void setSelection(const int i, const int playerID)
void setSelection(const int i, const int playerID)
{ m_selection[playerID] = i; updateSelection(); }
/** Select an item in the ribbon by its internal name */
@@ -159,9 +159,9 @@ namespace GUIEngine
GUIEngine::Widget * findWidgetNamed(const char* interalName);
/** \brief Dynamically (at runtime) add a text item to this ribbon
* \pre This must be called before RibbonWidget::add, while the
* \pre This must be called before RibbonWidget::add, while the
* widget is not yet displayed
* \pre only valid for ribbons that take text-only contents
* \pre only valid for ribbons that take text-only contents
* (e.g. tab bars)
*/
void addTextChild(const wchar_t* text, const std::string id);

View File

@@ -62,17 +62,17 @@ void SpinnerWidget::add()
if (min_s.size() > 0)
{
if (!StringUtils::parseString<int>(min_s, &m_min))
if (!StringUtils::parseString<int>(min_s, &m_min))
{
Log::warn("invalid value for spinner widget minimum value : %s", min_s.c_str());
Log::warn("invalid value for spinner widget minimum value : %s", min_s.c_str());
}
}
if (max_s.size() > 0)
{
if (!StringUtils::parseString<int>(max_s, &m_max))
{
Log::warn("invalid value for spinner widget maximum value : %s", max_s.c_str());
if (!StringUtils::parseString<int>(max_s, &m_max))
{
Log::warn("invalid value for spinner widget maximum value : %s", max_s.c_str());
}
}
@@ -160,7 +160,7 @@ void SpinnerWidget::add()
{
label->setText(m_labels[m_value].c_str() );
}
}
@@ -174,7 +174,7 @@ void SpinnerWidget::add()
m_children[2].m_id = m_children[2].m_element->getID();
// refresh display
setValue(m_value);
}

Some files were not shown because too many files have changed in this diff Show More