Merge remote-tracking branch 'origin/master' into nw

This commit is contained in:
hiker 2016-12-06 18:32:04 +11:00
commit 1939075a1b
80 changed files with 1817 additions and 1423 deletions

View File

@ -8,7 +8,7 @@ layout(location = 6) in vec3 Bitangent;
layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
layout(location = 12) in vec4 GlowColor;
layout(location = 15) in vec4 GlowColor;
flat out vec4 glowColor;

View File

@ -19,9 +19,18 @@ out vec2 uv;
void main()
{
mat4 new_model_matrix = ModelMatrix;
mat4 new_inverse_model_matrix = InverseModelMatrix;
new_model_matrix[3].xyz += windDir * Color.r;
// FIXME doesn't seem to make too much difference in pass 2, because this
// affects "nor" which is later only * 0.1 by scattering
new_inverse_model_matrix[3].xyz -= windDir * Color.r;
mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * new_model_matrix;
mat4 TransposeInverseModelView = transpose(InverseViewMatrix * new_inverse_model_matrix);
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix;
mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix);
nor = (TransposeInverseModelView * vec4(Normal, 1.)).xyz;
gl_Position = ModelViewProjectionMatrix * vec4(Position + windDir * Color.r, 1.);
}

View File

@ -2,17 +2,21 @@
layout(bindless_sampler) uniform sampler2D Albedo;
layout(bindless_sampler) uniform sampler2D dtex;
layout(bindless_sampler) uniform sampler2D SpecMap;
layout(bindless_sampler) uniform sampler2D colorization_mask;
#else
uniform sampler2D Albedo;
uniform sampler2D dtex;
uniform sampler2D SpecMap;
uniform sampler2D colorization_mask;
#endif
in vec3 nor;
in vec2 uv;
uniform vec2 color_change;
out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
@ -24,6 +28,15 @@ void main(void)
#endif
if (color.a < 0.5) discard;
float mask = texture(colorization_mask, uv).a;
if (color_change.x > 0.0)
{
vec3 old_hsv = rgbToHsv(color.rgb);
float mask_step = step(mask, 0.5);
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(color_change.x, max(old_hsv.y, color_change.y)), vec2(mask_step, mask_step));
color.xyz = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
}
vec2 texc = gl_FragCoord.xy / screen;
float z = texture(dtex, texc).x;
@ -39,8 +52,8 @@ void main(void)
float fLdotNBack = max(0., - dot(nor, L) * 0.6 + 0.4);
float scattering = mix(fPowEdotL, fLdotNBack, .5);
float specmap = texture(SpecMap, uv).g;
vec3 LightFactor = color.xyz * (scattering * 0.3) + getLightFactor(color.xyz, vec3(1.), specmap, 0.);
FragColor = vec4(color.xyz * LightFactor, 1.);
float specmap = texture(SpecMap, uv).g;
vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.);
FragColor = vec4(LightFactor, 1.);
}

View File

@ -7,7 +7,7 @@ uniform sampler2D SpecMap;
#ifdef Use_Bindless_Texture
flat in sampler2D handle;
flat in sampler2D secondhandle;
flat in sampler2D thirdhandle;
flat in sampler2D fourthhandle;
#endif
in vec2 uv;
in vec2 uv_bis;
@ -23,7 +23,7 @@ void main(void)
#ifdef SRGBBindlessFix
color.xyz = pow(color.xyz, vec3(2.2));
#endif
vec4 detail = texture(thirdhandle, uv_bis);
vec4 detail = texture(fourthhandle, uv_bis);
#else
vec4 color = texture(Albedo, uv);
vec4 detail = texture(Detail, uv_bis);

View File

@ -9,9 +9,11 @@ layout(location = 3) in vec2 Texcoord;
layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
layout(location = 10) in vec4 misc_data;
#ifdef Use_Bindless_Texture
layout(location = 10) in sampler2D Handle;
layout(location = 11) in sampler2D SecondHandle;
layout(location = 11) in sampler2D Handle;
layout(location = 12) in sampler2D SecondHandle;
layout(location = 13) in sampler2D ThirdHandle;
#endif
#else
@ -23,13 +25,16 @@ in vec2 Texcoord;
in vec3 Origin;
in vec3 Orientation;
in vec3 Scale;
in vec4 misc_data;
#endif
out vec3 nor;
out vec2 uv;
out vec2 color_change;
#ifdef Use_Bindless_Texture
flat out sampler2D handle;
flat out sampler2D secondhandle;
flat out sampler2D thirdhandle;
#endif
#stk_include "utils/getworldmatrix.vert"
@ -41,8 +46,10 @@ void main()
gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
color_change = misc_data.zw;
#ifdef Use_Bindless_Texture
handle = Handle;
secondhandle = SecondHandle;
thirdhandle = ThirdHandle;
#endif
}

View File

@ -4,32 +4,46 @@ layout(bindless_sampler) uniform sampler2D dtex;
uniform sampler2D Albedo;
uniform sampler2D SpecMap;
uniform sampler2D dtex;
uniform sampler2D colorization_mask;
#endif
#ifdef Use_Bindless_Texture
flat in sampler2D handle;
flat in sampler2D secondhandle;
flat in sampler2D thirdhandle;
#endif
in vec3 nor;
in vec2 uv;
in vec2 color_change;
out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
#ifdef Use_Bindless_Texture
vec4 color = texture(handle, uv);
float specmap = texture(secondhandle, uv).g;
float mask = texture(thirdhandle, uv).a;
#ifdef SRGBBindlessFix
color.xyz = pow(color.xyz, vec3(2.2));
#endif
#else
vec4 color = texture(Albedo, uv);
float specmap = texture(SpecMap, uv).g;
float mask = texture(colorization_mask, uv).a;
#endif
if (color.a < 0.5) discard;
if (color_change.x > 0.0)
{
vec3 old_hsv = rgbToHsv(color.rgb);
float mask_step = step(mask, 0.5);
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(color_change.x, max(old_hsv.y, color_change.y)), vec2(mask_step, mask_step));
color.xyz = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
}
vec2 texc = gl_FragCoord.xy / screen;
float z = texture(dtex, texc).x;
@ -46,7 +60,6 @@ void main(void)
float fLdotNBack = max(0., - dot(nor, L) * 0.6 + 0.4);
float scattering = mix(fPowEdotL, fLdotNBack, .5);
vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.);
FragColor = vec4(LightFactor, 1.);
}

View File

@ -5,7 +5,7 @@ uniform sampler2D glossMap;
#ifdef Use_Bindless_Texture
flat in sampler2D secondhandle;
flat in sampler2D thirdhandle;
flat in sampler2D fourthhandle;
#endif
in vec3 tangent;
in vec3 bitangent;
@ -18,7 +18,7 @@ void main()
{
// normal in Tangent Space
#ifdef Use_Bindless_Texture
vec3 TS_normal = 2.0 * texture(thirdhandle, uv).rgb - 1.0;
vec3 TS_normal = 2.0 * texture(fourthhandle, uv).rgb - 1.0;
float gloss = texture(secondhandle, uv).x;
#else
vec3 TS_normal = 2.0 * texture(normalMap, uv).rgb - 1.0;

View File

@ -10,10 +10,12 @@ layout(location = 6) in vec3 Bitangent;
layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
layout(location = 10) in vec4 misc_data;
#ifdef Use_Bindless_Texture
layout(location = 10) in sampler2D Handle;
layout(location = 11) in sampler2D SecondHandle;
layout(location = 11) in sampler2D Handle;
layout(location = 12) in sampler2D SecondHandle;
layout(location = 13) in sampler2D ThirdHandle;
layout(location = 14) in sampler2D FourthHandle;
#endif
#else
@ -28,6 +30,7 @@ in vec3 Bitangent;
in vec3 Origin;
in vec3 Orientation;
in vec3 Scale;
in vec4 misc_data;
#endif
out vec3 nor;
@ -36,10 +39,12 @@ out vec3 bitangent;
out vec2 uv;
out vec2 uv_bis;
out vec4 color;
out vec2 color_change;
#ifdef Use_Bindless_Texture
flat out sampler2D handle;
flat out sampler2D secondhandle;
flat out sampler2D thirdhandle;
flat out sampler2D fourthhandle;
#endif
#stk_include "utils/getworldmatrix.vert"
@ -54,12 +59,14 @@ void main(void)
// Keep direction
tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz;
bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz;
uv = Texcoord;
uv = vec2(Texcoord.x + misc_data.x, Texcoord.y + misc_data.y);
uv_bis = SecondTexcoord;
color = Color.zyxw;
color_change = misc_data.zw;
#ifdef Use_Bindless_Texture
handle = Handle;
secondhandle = SecondHandle;
thirdhandle = ThirdHandle;
fourthhandle = FourthHandle;
#endif
}

View File

@ -7,12 +7,12 @@ uniform sampler2D colorization_mask;
#ifdef Use_Bindless_Texture
flat in sampler2D handle;
flat in sampler2D secondhandle;
flat in sampler2D thirdhandle;
#endif
uniform vec2 color_change;
in vec2 uv;
in vec4 color;
in vec2 color_change;
out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
@ -24,6 +24,7 @@ void main(void)
vec4 col = texture(handle, uv);
float specmap = texture(secondhandle, uv).g;
float emitmap = texture(secondhandle, uv).b;
float mask = texture(thirdhandle, uv).a;
#ifdef SRGBBindlessFix
col.xyz = pow(col.xyz, vec3(2.2));
#endif

View File

@ -1,31 +1,47 @@
#ifndef Use_Bindless_Texture
uniform sampler2D Albedo;
uniform sampler2D SpecMap;
uniform sampler2D colorization_mask;
#endif
#ifdef Use_Bindless_Texture
flat in sampler2D handle;
flat in sampler2D secondhandle;
flat in sampler2D thirdhandle;
#endif
in vec2 uv;
in vec4 color;
in vec2 color_change;
out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
#ifdef Use_Bindless_Texture
vec4 col = texture(handle, uv);
float specmap = texture(secondhandle, uv).g;
float mask = texture(thirdhandle, uv).a;
#ifdef SRGBBindlessFix
col.xyz = pow(col.xyz, vec3(2.2));
#endif
#else
vec4 col = texture(Albedo, uv);
float specmap = texture(SpecMap, uv).g;
float mask = texture(colorization_mask, uv).a;
#endif
col.xyz *= pow(color.xyz, vec3(2.2));
if (col.a * color.a < 0.5) discard;
if (color_change.x > 0.0)
{
vec3 old_hsv = rgbToHsv(col.rgb);
float mask_step = step(mask, 0.5);
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(color_change.x, max(old_hsv.y, color_change.y)), vec2(mask_step, mask_step));
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
col = vec4(new_color.r, new_color.g, new_color.b, col.a);
}
FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap, 0.), 1.);
}

View File

@ -9,7 +9,7 @@ layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
#ifdef Use_Bindless_Texture
layout(location = 10) in uvec2 Handle;
layout(location = 11) in uvec2 Handle;
#endif
out vec3 nor;

View File

@ -10,7 +10,7 @@ layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
#ifdef Use_Bindless_Texture
layout(location = 10) in uvec2 Handle;
layout(location = 11) in uvec2 Handle;
#endif
#else

View File

@ -8,7 +8,7 @@ layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
#ifdef Use_Bindless_Texture
layout(location = 10) in uvec2 Handle;
layout(location = 11) in uvec2 Handle;
#endif
#else

View File

@ -1,7 +1,7 @@
#ifdef GL_ES
uniform mat4 ModelMatrix;
uniform mat4 InverseModelMatrix;
uniform mat4 TextureMatrix;
uniform vec2 texture_trans;
#else
uniform mat4 ModelMatrix =
mat4(1., 0., 0., 0.,
@ -14,11 +14,7 @@ uniform mat4 InverseModelMatrix =
0., 0., 1., 0.,
0., 0., 0., 1.);
uniform mat4 TextureMatrix =
mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1.);
uniform vec2 texture_trans = vec2(0., 0.);
#endif
#if __VERSION__ >= 330
@ -58,6 +54,6 @@ void main(void)
// Keep direction
tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz;
bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz;
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv = vec2(Texcoord.x + texture_trans.x, Texcoord.y + texture_trans.y);
uv_bis = SecondTexcoord;
}

View File

@ -1,6 +1,8 @@
#ifdef Use_Bindless_Texture
layout(bindless_sampler) uniform sampler2D Albedo;
layout(bindless_sampler) uniform sampler2D SpecMap;
layout(bindless_sampler) uniform sampler2D colorization_mask;
#else
uniform sampler2D Albedo;
uniform sampler2D SpecMap;
@ -20,6 +22,7 @@ void main(void)
{
#ifdef Use_Bindless_Texture
vec4 col = texture(Albedo, uv);
float mask = texture(colorization_mask, uv).a;
#ifdef SRGBBindlessFix
col.xyz = pow(col.xyz, vec3(2.2));
#endif

View File

@ -1,16 +1,21 @@
#ifdef Use_Bindless_Texture
layout(bindless_sampler) uniform sampler2D Albedo;
layout(bindless_sampler) uniform sampler2D SpecMap;
layout(bindless_sampler) uniform sampler2D colorization_mask;
#else
uniform sampler2D Albedo;
uniform sampler2D SpecMap;
uniform sampler2D colorization_mask;
#endif
uniform vec2 color_change;
in vec2 uv;
in vec4 color;
out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
@ -22,6 +27,16 @@ void main(void)
#endif
col.xyz *= pow(color.xyz, vec3(2.2));
if (col.a * color.a < 0.5) discard;
float mask = texture(colorization_mask, uv).a;
if (color_change.x > 0.0)
{
vec3 old_hsv = rgbToHsv(col.rgb);
float mask_step = step(mask, 0.5);
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(color_change.x, max(old_hsv.y, color_change.y)), vec2(mask_step, mask_step));
col.xyz = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
}
float specmap = texture(SpecMap, uv).g;
float emitmap = texture(SpecMap, uv).b;

View File

@ -1,11 +1,6 @@
uniform mat4 ModelMatrix;
uniform mat4 RSMMatrix;
uniform mat4 TextureMatrix =
mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1.);
uniform vec2 texture_trans = vec2(0., 0.);
#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
@ -33,7 +28,7 @@ void main(void)
mat4 TransposeInverseModel = transpose(inverse(ModelMatrix));
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModel * vec4(Normal, 0.)).xyz;
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv = vec2(Texcoord.x + texture_trans.x, Texcoord.y + texture_trans.y);
uv_bis = SecondTexcoord;
color = Color.zyxw;
}

View File

@ -14,7 +14,9 @@ void main()
{
vec4 Color = texture(tex, uv);
#ifdef Use_Bindless_Texture
#ifdef SRGBBindlessFix
Color.xyz = pow(Color.xyz, vec3(2.2));
#endif
#endif
Color.xyz *= pow(color.xyz, vec3(2.2));
Color.a *= color.a;

View File

@ -21,7 +21,9 @@ void main()
{
vec4 diffusecolor = texture(tex, uv);
#ifdef Use_Bindless_Texture
#ifdef SRGBBindlessFix
diffusecolor.xyz = pow(diffusecolor.xyz, vec3(2.2));
#endif
#endif
diffusecolor.xyz *= pow(color.xyz, vec3(2.2));
diffusecolor.a *= color.a;

View File

@ -21,7 +21,9 @@ void main()
{
vec4 diffusecolor = texture(tex, uv);
#ifdef Use_Bindless_Texture
#ifdef SRGBBindlessFix
diffusecolor.xyz = pow(diffusecolor.xyz, vec3(2.2));
#endif
#endif
diffusecolor.xyz *= pow(color.xyz, vec3(2.2));
diffusecolor.a *= color.a;

View File

@ -83,6 +83,12 @@ namespace irr
MacOS: Not yet implemented
*/
EET_USER_EVENT,
//! Pass on raw events from the OS
EET_SYSTEM_EVENT,
//! Application state events like a resume, pause etc.
EET_APPLICATION_EVENT,
//! This enum is never used, it only forces the compiler to
//! compile these enumeration values to 32 bit.
@ -191,6 +197,42 @@ namespace irr
//! No real event. Just for convenience to get number of events
ETIE_COUNT
};
enum ESYSTEM_EVENT_TYPE
{
//! From Android command handler for native activity messages
ESET_ANDROID_CMD = 0,
// TODO: for example ESET_WINDOWS_MESSAGE for win32 message loop events
//! No real event, but to get number of event types
ESET_COUNT
};
//! Enumeration for a commonly used application state events (it's useful mainly for mobile devices)
enum EAPPLICATION_EVENT_TYPE
{
//! The application will be resumed.
EAET_WILL_RESUME = 0,
//! The application has been resumed.
EAET_DID_RESUME,
//! The application will be paused.
EAET_WILL_PAUSE,
//! The application has been paused.
EAET_DID_PAUSE,
//! The application will be terminated.
EAET_WILL_TERMINATE,
//! The application received a memory warning.
EAET_MEMORY_WARNING,
//! No real event, but to get number of event types.
EAET_COUNT
};
namespace gui
{
@ -365,12 +407,16 @@ struct SEvent
//! Any kind of keyboard event.
struct SKeyInput
{
//! Character corresponding to the key (0, if not a character)
//! Character corresponding to the key (0, if not a character, value undefined in key releases)
wchar_t Char;
//! Key which has been pressed or released
EKEY_CODE Key;
//! System dependent code. Only set for systems which are described below, otherwise undefined.
//! Android: int32_t with physical key as returned by AKeyEvent_getKeyCode
u32 SystemKeyCode;
//! If not true, then the key was left up
bool PressedDown:1;
@ -518,6 +564,31 @@ struct SEvent
//! Another user specified data as int
s32 UserData2;
};
// Raw events from the OS
struct SSystemEvent
{
//! Android command handler native activity messages.
struct SAndroidCmd
{
//! APP_CMD_ enums defined in android_native_app_glue.h from the Android NDK
s32 Cmd;
};
// TOOD: more structs for iphone, Windows, X11, etc.
ESYSTEM_EVENT_TYPE EventType;
union
{
struct SAndroidCmd AndroidCmd;
};
};
// Application state event
struct SApplicationEvent
{
EAPPLICATION_EVENT_TYPE EventType;
};
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
struct SInputMethodEvent
@ -547,6 +618,8 @@ struct SEvent
struct SJoystickEvent JoystickEvent;
struct SLogEvent LogEvent;
struct SUserEvent UserEvent;
struct SSystemEvent SystemEvent;
struct SApplicationEvent ApplicationEvent;
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
struct SInputMethodEvent InputMethodEvent;
#endif

View File

@ -172,7 +172,6 @@ namespace scene
\return The non-transformed bounding box. */
virtual const core::aabbox3d<f32>& getBoundingBox() const = 0;
//! Get the axis aligned, transformed and animated absolute bounding box of this node.
/** \return The transformed bounding box. */
virtual const core::aabbox3d<f32> getTransformedBoundingBox() const
@ -590,6 +589,12 @@ namespace scene
return Children;
}
//! Returns a list of all children (non-const version).
/** \return The list of all children of this node. */
core::list<ISceneNode*>& getChildren()
{
return Children;
}
//! Changes the parent of the scene node.
/** \param newParent The new parent to be used. */

View File

@ -10,6 +10,7 @@ namespace irr
enum EKEY_CODE
{
KEY_UNKNOWN = 0x0,
KEY_LBUTTON = 0x01, // Left mouse button
KEY_RBUTTON = 0x02, // Right mouse button
KEY_CANCEL = 0x03, // Control-break processing
@ -141,6 +142,20 @@ namespace irr
KEY_RCONTROL = 0xA3, // Right CONTROL key
KEY_LMENU = 0xA4, // Left MENU key
KEY_RMENU = 0xA5, // Right MENU key
KEY_BROWSER_BACK = 0xA6, // Browser Back key
KEY_BROWSER_FORWARD = 0xA7, // Browser Forward key
KEY_BROWSER_REFRESH = 0xA8, // Browser Refresh key
KEY_BROWSER_STOP = 0xA9, // Browser Stop key
KEY_BROWSER_SEARCH = 0xAA, // Browser Search key
KEY_BROWSER_FAVORITES =0xAB, // Browser Favorites key
KEY_BROWSER_HOME = 0xAC, // Browser Start and Home key
KEY_VOLUME_MUTE = 0xAD, // Volume Mute key
KEY_VOLUME_DOWN = 0xAE, // Volume Down key
KEY_VOLUME_UP = 0xAF, // Volume Up key
KEY_MEDIA_NEXT_TRACK = 0xB0, // Next Track key
KEY_MEDIA_PREV_TRACK = 0xB1, // Previous Track key
KEY_MEDIA_STOP = 0xB2, // Stop Media key
KEY_MEDIA_PLAY_PAUSE = 0xB3, // Play/Pause Media key
KEY_OEM_1 = 0xBA, // for US ";:"
KEY_PLUS = 0xBB, // Plus Key "+"
KEY_COMMA = 0xBC, // Comma Key ","

View File

@ -79,6 +79,12 @@ struct SExposedVideoData
void* X11Context;
unsigned long X11Window;
} OpenGLLinux;
struct
{
//! The ANativeWindow object.
void* Window;
} OGLESAndroid;
};
};

View File

@ -195,6 +195,20 @@ For functions: template<class T> _IRR_DEPRECATED_ void test4(void) {}
#define _IRR_DEPRECATED_
#endif
//! Defines an override macro, to protect virtual functions from typos and other mismatches
/** Usage in a derived class:
virtual void somefunc() _IRR_OVERRIDE_;
*/
#if ( ((__GNUC__ > 4 ) || ((__GNUC__ == 4 ) && (__GNUC_MINOR__ >= 7))) && (defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L) )
#define _IRR_OVERRIDE_ override
#elif (_MSC_VER >= 1600 ) /* supported since MSVC 2010 */
#define _IRR_OVERRIDE_ override
#elif (__clang_major__ >= 3)
#define _IRR_OVERRIDE_ override
#else
#define _IRR_OVERRIDE_
#endif
//! Defines a small statement to work around a microsoft compiler bug.
/** The microsoft compiler 7.0 - 7.1 has a bug:
When you call unmanaged code that returns a bool type value of false from managed code,

View File

@ -1312,7 +1312,6 @@ bool CIrrDeviceLinux::createInputContext()
XSetICFocus(XInputContext);
setlocale(LC_CTYPE, oldLocale.c_str());
XFree(p);
return true;
}

View File

@ -124,10 +124,9 @@ namespace video
#endif
};
EGLConfig config;
EGLint num_configs;
u32 steps=5;
while (!eglChooseConfig(EglDisplay, attribs, &config, 1, &num_configs) || !num_configs)
while (!eglChooseConfig(EglDisplay, attribs, &EglConfig, 1, &num_configs) || !num_configs)
{
switch (steps)
{
@ -208,16 +207,16 @@ namespace video
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
EGLint format;
eglGetConfigAttrib(EglDisplay, config, EGL_NATIVE_VISUAL_ID, &format);
eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format);
#endif
os::Printer::log(" Creating EglSurface with nativeWindow...");
EglSurface = eglCreateWindowSurface(EglDisplay, config, EglWindow, NULL);
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL);
if (EGL_NO_SURFACE == EglSurface)
{
os::Printer::log("FAILED\n");
EglSurface = eglCreateWindowSurface(EglDisplay, config, NULL, NULL);
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, NULL, NULL);
os::Printer::log("Creating EglSurface without nativeWindows...");
}
else
@ -249,7 +248,7 @@ namespace video
EGL_NONE, 0
};
EglContext = eglCreateContext(EglDisplay, config, EGL_NO_CONTEXT, contextAttrib);
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
}
if (EGL_NO_CONTEXT == EglContext)
@ -264,7 +263,7 @@ namespace video
EGL_NONE, 0
};
EglContext = eglCreateContext(EglDisplay, config, EGL_NO_CONTEXT, contextAttrib);
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("FAILED\n");
@ -375,6 +374,32 @@ namespace video
// METHODS
// -----------------------------------------------------------------------
void COGLES2Driver::reloadEGLSurface(void* window)
{
os::Printer::log("Reload EGL surface.");
#ifdef EGL_VERSION_1_0
#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
EglWindow = (ANativeWindow*)window;
#endif
if (!EglWindow)
os::Printer::log("Invalid Egl window.");
eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(EglDisplay, EglSurface);
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0);
if (EGL_NO_SURFACE == EglSurface)
os::Printer::log("Could not create EGL surface.");
eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext);
#endif
}
bool COGLES2Driver::genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer)
{
Name = glGetString(GL_VERSION);

View File

@ -381,6 +381,8 @@ namespace video
//! Get bridge calls.
COGLES2CallBridge* getBridgeCalls() const;
void reloadEGLSurface(void* window);
private:
// Bridge calls.
COGLES2CallBridge* BridgeCalls;
@ -477,6 +479,7 @@ namespace video
void* EglDisplay;
void* EglSurface;
void* EglContext;
EGLConfig EglConfig;
#endif
SIrrlichtCreationParameters Params;

View File

@ -14,9 +14,13 @@
#if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__)
#include <sys/param.h>
#include <sys/types.h>
#ifdef ANDROID
#include <linux/sysctl.h>
#else
#include <sys/sysctl.h>
#endif
#endif
#endif
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
#include "CIrrDeviceLinux.h"

View File

@ -105,11 +105,8 @@ namespace irr
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %d", __FILE__, __LINE__);
if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST)) {
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %d", __FILE__, __LINE__);
dev = new CIrrDeviceAndroid(params);
}
if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceAndroid(params);
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_

View File

@ -181,7 +181,7 @@ namespace os
void Printer::log(const c8* message, ELOG_LEVEL ll)
{
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s", message);
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s", message);
#endif
if (Logger)
Logger->log(message, ll);
@ -192,7 +192,7 @@ namespace os
#ifdef _IRR_ANDROID_PLATFORM_
char test[200];
wcstombs(test, message, 200);
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s", test);
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s", test);
#endif
if (Logger)
Logger->log(message, ll);
@ -201,7 +201,7 @@ namespace os
void Printer::log(const c8* message, const c8* hint, ELOG_LEVEL ll)
{
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %s", message, hint);
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s %s", message, hint);
#endif
if (Logger)
Logger->log(message, hint, ll);
@ -210,7 +210,7 @@ namespace os
void Printer::log(const c8* message, const io::path& hint, ELOG_LEVEL ll)
{
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %s", message, core::stringc(hint).c_str());
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s %s", message, core::stringc(hint).c_str());
#endif
if (Logger)
Logger->log(message, hint.c_str(), ll);

View File

@ -1,5 +1,5 @@
# Modify this file to change the last-modified date when you add/remove a file.
# This will then trigger a new cmake run automatically.
# This will then trigger a new cmake run automatically.
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")

View File

@ -23,26 +23,25 @@
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<InstanceDataSingleTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataSingleTex &instance)
void InstanceFiller<InstanceDataSingleTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataSingleTex& instance)
{
fillOriginOrientationScale<InstanceDataSingleTex>(node, instance);
fillOriginOrientationScale<InstanceDataSingleTex>(STK::tuple_get<0>(is), instance);
instance.Texture = mesh->TextureHandles[0];
}
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<InstanceDataDualTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataDualTex &instance)
void InstanceFiller<InstanceDataThreeTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataThreeTex& instance)
{
fillOriginOrientationScale<InstanceDataDualTex>(node, instance);
instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1];
}
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<InstanceDataThreeTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataThreeTex &instance)
{
fillOriginOrientationScale<InstanceDataThreeTex>(node, instance);
fillOriginOrientationScale<InstanceDataThreeTex>(STK::tuple_get<0>(is), instance);
instance.MiscData.X = STK::tuple_get<1>(is).X;
instance.MiscData.Y = STK::tuple_get<1>(is).Y;
instance.MiscData.Z = STK::tuple_get<2>(is).X;
instance.MiscData.W = STK::tuple_get<2>(is).Y;
instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1];
instance.ThirdTexture = mesh->TextureHandles[2];
@ -50,8 +49,28 @@ void InstanceFiller<InstanceDataThreeTex>::add(GLMesh *mesh, scene::ISceneNode *
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<GlowInstanceData>::add(GLMesh *mesh, scene::ISceneNode *node, GlowInstanceData &instance)
void InstanceFiller<InstanceDataFourTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataFourTex& instance)
{
fillOriginOrientationScale<InstanceDataFourTex>(STK::tuple_get<0>(is), instance);
instance.MiscData.X = STK::tuple_get<1>(is).X;
instance.MiscData.Y = STK::tuple_get<1>(is).Y;
instance.MiscData.Z = STK::tuple_get<2>(is).X;
instance.MiscData.W = STK::tuple_get<2>(is).Y;
instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1];
instance.ThirdTexture = mesh->TextureHandles[2];
instance.FourthTexture = mesh->TextureHandles[3];
}
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<GlowInstanceData>::add(GLMesh* mesh,
const InstanceSettings& is,
GlowInstanceData& instance)
{
scene::ISceneNode* node = STK::tuple_get<0>(is);
fillOriginOrientationScale<GlowInstanceData>(node, instance);
STKMeshSceneNode *nd = dynamic_cast<STKMeshSceneNode*>(node);
instance.Color = nd->getGlowColor().color;
@ -142,25 +161,24 @@ void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map)
if(!CVS->supportsAsyncInstanceUpload())
mapIndirectBuffer();
std::vector<int> dual_tex_material_list =
std::vector<int> three_tex_material_list =
createVector<int>(Material::SHADERTYPE_SOLID,
Material::SHADERTYPE_ALPHA_TEST,
Material::SHADERTYPE_SOLID_UNLIT,
Material::SHADERTYPE_SPHERE_MAP,
Material::SHADERTYPE_VEGETATION);
fillInstanceData<InstanceDataDualTex, SolidPassMeshMap>
(mesh_map, dual_tex_material_list, InstanceTypeDualTex);
std::vector<int> three_tex_material_list =
createVector<int>(Material::SHADERTYPE_DETAIL_MAP,
Material::SHADERTYPE_NORMAL_MAP);
fillInstanceData<InstanceDataThreeTex, SolidPassMeshMap>
(mesh_map, three_tex_material_list, InstanceTypeThreeTex);
std::vector<int> four_tex_material_list =
createVector<int>(Material::SHADERTYPE_DETAIL_MAP,
Material::SHADERTYPE_NORMAL_MAP);
fillInstanceData<InstanceDataFourTex, SolidPassMeshMap>
(mesh_map, four_tex_material_list, InstanceTypeFourTex);
if (!CVS->supportsAsyncInstanceUpload())
glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER);
} //SolidCommandBuffer::fill

View File

@ -31,15 +31,17 @@
#include <array>
#include <unordered_map>
typedef STK::Tuple<scene::ISceneNode*, core::vector2df, core::vector2df> InstanceSettings;
struct InstanceList
{
GLMesh *m_mesh;
std::vector<irr::scene::ISceneNode*> m_scene_nodes;
std::vector<InstanceSettings> m_instance_settings;
};
typedef std::unordered_map <std::pair<scene::IMeshBuffer*, RenderInfo*>, InstanceList,
MeshRenderInfoHash, MeshRenderInfoEquals> SolidPassMeshMap;
typedef std::unordered_map <irr::scene::IMeshBuffer *, InstanceList > OtherMeshMap;
// ----------------------------------------------------------------------------
@ -69,7 +71,7 @@ void fillOriginOrientationScale(scene::ISceneNode *node, InstanceData &instance)
template<typename InstanceData>
struct InstanceFiller
{
static void add(GLMesh *, scene::ISceneNode *, InstanceData &);
static void add(GLMesh *, const InstanceSettings&, InstanceData &);
};
// ----------------------------------------------------------------------------
@ -84,7 +86,7 @@ struct InstanceFiller
* \param[in,out] poly_count Number of triangles. Will be updated.
*/
template<typename T>
void FillInstances_impl(InstanceList instance_list,
void FillInstances_impl(const InstanceList& instance_list,
T * instance_buffer,
DrawElementsIndirectCommand *command_buffer,
size_t &instance_buffer_offset,
@ -95,11 +97,11 @@ void FillInstances_impl(InstanceList instance_list,
GLMesh *mesh = instance_list.m_mesh;
size_t initial_offset = instance_buffer_offset;
for (unsigned i = 0; i < instance_list.m_scene_nodes.size(); i++)
for (unsigned i = 0; i < instance_list.m_instance_settings.size(); i++)
{
scene::ISceneNode *node = instance_list.m_scene_nodes[i];
InstanceFiller<T>::add(mesh, node, instance_buffer[instance_buffer_offset++]);
assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataDualTex));
InstanceFiller<T>::add(mesh, instance_list.m_instance_settings[i],
instance_buffer[instance_buffer_offset++]);
assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataThreeTex));
}
DrawElementsIndirectCommand &CurrentCommand = command_buffer[command_buffer_offset++];
@ -229,7 +231,7 @@ protected:
VAOManager::getInstance()->getInstanceBuffer(instance_type));
instance_buffer = (InstanceData*)
glMapBufferRange(GL_ARRAY_BUFFER, 0,
10000 * sizeof(InstanceDataDualTex),
10000 * sizeof(InstanceDataThreeTex),
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
}
@ -300,12 +302,14 @@ public:
#endif
TexExpander<typename T::InstancedFirstPassShader>::template
expandTex(*mesh, T::FirstPassTextures);
if (!mesh->mb->getMaterial().BackfaceCulling)
glDisable(GL_CULL_FACE);
glDrawElementsIndirect(GL_TRIANGLES,
GL_UNSIGNED_SHORT,
(const void*)((m_offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand)));
}
if (!mesh->mb->getMaterial().BackfaceCulling)
glEnable(GL_CULL_FACE);
}
} //drawIndirectFirstPass
// ----------------------------------------------------------------------------
@ -355,29 +359,13 @@ public:
{
GLMesh *mesh = m_meshes[T::MaterialType][i];
expandTexSecondPass<T>(*mesh, prefilled_tex);
//TODO: next 10 lines are duplicated in draw_tools.hpp (see CustomUnrollArgs::drawMesh)
//TODO: find a way to remove duplicated code
const bool support_change_hue = (mesh->m_render_info != NULL &&
mesh->m_material != NULL);
const bool need_change_hue =
(support_change_hue && mesh->m_render_info->getHue() > 0.0f);
if (need_change_hue)
{
T::InstancedSecondPassShader::getInstance()->changeableColor
(mesh->m_render_info->getHue(),
mesh->m_material->getColorizationFactor());
}
if (!mesh->mb->getMaterial().BackfaceCulling)
glDisable(GL_CULL_FACE);
glDrawElementsIndirect(GL_TRIANGLES,
GL_UNSIGNED_SHORT,
(const void*)((m_offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand)));
if (need_change_hue)
{
// Reset after changing
T::InstancedSecondPassShader::getInstance()->changeableColor();
}
if (!mesh->mb->getMaterial().BackfaceCulling)
glEnable(GL_CULL_FACE);
}
} //drawIndirectSecondPass

View File

@ -27,26 +27,11 @@
#include "graphics/stk_billboard.hpp"
#include "graphics/stk_mesh.hpp"
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_scene_manager.hpp"
#include "graphics/vao_manager.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
#include "utils/profiler.hpp"
using namespace irr;
namespace
{
void FixBoundingBoxes(scene::ISceneNode* node)
{
for (scene::ISceneNode *child : node->getChildren())
{
FixBoundingBoxes(child);
const_cast<core::aabbox3df&>(node->getBoundingBox()).addInternalBox(child->getBoundingBox());
}
}
} //namespace
// ----------------------------------------------------------------------------
void DrawCalls::clearLists()
{
@ -74,27 +59,16 @@ void DrawCalls::clearLists()
}
// ----------------------------------------------------------------------------
void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
std::vector<scene::ISceneNode *> *ImmediateDraw,
const scene::ICameraSceneNode *cam,
scene::ICameraSceneNode *shadowcam[4],
const scene::ICameraSceneNode *rsmcam,
bool &culledforcam,
bool culledforshadowcam[4],
bool &culledforrsm,
bool drawRSM)
bool DrawCalls::isCulledPrecise(const scene::ICameraSceneNode *cam,
const scene::ISceneNode* node,
bool visualization)
{
STKMeshCommon *node = dynamic_cast<STKMeshCommon*>(Node);
if (!node)
return;
node->updateNoGL();
m_deferred_update.push_back(node);
const core::matrix4 &trans = Node->getAbsoluteTransformation();
if (!node->getAutomaticCulling() && !visualization)
return false;
const core::matrix4 &trans = node->getAbsoluteTransformation();
core::vector3df edges[8];
Node->getBoundingBox().getEdges(edges);
node->getBoundingBox().getEdges(edges);
for (unsigned i = 0; i < 8; i++)
trans.transformVect(edges[i]);
@ -109,35 +83,119 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
0---------4/
*/
if (irr_driver->getBoundingBoxesViz())
if (visualization)
{
addEdge(edges[0], edges[1]);
addEdge(edges[1], edges[5]);
addEdge(edges[5], edges[4]);
addEdge(edges[4], edges[0]);
addEdge(edges[2], edges[3]);
addEdge(edges[3], edges[7]);
addEdge(edges[7], edges[6]);
addEdge(edges[6], edges[2]);
addEdge(edges[0], edges[2]);
addEdge(edges[1], edges[3]);
addEdge(edges[5], edges[7]);
addEdge(edges[4], edges[6]);
addEdgeForViz(edges[0], edges[1]);
addEdgeForViz(edges[1], edges[5]);
addEdgeForViz(edges[5], edges[4]);
addEdgeForViz(edges[4], edges[0]);
addEdgeForViz(edges[2], edges[3]);
addEdgeForViz(edges[3], edges[7]);
addEdgeForViz(edges[7], edges[6]);
addEdgeForViz(edges[6], edges[2]);
addEdgeForViz(edges[0], edges[2]);
addEdgeForViz(edges[1], edges[3]);
addEdgeForViz(edges[5], edges[7]);
addEdgeForViz(edges[4], edges[6]);
if (!node->getAutomaticCulling())
{
return false;
}
}
const scene::SViewFrustum &frust = *cam->getViewFrustum();
for (s32 i = 0; i < scene::SViewFrustum::VF_PLANE_COUNT; i++)
{
if (isBoxInFrontOfPlane(frust.planes[i], edges))
{
return true;
}
}
return false;
} // isCulledPrecise
// ----------------------------------------------------------------------------
bool DrawCalls::isBoxInFrontOfPlane(const core::plane3df &plane,
const core::vector3df* edges)
{
for (u32 i = 0; i < 8; i++)
{
if (plane.classifyPointRelation(edges[i]) != core::ISREL3D_FRONT)
return false;
}
return true;
} // isBoxInFrontOfPlane
// ----------------------------------------------------------------------------
void DrawCalls::addEdgeForViz(const core::vector3df &p0,
const core::vector3df &p1)
{
m_bounding_boxes.push_back(p0.X);
m_bounding_boxes.push_back(p0.Y);
m_bounding_boxes.push_back(p0.Z);
m_bounding_boxes.push_back(p1.X);
m_bounding_boxes.push_back(p1.Y);
m_bounding_boxes.push_back(p1.Z);
} // addEdgeForViz
// ----------------------------------------------------------------------------
void DrawCalls::renderBoundingBoxes()
{
Shaders::ColoredLine *line = Shaders::ColoredLine::getInstance();
line->use();
line->bindVertexArray();
line->bindBuffer();
line->setUniforms(irr::video::SColor(255, 255, 0, 0));
const float *tmp = m_bounding_boxes.data();
for (unsigned int i = 0; i < m_bounding_boxes.size(); i += 1024 * 6)
{
unsigned count = std::min((unsigned)m_bounding_boxes.size() - i,
(unsigned)1024 * 6);
glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]);
glDrawArrays(GL_LINES, 0, count / 3);
}
m_bounding_boxes.clear();
} // renderBoundingBoxes
// ----------------------------------------------------------------------------
void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
std::vector<scene::ISceneNode *> *ImmediateDraw,
const scene::ICameraSceneNode *cam,
ShadowMatrices& shadow_matrices)
{
STKMeshCommon* node = dynamic_cast<STKMeshCommon*>(Node);
if (!node)
return;
node->updateNoGL();
m_deferred_update.push_back(node);
if (node->isImmediateDraw())
{
ImmediateDraw->push_back(Node);
return;
}
culledforcam = culledforcam || isCulledPrecise(cam, Node);
culledforrsm = culledforrsm || isCulledPrecise(rsmcam, Node);
for (unsigned i = 0; i < 4; i++)
culledforshadowcam[i] = culledforshadowcam[i] || isCulledPrecise(shadowcam[i], Node);
bool culled_for_cams[6] = { true, true, true, true, true, true };
culled_for_cams[0] = isCulledPrecise(cam, Node,
irr_driver->getBoundingBoxesViz());
if (UserConfigParams::m_gi && !shadow_matrices.isRSMMapAvail())
{
culled_for_cams[1] = isCulledPrecise(shadow_matrices.getSunCam(), Node);
}
if (CVS->isShadowEnabled())
{
for (unsigned i = 0; i < 4; i++)
{
culled_for_cams[i + 2] =
isCulledPrecise(shadow_matrices.getShadowCamNodes()[i], Node);
}
}
// Transparent
if (World::getWorld() && World::getWorld()->isFogEnabled())
{
const Track * const track = World::getWorld()->getTrack();
@ -155,18 +213,18 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
tmpcol.getBlue() / 255.0f);
for (GLMesh *mesh : node->TransparentMesh[TM_DEFAULT])
pushVector(ListBlendTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix,
pushVector(ListBlendTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans,
fogmax, startH, endH, start, end, col);
for (GLMesh *mesh : node->TransparentMesh[TM_ADDITIVE])
pushVector(ListAdditiveTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix,
pushVector(ListAdditiveTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans,
fogmax, startH, endH, start, end, col);
}
else
{
for (GLMesh *mesh : node->TransparentMesh[TM_DEFAULT])
pushVector(ListBlendTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, 1.0f);
pushVector(ListBlendTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, 1.0f);
for (GLMesh *mesh : node->TransparentMesh[TM_ADDITIVE])
pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, 1.0f);
pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, 1.0f);
}
// Use sun color to determine custom alpha for ghost karts
@ -179,15 +237,15 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
}
for (GLMesh *mesh : node->TransparentMesh[TM_TRANSLUCENT_STD])
pushVector(ListTranslucentStandard::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha);
pushVector(ListTranslucentStandard::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, custom_alpha);
for (GLMesh *mesh : node->TransparentMesh[TM_TRANSLUCENT_TAN])
pushVector(ListTranslucentTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha);
pushVector(ListTranslucentTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, custom_alpha);
for (GLMesh *mesh : node->TransparentMesh[TM_TRANSLUCENT_2TC])
pushVector(ListTranslucent2TCoords::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha);
pushVector(ListTranslucent2TCoords::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, custom_alpha);
for (GLMesh *mesh : node->TransparentMesh[TM_DISPLACEMENT])
pushVector(ListDisplacement::getInstance(), mesh, Node->getAbsoluteTransformation());
if (!culledforcam)
if (!culled_for_cams[0])
{
for (unsigned Mat = 0; Mat < Material::SHADERTYPE_COUNT; ++Mat)
{
@ -198,52 +256,28 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
if (node->glow())
{
m_glow_pass_mesh[mesh->mb].m_mesh = mesh;
m_glow_pass_mesh[mesh->mb].m_scene_nodes.emplace_back(Node);
m_glow_pass_mesh[mesh->mb].m_instance_settings
.emplace_back(Node, core::vector2df(0.0f, 0.0f), core::vector2df(0.0f, 0.0f));
}
if (Mat != Material::SHADERTYPE_SPLATTING && mesh->TextureMatrix.isIdentity())
if (Mat == Material::SHADERTYPE_SPLATTING)
{
std::pair<scene::IMeshBuffer*, RenderInfo*> meshRenderInfo(mesh->mb, mesh->m_render_info);
m_solid_pass_mesh[Mat][meshRenderInfo].m_mesh = mesh;
m_solid_pass_mesh[Mat][meshRenderInfo].m_scene_nodes.emplace_back(Node);
// Notice: splatting will be drawn using non-instanced shader only
// It's only used one place (in overworld) and may be removed eventually
core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix;
ModelMatrix.getInverse(InvModelMatrix);
ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix);
}
else
{
core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix;
ModelMatrix.getInverse(InvModelMatrix);
switch (Mat)
{
case Material::SHADERTYPE_SOLID:
ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
break;
case Material::SHADERTYPE_ALPHA_TEST:
ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
break;
case Material::SHADERTYPE_SOLID_UNLIT:
ListMatUnlit::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
break;
case Material::SHADERTYPE_SPLATTING:
ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix);
break;
case Material::SHADERTYPE_ALPHA_BLEND:
break;
case Material::SHADERTYPE_ADDITIVE:
break;
case Material::SHADERTYPE_VEGETATION:
break;
case Material::SHADERTYPE_WATER:
break;
case Material::SHADERTYPE_SPHERE_MAP:
break;
case Material::SHADERTYPE_NORMAL_MAP:
break;
case Material::SHADERTYPE_DETAIL_MAP:
break;
default:
Log::warn("DrawCalls", "Unknown material type: %d", Mat);
}
// Only take render info into account if the node is not static (animated)
// So they can have different animation
std::pair<scene::IMeshBuffer*, RenderInfo*> mesh_render_info(mesh->mb,
dynamic_cast<STKMeshSceneNode*>(Node) == NULL ? mesh->m_render_info : NULL);
m_solid_pass_mesh[Mat][mesh_render_info].m_mesh = mesh;
m_solid_pass_mesh[Mat][mesh_render_info].m_instance_settings.emplace_back(Node, mesh->texture_trans,
(mesh->m_render_info && mesh->m_material ?
core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) :
core::vector2df(0.0f, 0.0f)));
}
}
}
@ -257,37 +291,47 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
switch (Mat)
{
case Material::SHADERTYPE_SOLID:
ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans,
(mesh->m_render_info && mesh->m_material ?
core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) :
core::vector2df(0.0f, 0.0f)));
break;
case Material::SHADERTYPE_ALPHA_TEST:
ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans,
(mesh->m_render_info && mesh->m_material ?
core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) :
core::vector2df(0.0f, 0.0f)));
break;
case Material::SHADERTYPE_NORMAL_MAP:
ListMatNormalMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatNormalMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans,
(mesh->m_render_info && mesh->m_material ?
core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) :
core::vector2df(0.0f, 0.0f)));
break;
case Material::SHADERTYPE_DETAIL_MAP:
ListMatDetails::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatDetails::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SOLID_UNLIT:
ListMatUnlit::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatUnlit::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPHERE_MAP:
ListMatSphereMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatSphereMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPLATTING:
ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix);
break;
case Material::SHADERTYPE_VEGETATION:
ListMatGrass::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, m_wind_dir);
ListMatGrass::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, m_wind_dir,
(mesh->m_render_info && mesh->m_material ?
core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) :
core::vector2df(0.0f, 0.0f)));
break;
case Material::SHADERTYPE_ALPHA_BLEND:
break;
case Material::SHADERTYPE_ADDITIVE:
break;
case Material::SHADERTYPE_WATER:
break;
default:
Log::warn("DrawCalls", "Unknown material type: %d", Mat);
}
@ -299,7 +343,7 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
return;
for (unsigned cascade = 0; cascade < 4; ++cascade)
{
if (culledforshadowcam[cascade])
if (culled_for_cams[cascade + 2])
continue;
for (unsigned Mat = 0; Mat < Material::SHADERTYPE_COUNT; ++Mat)
{
@ -308,7 +352,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
{
m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_mesh = mesh;
m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_scene_nodes.emplace_back(Node);
m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_instance_settings
.emplace_back(Node, core::vector2df(0.0f, 0.0f), core::vector2df(0.0f, 0.0f));
}
}
else
@ -321,36 +366,34 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
switch (Mat)
{
case Material::SHADERTYPE_SOLID:
ListMatDefault::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatDefault::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_ALPHA_TEST:
ListMatAlphaRef::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatAlphaRef::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_NORMAL_MAP:
ListMatNormalMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatNormalMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_DETAIL_MAP:
ListMatDetails::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatDetails::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SOLID_UNLIT:
ListMatUnlit::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatUnlit::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPHERE_MAP:
ListMatSphereMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatSphereMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPLATTING:
ListMatSplatting::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix);
break;
case Material::SHADERTYPE_VEGETATION:
ListMatGrass::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, m_wind_dir);
ListMatGrass::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, m_wind_dir, core::vector2df(0.0f, 0.0f));
case Material::SHADERTYPE_ALPHA_BLEND:
break;
case Material::SHADERTYPE_ADDITIVE:
break;
case Material::SHADERTYPE_WATER:
break;
default:
Log::warn("DrawCalls", "Unknown material type: %d", Mat);
}
@ -358,33 +401,32 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
}
}
}
if (!UserConfigParams::m_gi || !drawRSM)
if (!UserConfigParams::m_gi || shadow_matrices.isRSMMapAvail())
return;
if (!culledforrsm)
if (!culled_for_cams[1])
{
for (unsigned Mat = 0; Mat < Material::SHADERTYPE_COUNT; ++Mat)
{
if (CVS->supportsIndirectInstancingRendering())
{
if (Mat == Material::SHADERTYPE_SPLATTING)
for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
{
if (Mat == Material::SHADERTYPE_SPLATTING)
{
core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix;
ModelMatrix.getInverse(InvModelMatrix);
ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix);
}
else
{
for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix);
}
else
{
m_reflective_shadow_map_mesh[Mat][mesh->mb].m_mesh = mesh;
m_reflective_shadow_map_mesh[Mat][mesh->mb].m_scene_nodes.emplace_back(Node);
m_reflective_shadow_map_mesh[Mat][mesh->mb].m_instance_settings
.emplace_back(Node, core::vector2df(0.0f, 0.0f), core::vector2df(0.0f, 0.0f));
}
}
}
else
{
core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix;
ModelMatrix.getInverse(InvModelMatrix);
@ -393,37 +435,35 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
switch (Mat)
{
case Material::SHADERTYPE_SOLID:
ListMatDefault::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatDefault::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_ALPHA_TEST:
ListMatAlphaRef::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatAlphaRef::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_NORMAL_MAP:
ListMatNormalMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatNormalMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_DETAIL_MAP:
ListMatDetails::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatDetails::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SOLID_UNLIT:
ListMatUnlit::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatUnlit::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPHERE_MAP:
ListMatSphereMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix);
ListMatSphereMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPLATTING:
ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix);
break;
case Material::SHADERTYPE_VEGETATION:
ListMatGrass::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, m_wind_dir);
ListMatGrass::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, m_wind_dir, core::vector2df(0.0f, 0.0f));
break;
case Material::SHADERTYPE_ALPHA_BLEND:
break;
case Material::SHADERTYPE_ADDITIVE:
break;
case Material::SHADERTYPE_WATER:
break;
default:
Log::warn("DrawCalls", "Unknown material type: %d", Mat);
}
@ -433,16 +473,11 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
}
}
// ----------------------------------------------------------------------------
void DrawCalls::parseSceneManager(core::list<scene::ISceneNode*> &List,
std::vector<scene::ISceneNode *> *ImmediateDraw,
const scene::ICameraSceneNode* cam,
scene::ICameraSceneNode *shadow_cam[4],
const scene::ICameraSceneNode *rsmcam,
bool culledforcam,
bool culledforshadowcam[4],
bool culledforrsm,
bool drawRSM)
const scene::ICameraSceneNode *cam,
ShadowMatrices& shadow_matrices)
{
core::list<scene::ISceneNode*>::Iterator I = List.begin(), E = List.end();
for (; I != E; ++I)
@ -467,13 +502,9 @@ void DrawCalls::parseSceneManager(core::list<scene::ISceneNode*> &List,
continue;
}
bool newculledforcam = culledforcam;
bool newculledforrsm = culledforrsm;
bool newculledforshadowcam[4] = { culledforshadowcam[0], culledforshadowcam[1], culledforshadowcam[2], culledforshadowcam[3] };
handleSTKCommon(*I, ImmediateDraw, cam, shadow_cam, rsmcam, newculledforcam, newculledforshadowcam, newculledforrsm, drawRSM);
parseSceneManager(const_cast<core::list<scene::ISceneNode*>& >((*I)->getChildren()), ImmediateDraw, cam, shadow_cam, rsmcam, newculledforcam, newculledforshadowcam, newculledforrsm, drawRSM);
handleSTKCommon((*I), ImmediateDraw, cam, shadow_matrices);
parseSceneManager((*I)->getChildren(), ImmediateDraw, cam,
shadow_matrices);
}
}
@ -508,15 +539,13 @@ DrawCalls::~DrawCalls()
#endif // !defined(USE_GLES2)
} //~DrawCalls
// ----------------------------------------------------------------------------
/** Prepare draw calls before scene rendering
* \param[out] solid_poly_count Total number of polygons in objects
* that will be rendered in this frame
* \param[out] shadow_poly_count Total number of polygons for shadow
* (rendered this frame)
*/
*/
void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices,
scene::ICameraSceneNode *camnode,
unsigned &solid_poly_count,
@ -535,23 +564,11 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices,
m_glow_pass_mesh.clear();
m_deferred_update.clear();
core::list<scene::ISceneNode*> List = irr_driver->getSceneManager()->getRootSceneNode()->getChildren();
PROFILER_PUSH_CPU_MARKER("- culling", 0xFF, 0xFF, 0x0);
for (scene::ISceneNode *child : List)
FixBoundingBoxes(child);
bool cam = false, rsmcam = false;
bool shadowcam[4] = { false, false, false, false };
parseSceneManager(List,
&m_immediate_draw_list,
camnode,
shadow_matrices.getShadowCamNodes(),
shadow_matrices.getSunCam(),
cam, shadowcam, rsmcam,
!shadow_matrices.isRSMMapAvail());
parseSceneManager(
irr_driver->getSceneManager()->getRootSceneNode()->getChildren(),
&m_immediate_draw_list, camnode, shadow_matrices);
PROFILER_POP_CPU_MARKER();
// Add a 1 s timeout

View File

@ -38,6 +38,8 @@ private:
std::vector<STKBillboard *> m_billboard_list;
std::vector<ParticleSystemProxy *> m_particles_list;
std::vector<float> m_bounding_boxes;
/** meshes to draw */
SolidPassMeshMap m_solid_pass_mesh [ Material::SHADERTYPE_COUNT];
OtherMeshMap m_shadow_pass_mesh [4 * Material::SHADERTYPE_COUNT];
@ -57,23 +59,22 @@ private:
void handleSTKCommon(scene::ISceneNode *Node,
std::vector<scene::ISceneNode *> *ImmediateDraw,
const scene::ICameraSceneNode *cam,
scene::ICameraSceneNode *shadowcam[4],
const scene::ICameraSceneNode *rsmcam,
bool &culledforcam,
bool culledforshadowcam[4],
bool &culledforrsm,
bool drawRSM);
void parseSceneManager(core::list<scene::ISceneNode*> &List,
std::vector<scene::ISceneNode *> *ImmediateDraw,
const scene::ICameraSceneNode* cam,
scene::ICameraSceneNode *shadow_cam[4],
const scene::ICameraSceneNode *rsmcam,
bool culledforcam,
bool culledforshadowcam[4],
bool culledforrsm,
bool drawRSM);
ShadowMatrices& shadow_matrices);
void parseSceneManager(core::list<scene::ISceneNode*> &List,
std::vector<scene::ISceneNode *> *ImmediateDraw,
const scene::ICameraSceneNode *cam,
ShadowMatrices& shadow_matrices);
bool isCulledPrecise(const scene::ICameraSceneNode *cam,
const scene::ISceneNode* node,
bool visualization = false);
bool isBoxInFrontOfPlane(const core::plane3df &plane,
const core::vector3df* edges);
void addEdgeForViz(const core::vector3df &p0, const core::vector3df &p1);
public:
DrawCalls();
~DrawCalls();
@ -104,7 +105,7 @@ public:
void drawIndirectGlow() const;
void multidrawGlow() const;
void renderBoundingBoxes();
};
#endif // !SERVER_ONLY

View File

@ -88,7 +88,48 @@ void renderMeshes2ndPass( const std::vector<uint64_t> &Prefilled_Handle,
}
} // renderMeshes2ndPass
// ----------------------------------------------------------------------------
template<>
void renderMeshes2ndPass<GrassMat, 4, 3, 1>
(const std::vector<uint64_t> &Prefilled_Handle,
const std::vector<GLuint> &Prefilled_Tex)
{
auto &meshes = GrassMat::List::getInstance()->SolidPass;
GrassMat::SecondPassShader::getInstance()->use();
if (CVS->isARBBaseInstanceUsable())
glBindVertexArray(VAOManager::getInstance()->getVAO(GrassMat::VertexType));
for (unsigned i = 0; i < meshes.size(); i++)
{
GLMesh &mesh = *(STK::tuple_get<0>(meshes.at(i)));
if (!CVS->isARBBaseInstanceUsable())
glBindVertexArray(mesh.vao);
if (mesh.VAOType != GrassMat::VertexType)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to pass 2 "
"(hint texture : %s)",
mesh.textures[0]->getName().getPath().c_str());
#endif
continue;
}
if (CVS->isAZDOEnabled())
{
HandleExpander<GrassMat::SecondPassShader>::
expand(mesh.TextureHandles, GrassMat::SecondPassTextures,
Prefilled_Handle[0], Prefilled_Handle[1],
Prefilled_Handle[2], Prefilled_Handle[3]);
}
else
{
TexExpander<GrassMat::SecondPassShader>::
expandTex(mesh, GrassMat::SecondPassTextures, Prefilled_Tex[0],
Prefilled_Tex[1], Prefilled_Tex[2], Prefilled_Tex[3]);
}
CustomUnrollArgs<4, 3, 1>::drawMesh<GrassMat::SecondPassShader>(meshes.at(i));
}
} // renderMeshes2ndPass
// ----------------------------------------------------------------------------
template<typename T, int...List>
@ -111,7 +152,6 @@ void renderShadow(unsigned cascade)
} // for i
} // renderShadow
// ----------------------------------------------------------------------------
template<typename T, int... Selector>
void drawRSM(const core::matrix4 & rsm_matrix)
@ -134,8 +174,6 @@ void drawRSM(const core::matrix4 & rsm_matrix)
}
} // drawRSM
// ----------------------------------------------------------------------------
void GL3DrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const
{
@ -154,14 +192,14 @@ void GL3DrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls,
const std::vector<uint64_t>& handles,
const std::vector<GLuint>& prefilled_tex) const
{
renderMeshes2ndPass<DefaultMaterial, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<AlphaRef, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<UnlitMat, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SphereMap, 2, 1> (handles, prefilled_tex);
renderMeshes2ndPass<DetailMat, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<GrassMat, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<NormalMat, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<DefaultMaterial, 4, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<AlphaRef, 4, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<UnlitMat, 3, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SphereMap, 2, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<DetailMat, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<GrassMat, 4, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<NormalMat, 4, 3, 1> (handles, prefilled_tex);
}
// ----------------------------------------------------------------------------
@ -203,13 +241,7 @@ void GL3DrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
void IndirectDrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const
{
#if !defined(USE_GLES2)
//TODO: find a way to add TextureMarix in instanced shaders,
//and remove these four lines
renderMeshes1stPass<DefaultMaterial, 2, 1>();
renderMeshes1stPass<SplattingMat, 2, 1>();
renderMeshes1stPass<UnlitMat, 3, 2, 1>();
renderMeshes1stPass<AlphaRef, 3, 2, 1>();
draw_calls.drawIndirectSolidFirstPass();
#endif //!defined(USE_GLES2)
}
@ -220,13 +252,7 @@ void IndirectDrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls,
const std::vector<GLuint>& prefilled_tex) const
{
#if !defined(USE_GLES2)
//TODO: find a way to add TextureMatrix in instanced shaders,
//and remove these four lines
renderMeshes2ndPass<DefaultMaterial, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<AlphaRef, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<UnlitMat, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1> (handles, prefilled_tex);
draw_calls.drawIndirectSolidSecondPass(prefilled_tex);
#endif //!defined(USE_GLES2)
}
@ -266,7 +292,7 @@ void IndirectDrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
const core::matrix4 &rsm_matrix) const
{
#if !defined(USE_GLES2)
drawRSM<SplattingMat, 1>(rsm_matrix); //TODO: write instanced splatting RSM shader and remove this line
drawRSM<SplattingMat, 1>(rsm_matrix);
draw_calls.drawIndirectReflectiveShadowMaps(rsm_matrix);
#endif //!defined(USE_GLES2)
}
@ -276,13 +302,7 @@ void IndirectDrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
void MultidrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const
{
#if !defined(USE_GLES2)
//TODO: find a way to add TextureMarix in instanced shaders,
//and remove these four lines
renderMeshes1stPass<DefaultMaterial, 2, 1>();
renderMeshes1stPass<SplattingMat, 2, 1>();
renderMeshes1stPass<UnlitMat, 3, 2, 1>();
renderMeshes1stPass<AlphaRef, 3, 2, 1>();
draw_calls.multidrawSolidFirstPass();
#endif //!defined(USE_GLES2)
}
@ -293,13 +313,7 @@ void MultidrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls,
const std::vector<GLuint>& prefilled_tex) const
{
#if !defined(USE_GLES2)
//TODO: find a way to add TextureMarix in instanced shaders,
//and remove these four lines
renderMeshes2ndPass<DefaultMaterial, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<AlphaRef, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<UnlitMat, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1> (handles, prefilled_tex);
draw_calls.multidrawSolidSecondPass(handles);
#endif //!defined(USE_GLES2)
}
@ -334,7 +348,7 @@ void MultidrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
const core::matrix4 &rsm_matrix) const
{
#if !defined(USE_GLES2)
drawRSM<SplattingMat, 1>(rsm_matrix); //TODO: add instanced splatting RSM shader
drawRSM<SplattingMat, 1>(rsm_matrix);
draw_calls.multidrawReflectiveShadowMaps(rsm_matrix);
#endif //!defined(USE_GLES2)
}

View File

@ -64,37 +64,19 @@ struct CustomUnrollArgs<>
{
irr_driver->increaseObjectCount(); //TODO: move somewhere else
GLMesh *mesh = STK::tuple_get<0>(t);
//shadow_custom_unroll_args, rsm_custom_unroll_args and custom_unroll_args
// have been merged in order to avoid duplicated code.
// don't need to call change color things for shadows and rsm
//TODO: don't call next 10 lines for shadow/rsm shaders?
const bool support_change_hue = (mesh->m_render_info != NULL &&
mesh->m_material != NULL);
const bool need_change_hue = (support_change_hue &&
mesh->m_render_info->getHue() > 0.0f);
if (need_change_hue)
{
S::getInstance()->changeableColor(mesh->m_render_info->getHue(),
mesh->m_material->getColorizationFactor());
}
if (!mesh->mb->getMaterial().BackfaceCulling)
glDisable(GL_CULL_FACE);
S::getInstance()->setUniforms(args...);
glDrawElementsBaseVertex(mesh->PrimitiveType,
(int)mesh->IndexCount,
mesh->IndexType,
(GLvoid *)mesh->vaoOffset,
(int)mesh->vaoBaseVertex);
if (need_change_hue)
{
// Reset after changing
S::getInstance()->changeableColor();
}
if (!mesh->mb->getMaterial().BackfaceCulling)
glEnable(GL_CULL_FACE);
} // drawMesh
}; // CustomUnrollArgs
// ----------------------------------------------------------------------------
/** Variadic template to implement TexExpander*/
template<typename T, int N>

View File

@ -24,7 +24,6 @@
#include "graphics/post_processing.hpp"
#include "graphics/rtts.hpp"
#include "graphics/shaders.hpp"
#include "graphics/stk_scene_manager.hpp"
#include "modes/world.hpp"
#include "utils/tuple.hpp"
#include <SColor.h>
@ -182,23 +181,15 @@ AbstractGeometryPasses::AbstractGeometryPasses()
}
// ----------------------------------------------------------------------------
void AbstractGeometryPasses::setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures)
void AbstractGeometryPasses::setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures,
const std::vector<uint64_t>& prefilled_handles)
{
m_prefilled_textures = prefilled_textures;
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
m_textures_handles.clear();
for(size_t i=0;i<m_prefilled_textures.size();i++)
{
uint64_t handle = 0;
handle = glGetTextureSamplerHandleARB(m_prefilled_textures[i],
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[i]);
if (!glIsTextureHandleResidentARB(handle))
glMakeTextureHandleResidentARB(handle);
m_textures_handles.push_back(handle);
}
m_textures_handles = prefilled_handles;
}
#endif // !defined(USE_GLES2)
}

View File

@ -11,7 +11,7 @@
// 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
// 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.
@ -47,7 +47,8 @@ public:
AbstractGeometryPasses();
virtual ~AbstractGeometryPasses(){}
void setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures);
void setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures,
const std::vector<uint64_t>& prefilled_handles);
virtual void renderSolidFirstPass(const DrawCalls& draw_calls) const = 0;

View File

@ -43,6 +43,7 @@ extern "C" {
# define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
# endif
#elif defined(USE_GLES2)
# define __gl2_h_
# include <GLES3/gl3.h>
# include <GLES3/gl3ext.h>
# include <GLES2/gl2ext.h>

View File

@ -37,7 +37,6 @@
#include "graphics/stk_animated_mesh.hpp"
#include "graphics/stk_billboard.hpp"
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_scene_manager.hpp"
#include "graphics/sun.hpp"
#include "graphics/texture_manager.hpp"
#include "guiengine/engine.hpp"
@ -93,6 +92,10 @@ using namespace irr;
#include <X11/Xutil.h>
#endif
#ifdef ANDROID
struct android_app* global_android_app;
#endif
/** singleton */
IrrDriver *irr_driver = NULL;
@ -116,13 +119,21 @@ IrrDriver::IrrDriver()
{
m_resolution_changing = RES_CHANGE_NONE;
m_phase = SOLID_NORMAL_AND_DEPTH_PASS;
m_device = createDevice(video::EDT_NULL,
irr::core::dimension2d<u32>(640, 480),
/*bits*/16U, /**fullscreen*/ false,
/*stencilBuffer*/ false,
/*vsync*/false,
/*event receiver*/ NULL,
file_manager->getFileSystem());
struct irr::SIrrlichtCreationParameters p;
p.DriverType = video::EDT_NULL;
p.WindowSize = core::dimension2d<u32>(640,480);
p.Bits = 16U;
p.Fullscreen = false;
p.Vsync = false;
p.EventReceiver = NULL;
p.FileSystem = file_manager->getFileSystem();
#ifdef ANDROID
p.PrivateData = (void*)global_android_app;
#endif
m_device = createDeviceEx(p);
m_request_screenshot = false;
m_renderer = NULL;
m_wind = new Wind();
@ -446,6 +457,9 @@ void IrrDriver::initDevice()
params.DriverType = video::EDT_OGLES2;
#else
params.DriverType = video::EDT_OPENGL;
#endif
#if defined(ANDROID)
params.PrivateData = (void*)global_android_app;
#endif
params.Stencilbuffer = false;
params.Bits = bits;
@ -727,7 +741,7 @@ void IrrDriver::createSunInterposer()
getUnicolorTexture(video::SColor(255, 255, 255, 255)));
mb->getMaterial().setTexture(1,
getUnicolorTexture(video::SColor(0, 0, 0, 0)));
mb->getMaterial().setTexture(7,
mb->getMaterial().setTexture(2,
getUnicolorTexture(video::SColor(0, 0, 0, 0)));
}
m_sun_interposer = new STKMeshSceneNode(sphere,
@ -1178,7 +1192,7 @@ scene::IMeshSceneNode *IrrDriver::addSphere(float radius,
//m.setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180)));
m.setTexture(0, getUnicolorTexture(color));
m.setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m.setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m.setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
if (CVS->isGLSL())
{

View File

@ -45,6 +45,12 @@
#include <string>
#include <vector>
#ifdef ANDROID
#include <android_native_app_glue.h>
extern struct android_app* global_android_app;
#endif
namespace irr
{

File diff suppressed because it is too large Load Diff

View File

@ -47,18 +47,19 @@ public:
void updateLightsInfo(irr::scene::ICameraSceneNode * const camnode,
float dt);
void renderRadianceHints( const ShadowMatrices& shadow_matrices,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer);
void renderGlobalIllumination( const ShadowMatrices& shadow_matrices,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer,
const FrameBuffer& diffuse_framebuffer,
GLuint normal_depth_texture,
GLuint depth_stencil_texture);
void renderLights( bool has_shadow,
GLuint normal_depth_texture,
GLuint depth_stencil_texture,
const FrameBuffer& shadow_framebuffer,
const FrameBuffer& diffuse_specular_framebuffer,
GLuint specular_probe);
void renderAmbientScatter(GLuint depth_stencil_texture);
void renderLightsScatter(GLuint depth_stencil_texture,

View File

@ -717,6 +717,10 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
}
#ifndef SERVER_ONLY
// Backface culling
if(!m_backface_culling)
m->setFlag(video::EMF_BACK_FACE_CULLING, false);
if (CVS->isGLSL())
{
ITexture *tex;
@ -730,7 +734,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
glossytex = getUnicolorTexture(SColor(0, 0, 0, 0));
}
if (!m->getTexture(7))
if (!m->getTexture(2))
{
// Only set colorization mask if not set
ITexture *colorization_mask_tex = getUnicolorTexture(SColor(0, 0, 0, 0));
@ -738,7 +742,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
{
colorization_mask_tex = irr_driver->getTexture(m_colorization_mask);
}
m->setTexture(7, colorization_mask_tex);
m->setTexture(2, colorization_mask_tex);
}
@ -793,26 +797,26 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
return;
case SHADERTYPE_SPLATTING:
tex = irr_driver->getTexture(m_splatting_texture_1);
m->setTexture(2, tex);
m->setTexture(3, tex);
if (m_splatting_texture_2.size() > 0)
{
tex = irr_driver->getTexture(m_splatting_texture_2);
}
m->setTexture(3, tex);
m->setTexture(4, tex);
if (m_splatting_texture_3.size() > 0)
{
tex = irr_driver->getTexture(m_splatting_texture_3);
}
m->setTexture(4, tex);
m->setTexture(5, tex);
if (m_splatting_texture_4.size() > 0)
{
tex = irr_driver->getTexture(m_splatting_texture_4);
}
m->setTexture(5, tex);
m->setTexture(6, glossytex);
m->setTexture(6, tex);
m->setTexture(7, glossytex);
// Material and shaders
m->MaterialType = Shaders::getShader(ES_SPLATTING);
@ -847,7 +851,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
if (m_normal_map_tex.size() > 0)
{
tex = irr_driver->getTexture(m_normal_map_tex);
m->setTexture(2, tex);
m->setTexture(3, tex);
// Material and shaders
m->MaterialType = Shaders::getShader(ES_NORMAL_MAP);
@ -860,9 +864,9 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
if (mb && mb->getVertexType() == video::EVT_2TCOORDS)
{
if (m->getTexture(1) != glossytex)
m->setTexture(2, m->getTexture(1));
if (!m->getTexture(2))
m->setTexture(2, getUnicolorTexture(SColor(255, 255, 255, 255)));
m->setTexture(3, m->getTexture(1));
if (!m->getTexture(3))
m->setTexture(3, getUnicolorTexture(SColor(255, 255, 255, 255)));
}
m->setTexture(1, glossytex);
}
@ -993,10 +997,6 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
}
}
// Backface culling
if(!m_backface_culling)
m->setFlag(video::EMF_BACK_FACE_CULLING, false);
// Material color
m->ColorMaterial = video::ECM_DIFFUSE_AND_AMBIENT;

View File

@ -22,15 +22,15 @@
const STK::Tuple<size_t> DefaultMaterial::FirstPassTextures
= STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> DefaultMaterial::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 7);
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<> DefaultMaterial::ShadowTextures;
const STK::Tuple<size_t> DefaultMaterial::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t, size_t> AlphaRef::FirstPassTextures
= STK::Tuple<size_t, size_t>(0, 1);
const STK::Tuple<size_t, size_t> AlphaRef::SecondPassTextures
= STK::Tuple<size_t, size_t>(0, 1);
const STK::Tuple<size_t, size_t, size_t> AlphaRef::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<size_t> AlphaRef::ShadowTextures = STK::Tuple<size_t>(0);
const STK::Tuple<size_t> AlphaRef::RSMTextures = STK::Tuple<size_t>(0);
@ -50,33 +50,33 @@ const STK::Tuple<size_t> UnlitMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t, size_t> GrassMat::FirstPassTextures
= STK::Tuple<size_t, size_t>(0, 1);
const STK::Tuple<size_t, size_t> GrassMat::SecondPassTextures
= STK::Tuple<size_t, size_t>(0, 1);
const STK::Tuple<size_t, size_t, size_t> GrassMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<size_t> GrassMat::ShadowTextures = STK::Tuple<size_t>(0);
const STK::Tuple<size_t> GrassMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t, size_t> NormalMat::FirstPassTextures
= STK::Tuple<size_t, size_t>(2, 1);
= STK::Tuple<size_t, size_t>(3, 1);
const STK::Tuple<size_t, size_t, size_t> NormalMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 7);
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<> NormalMat::ShadowTextures;
const STK::Tuple<size_t> NormalMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t> DetailMat::FirstPassTextures = STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> DetailMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 2, 1);
= STK::Tuple<size_t, size_t, size_t>(0, 3, 1);
const STK::Tuple<> DetailMat::ShadowTextures;
const STK::Tuple<size_t> DetailMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t> SplattingMat::FirstPassTextures = STK::Tuple<size_t>(6);
const STK::Tuple<size_t> SplattingMat::FirstPassTextures = STK::Tuple<size_t>(7);
const STK::Tuple<size_t, size_t, size_t, size_t, size_t>
SplattingMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 2, 3, 4, 5);
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 3, 4, 5, 6);
const STK::Tuple<> SplattingMat::ShadowTextures;
const STK::Tuple<size_t, size_t, size_t, size_t, size_t> SplattingMat::RSMTextures
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 2, 3, 4, 5);
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 3, 4, 5, 6);
#endif
#endif

View File

@ -57,35 +57,33 @@ public:
}; // InstancedObjectRefPass1Shader
// ============================================================================
class ObjectRefPass2Shader : public TextureShader<ObjectRefPass2Shader, 5,
core::matrix4, core::matrix4>
class ObjectRefPass2Shader : public TextureShader<ObjectRefPass2Shader, 6,
core::matrix4, core::vector2df,
core::vector2df>
{
public:
ObjectRefPass2Shader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "objectref_pass2.frag");
assignUniforms("ModelMatrix", "TextureMatrix");
assignUniforms("ModelMatrix", "texture_trans", "color_change");
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED,
2, "SSAO", ST_BILINEAR_FILTERED,
3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED,
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED);
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // ObjectRefPass2Shader
}; // ObjectRefPass2Shader
// ============================================================================
class InstancedObjectPass2Shader : public TextureShader<InstancedObjectPass2Shader, 6>
{
private:
GLint m_color_change_location;
public:
InstancedObjectPass2Shader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_object_pass.vert",
GL_FRAGMENT_SHADER, "instanced_object_pass2.frag");
m_color_change_location = glGetUniformLocation(m_program, "color_change");
assignUniforms();
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED,
@ -94,16 +92,10 @@ public:
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedObjectPass2Shader
virtual bool changeableColor(float hue = 0.0f, float min_sat = 0.0f) const OVERRIDE
{
glUniform2f(m_color_change_location, hue, min_sat);
return true;
} // changeableColor
}; // InstancedObjectPass2Shader
// ============================================================================
class InstancedObjectRefPass2Shader : public TextureShader<InstancedObjectRefPass2Shader, 5>
class InstancedObjectRefPass2Shader : public TextureShader<InstancedObjectRefPass2Shader, 6>
{
public:
InstancedObjectRefPass2Shader()
@ -115,7 +107,8 @@ public:
1, "SpecularMap", ST_NEAREST_FILTERED,
2, "SSAO", ST_BILINEAR_FILTERED,
3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED,
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED);
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedObjectRefPass2Shader
}; // InstancedObjectRefPass2Shader
@ -174,7 +167,7 @@ public:
}; // InstancedShadowShader
// ============================================================================
class CRSMShader : public TextureShader<CRSMShader, 1, core::matrix4, core::matrix4,
class CRSMShader : public TextureShader<CRSMShader, 1, core::matrix4, core::vector2df,
core::matrix4>
{
public:
@ -183,7 +176,7 @@ public:
loadProgram(OBJECT, GL_VERTEX_SHADER, "rsm.vert",
GL_FRAGMENT_SHADER, "rsm.frag");
assignUniforms("RSMMatrix", "ModelMatrix", "TextureMatrix");
assignUniforms("ModelMatrix", "texture_trans", "RSMMatrix");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // CRSMShader
}; // CRSMShader
@ -199,7 +192,7 @@ public:
loadProgram(OBJECT, GL_VERTEX_SHADER, "rsm.vert",
GL_FRAGMENT_SHADER, "splatting_rsm.frag");
assignUniforms("RSMMatrix", "ModelMatrix");
assignUniforms("ModelMatrix", "RSMMatrix");
assignSamplerNames(0, "tex_layout", ST_TRILINEAR_ANISOTROPIC_FILTERED,
1, "tex_detail0", ST_TRILINEAR_ANISOTROPIC_FILTERED,
2, "tex_detail1", ST_TRILINEAR_ANISOTROPIC_FILTERED,
@ -280,14 +273,14 @@ public:
// ============================================================================
class ObjectRefPass1Shader : public TextureShader<ObjectRefPass1Shader, 2, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df>
{
public:
ObjectRefPass1Shader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "objectref_pass1.frag");
assignUniforms("ModelMatrix", "InverseModelMatrix", "TextureMatrix");
assignUniforms("ModelMatrix", "InverseModelMatrix", "texture_trans");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED,
1, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // ObjectRefPass1Shader
@ -326,14 +319,14 @@ public:
// ============================================================================
class ObjectUnlitShader : public TextureShader<ObjectUnlitShader, 4, core::matrix4,
core::matrix4>
core::vector2df>
{
public:
ObjectUnlitShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "object_unlit.frag");
assignUniforms("ModelMatrix", "TextureMatrix");
assignUniforms("ModelMatrix", "texture_trans");
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED,
2, "SSAO", ST_BILINEAR_FILTERED,
@ -548,25 +541,27 @@ public:
// ============================================================================
class GrassPass2Shader : public TextureShader<GrassPass2Shader, 5, core::matrix4,
core::vector3df>
class GrassPass2Shader : public TextureShader<GrassPass2Shader, 7, core::matrix4,
core::vector3df, core::vector2df>
{
public:
GrassPass2Shader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "grass_pass.vert",
GL_FRAGMENT_SHADER, "grass_pass2.frag");
assignUniforms("ModelMatrix", "windDir");
assignUniforms("ModelMatrix", "windDir", "color_change");
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED,
2, "SSAO", ST_BILINEAR_FILTERED,
3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED,
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED);
3, "dtex", ST_NEAREST_FILTERED,
4, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
6, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // GrassPass2Shader
}; // GrassPass2Shader
// ============================================================================
class InstancedGrassPass2Shader : public TextureShader<InstancedGrassPass2Shader, 6,
class InstancedGrassPass2Shader : public TextureShader<InstancedGrassPass2Shader, 7,
core::vector3df>
{
public:
@ -580,7 +575,8 @@ public:
2, "SSAO", ST_BILINEAR_FILTERED,
3, "dtex", ST_NEAREST_FILTERED,
4, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED);
5, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
6, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedGrassPass2Shader
}; // InstancedGrassPass2Shader
@ -638,7 +634,7 @@ struct DefaultMaterial
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
static const enum Material::ShaderType MaterialType
= Material::SHADERTYPE_SOLID;
static const enum InstanceType Instance = InstanceTypeDualTex;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const STK::Tuple<size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<> ShadowTextures;
@ -659,9 +655,9 @@ struct AlphaRef
typedef ListMatAlphaRef List;
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_ALPHA_TEST;
static const enum InstanceType Instance = InstanceTypeDualTex;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const STK::Tuple<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t> SecondPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<size_t> ShadowTextures;
static const STK::Tuple<size_t> RSMTextures;
}; // struct AlphaRef
@ -681,7 +677,7 @@ struct SphereMap
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
static const enum Material::ShaderType MaterialType
= Material::SHADERTYPE_SPHERE_MAP;
static const enum InstanceType Instance = InstanceTypeDualTex;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const STK::Tuple<size_t> FirstPassTextures;
static const STK::Tuple<size_t> SecondPassTextures;
static const STK::Tuple<> ShadowTextures;
@ -703,7 +699,7 @@ struct UnlitMat
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
static const enum Material::ShaderType MaterialType =
Material::SHADERTYPE_SOLID_UNLIT;
static const enum InstanceType Instance = InstanceTypeDualTex;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const STK::Tuple<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t> SecondPassTextures;
static const STK::Tuple<size_t> ShadowTextures;
@ -725,9 +721,9 @@ struct GrassMat
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
static const enum Material::ShaderType MaterialType
= Material::SHADERTYPE_VEGETATION;
static const enum InstanceType Instance = InstanceTypeDualTex;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const STK::Tuple<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t> SecondPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<size_t> ShadowTextures;
static const STK::Tuple<size_t> RSMTextures;
}; // GrassMat
@ -747,7 +743,7 @@ struct NormalMat
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_TANGENTS;
static const enum Material::ShaderType MaterialType
= Material::SHADERTYPE_NORMAL_MAP;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const enum InstanceType Instance = InstanceTypeFourTex;
static const STK::Tuple<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<> ShadowTextures;
@ -769,7 +765,7 @@ struct DetailMat
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS;
static const enum Material::ShaderType MaterialType
= Material::SHADERTYPE_DETAIL_MAP;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const enum InstanceType Instance = InstanceTypeFourTex;
static const STK::Tuple<size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<> ShadowTextures;
@ -780,9 +776,7 @@ struct DetailMat
struct SplattingMat
{
typedef InstancedObjectPass1Shader InstancedFirstPassShader;
//TODO: InstancedSecondPassShader
typedef InstancedShadowShader InstancedShadowPassShader;
//TODO InstancedRSMShader
typedef Shaders::ObjectPass1Shader FirstPassShader;
typedef SplattingShader SecondPassShader;
typedef ShadowShader ShadowPassShader;

View File

@ -1295,7 +1295,8 @@ void PostProcessing::renderDoF(const FrameBuffer &framebuffer, GLuint color_text
// ----------------------------------------------------------------------------
void PostProcessing::renderGodRays(scene::ICameraSceneNode * const camnode,
const FrameBuffer &fbo,
const FrameBuffer &in_fbo,
const FrameBuffer &out_fbo,
const FrameBuffer &quarter1_fbo,
const FrameBuffer &quarter2_fbo)
{
@ -1303,7 +1304,7 @@ void PostProcessing::renderGodRays(scene::ICameraSceneNode * const camnode,
glEnable(GL_DEPTH_TEST);
// Grab the sky
fbo.bind();
out_fbo.bind();
glClear(GL_COLOR_BUFFER_BIT);
// irr_driver->renderSkybox(camnode);
@ -1323,7 +1324,7 @@ void PostProcessing::renderGodRays(scene::ICameraSceneNode * const camnode,
quarter1_fbo.bind();
glViewport(0, 0, irr_driver->getActualScreenSize().Width / 4,
irr_driver->getActualScreenSize().Height / 4);
GodFadeShader::getInstance()->render(fbo.getRTT()[0], col);
GodFadeShader::getInstance()->render(out_fbo.getRTT()[0], col);
// Blur
renderGaussian3Blur(quarter1_fbo, quarter2_fbo);
@ -1358,8 +1359,8 @@ void PostProcessing::renderGodRays(scene::ICameraSceneNode * const camnode,
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE);
glBlendEquation(GL_FUNC_ADD);
fbo.bind();
renderPassThrough(quarter2_fbo.getRTT()[0], fbo.getWidth(), fbo.getHeight());
in_fbo.bind();
renderPassThrough(quarter2_fbo.getRTT()[0], in_fbo.getWidth(), in_fbo.getHeight());
glDisable(GL_BLEND);
}
@ -1454,7 +1455,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
{
PROFILER_PUSH_CPU_MARKER("- Godrays", 0xFF, 0x00, 0x00);
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_GODRAYS));
renderGodRays(camnode, *out_fbo, rtts->getFBO(FBO_QUARTER1), rtts->getFBO(FBO_QUARTER2));
renderGodRays(camnode, *in_fbo, *out_fbo, rtts->getFBO(FBO_QUARTER1), rtts->getFBO(FBO_QUARTER2));
PROFILER_POP_CPU_MARKER();
}

View File

@ -104,6 +104,7 @@ public:
void renderDoF(const FrameBuffer &framebuffer, GLuint color_texture, GLuint depth_stencil_texture);
void renderGodRays(scene::ICameraSceneNode * const camnode,
const FrameBuffer &in_fbo,
const FrameBuffer &out_fbo,
const FrameBuffer &quarter1_fbo,
const FrameBuffer &quarter2_fbo);

View File

@ -22,6 +22,7 @@
#include "config/user_config.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/shaders.hpp"
#include "utils/log.hpp"
static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type, unsigned mipmaplevel = 1)
@ -293,11 +294,43 @@ RTT::RTT(size_t width, size_t height)
glClearColor(.5, .5, .5, .5);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
uint64_t handle =
glGetTextureSamplerHandleARB(getRenderTarget(RTT_DIFFUSE),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]);
glMakeTextureHandleResidentARB(handle);
m_prefilled_handles.push_back(handle);
handle =
glGetTextureSamplerHandleARB(getRenderTarget(RTT_SPECULAR),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[1]);
glMakeTextureHandleResidentARB(handle);
m_prefilled_handles.push_back(handle);
handle =
glGetTextureSamplerHandleARB(getRenderTarget(RTT_HALF1_R),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[2]);
glMakeTextureHandleResidentARB(handle);
m_prefilled_handles.push_back(handle);
handle =
glGetTextureSamplerHandleARB(getDepthStencilTexture(),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[3]);
glMakeTextureHandleResidentARB(handle);
m_prefilled_handles.push_back(handle);
}
#endif
}
RTT::~RTT()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
for (uint64_t& handle : m_prefilled_handles)
glMakeTextureHandleNonResidentARB(handle);
}
#endif
glDeleteTextures(RTT_COUNT, RenderTargetTextures);
glDeleteTextures(1, &DepthStencilTexture);
if (CVS->isShadowEnabled())

View File

@ -18,8 +18,9 @@
#ifndef HEADER_RTTS_HPP
#define HEADER_RTTS_HPP
#include "utils/ptr_vector.hpp"
#include "utils/leak_check.hpp"
#include "utils/ptr_vector.hpp"
#include "utils/types.hpp"
#include <stddef.h>
class FrameBuffer;
@ -156,10 +157,12 @@ public:
unsigned getDepthStencilTexture() const { return DepthStencilTexture; }
unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; }
FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; }
const std::vector<uint64_t>& getPrefilledHandles() { return m_prefilled_handles; }
private:
unsigned RenderTargetTextures[RTT_COUNT];
PtrVector<FrameBuffer> FrameBuffers;
std::vector<uint64_t> m_prefilled_handles;
unsigned DepthStencilTexture;
size_t m_width;

View File

@ -33,7 +33,6 @@
#include "graphics/shaders.hpp"
#include "graphics/skybox.hpp"
#include "graphics/spherical_harmonics.hpp"
#include "graphics/stk_scene_manager.hpp"
#include "graphics/texture_manager.hpp"
#include "items/item_manager.hpp"
#include "items/powerup_manager.hpp"
@ -45,8 +44,6 @@
#include <algorithm>
extern std::vector<float> BoundingBoxes; //TODO: replace global variable by something cleaner
// ----------------------------------------------------------------------------
void ShaderBasedRenderer::setRTT(RTT* rtts)
{
@ -58,7 +55,8 @@ void ShaderBasedRenderer::setRTT(RTT* rtts)
rtts->getRenderTarget(RTT_SPECULAR),
rtts->getRenderTarget(RTT_HALF1_R),
rtts->getDepthStencilTexture());
m_geometry_passes->setFirstPassRenderTargets(prefilled_textures);
m_geometry_passes->setFirstPassRenderTargets(prefilled_textures,
rtts->getPrefilledHandles());
m_rtts = rtts;
}
else if (rtts == NULL)
@ -359,30 +357,37 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
if (CVS->isDefferedEnabled())
{
if (CVS->isGlobalIlluminationEnabled() && hasShadow)
{
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH));
m_lighting_passes.renderRadianceHints( m_shadow_matrices,
m_rtts->getRadianceHintFrameBuffer(),
m_rtts->getReflectiveShadowMapFrameBuffer());
}
m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind();
glClear(GL_COLOR_BUFFER_BIT);
m_rtts->getFBO(FBO_DIFFUSE).bind();
if (CVS->isGlobalIlluminationEnabled() && hasShadow)
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_GI));
m_lighting_passes.renderGlobalIllumination( m_shadow_matrices,
m_rtts->getRadianceHintFrameBuffer(),
m_rtts->getReflectiveShadowMapFrameBuffer(),
m_rtts->getFBO(FBO_DIFFUSE),
m_rtts->getRenderTarget(RTT_NORMAL_AND_DEPTH),
m_rtts->getDepthStencilTexture());
}
GLuint specular_probe;
if(m_skybox)
}
m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind();
GLuint specular_probe = 0;
if (m_skybox)
{
specular_probe = m_skybox->getSpecularProbe();
}
else
{
specular_probe = 0;
}
m_lighting_passes.renderLights( hasShadow,
m_rtts->getRenderTarget(RTT_NORMAL_AND_DEPTH),
m_rtts->getDepthStencilTexture(),
m_rtts->getShadowFrameBuffer(),
m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR),
specular_probe);
}
PROFILER_POP_CPU_MARKER();
@ -471,8 +476,6 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
m_rtts->getFBO(FBO_COLORS).bind();
m_lighting_passes.renderGlobalIllumination(m_shadow_matrices,
m_rtts->getRadianceHintFrameBuffer(),
m_rtts->getReflectiveShadowMapFrameBuffer(),
m_rtts->getFBO(FBO_DIFFUSE),
m_rtts->getRenderTarget(RTT_NORMAL_AND_DEPTH),
m_rtts->getDepthStencilTexture());
}
@ -538,24 +541,6 @@ void ShaderBasedRenderer::renderParticles()
// m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT_EFFECT);
} //renderParticles
// ----------------------------------------------------------------------------
void ShaderBasedRenderer::renderBoundingBoxes()
{
Shaders::ColoredLine *line = Shaders::ColoredLine::getInstance();
line->use();
line->bindVertexArray();
line->bindBuffer();
line->setUniforms(irr::video::SColor(255, 255, 0, 0));
const float *tmp = BoundingBoxes.data();
for (unsigned int i = 0; i < BoundingBoxes.size(); i += 1024 * 6)
{
unsigned count = std::min((unsigned)BoundingBoxes.size() - i, (unsigned)1024 * 6);
glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]);
glDrawArrays(GL_LINES, 0, count / 3);
}
} //renderBoundingBoxes
// ----------------------------------------------------------------------------
void ShaderBasedRenderer::debugPhysics()
{
@ -736,7 +721,7 @@ void ShaderBasedRenderer::addSkyBox(const std::vector<video::ITexture*> &texture
if(spherical_harmonics_textures.size() == 6)
{
m_spherical_harmonics->setTextures(spherical_harmonics_textures);
}
}
}
// ----------------------------------------------------------------------------
@ -768,7 +753,7 @@ GLuint ShaderBasedRenderer::getDepthStencilTexture() const
void ShaderBasedRenderer::setAmbientLight(const video::SColorf &light,
bool force_SH_computation)
{
if(!m_spherical_harmonics->has6Textures() || force_SH_computation)
if (force_SH_computation)
m_spherical_harmonics->setAmbientLight(light.toSColor());
}
@ -806,9 +791,7 @@ void ShaderBasedRenderer::render(float dt)
{
resetObjectCount();
resetPolyCount();
BoundingBoxes.clear(); //TODO: do not use a global variable
setOverrideMaterial();
addItemsInGlowingList();
@ -860,7 +843,7 @@ void ShaderBasedRenderer::render(float dt)
if (irr_driver->getBoundingBoxesViz())
{
renderBoundingBoxes();
m_draw_calls.renderBoundingBoxes();
}
debugPhysics();

View File

@ -83,7 +83,6 @@ private:
void renderParticles();
void renderBoundingBoxes();
void debugPhysics();
void renderPostProcessing(Camera * const camera);

View File

@ -352,8 +352,7 @@ Shaders::ObjectPass2Shader::ObjectPass2Shader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "object_pass2.frag");
m_color_change_location = glGetUniformLocation(m_program, "color_change");
assignUniforms("ModelMatrix", "TextureMatrix");
assignUniforms("ModelMatrix", "texture_trans", "color_change");
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED,
2, "SSAO", ST_BILINEAR_FILTERED,
@ -367,7 +366,7 @@ Shaders::TransparentShader::TransparentShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "transparent.frag");
assignUniforms("ModelMatrix", "TextureMatrix", "custom_alpha");
assignUniforms("ModelMatrix", "texture_trans", "custom_alpha");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // TransparentShader
@ -376,7 +375,7 @@ Shaders::TransparentFogShader::TransparentFogShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "transparentfog.frag");
assignUniforms("ModelMatrix", "TextureMatrix", "fogmax", "startH",
assignUniforms("ModelMatrix", "texture_trans", "fogmax", "startH",
"endH", "start", "end", "col");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // TransparentFogShader

View File

@ -122,7 +122,7 @@ public:
// ========================================================================
class TransparentShader : public TextureShader<TransparentShader, 1,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
float >
{
public:
@ -131,7 +131,7 @@ public:
// ========================================================================
class TransparentFogShader : public TextureShader<TransparentFogShader, 1,
core::matrix4, core::matrix4, float, float,
core::matrix4, core::vector2df, float, float,
float, float, float, video::SColorf >
{
public:
@ -147,17 +147,11 @@ public:
// ========================================================================
class ObjectPass2Shader : public TextureShader < ObjectPass2Shader, 6,
core::matrix4, core::matrix4 >
core::matrix4, core::vector2df,
core::vector2df >
{
private:
GLint m_color_change_location;
public:
ObjectPass2Shader();
virtual bool changeableColor(float hue = 0.0f, float min_sat = 0.0f) const OVERRIDE
{
glUniform2f(m_color_change_location, hue, min_sat);
return true;
} // changeableColor
}; // ObjectPass2Shader
// ========================================================================

View File

@ -69,7 +69,7 @@ void ShowCurve::addEmptyMesh()
m_buffer = m_mesh->getMeshBuffer(0);
m_buffer->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180)));
m_buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m_buffer->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m_buffer->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
assert(m_buffer->getVertexType()==video::EVT_STANDARD);
} // addEmptyMesh

View File

@ -188,10 +188,18 @@ void STKAnimatedMesh::updateNoGL()
for (u32 i = 0; i < m->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
if (mb)
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
if (mb != NULL)
{
// Test if texture matrix needs to be updated every frame
const core::matrix4& mat = getMaterial(i).getTextureMatrix(0);
if (mat.isIdentity())
continue;
else
{
GLmeshes[i].texture_trans.X = mat[8];
GLmeshes[i].texture_trans.Y = mat[9];
}
}
}
}

View File

@ -235,7 +235,7 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name,
}
for (unsigned i = 0; i < 8; i++)
result.textures[i] = mb->getMaterial().getTexture(i);
result.TextureMatrix = 0;
result.texture_trans = core::vector2df(0.0f, 0.0f);
result.VAOType = mb->getVertexType();
return result;
} // allocateMeshBuffer
@ -365,7 +365,10 @@ static void setTexture(GLMesh &mesh, unsigned i, bool is_srgb,
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
}
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[i]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[i]);
insertTextureHandle(mesh.TextureHandles[i]);
}
}
#endif
} // setTexture
@ -403,17 +406,19 @@ void initTextures(GLMesh &mesh, Material::ShaderType mat)
default:
case Material::SHADERTYPE_SOLID:
case Material::SHADERTYPE_ALPHA_TEST:
case Material::SHADERTYPE_VEGETATION:
case Material::SHADERTYPE_SPHERE_MAP:
case Material::SHADERTYPE_SOLID_UNLIT:
case Material::SHADERTYPE_VEGETATION:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, false, getShaderTypeName(mat));
break;
case Material::SHADERTYPE_DETAIL_MAP:
case Material::SHADERTYPE_NORMAL_MAP:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, false, getShaderTypeName(mat));
setTexture(mesh, 3, false, getShaderTypeName(mat));
break;
case Material::SHADERTYPE_SPLATTING:
setTexture(mesh, 0, true, getShaderTypeName(mat));
@ -423,6 +428,7 @@ void initTextures(GLMesh &mesh, Material::ShaderType mat)
setTexture(mesh, 4, true, getShaderTypeName(mat));
setTexture(mesh, 5, true, getShaderTypeName(mat));
setTexture(mesh, 6, false, getShaderTypeName(mat));
setTexture(mesh, 7, false, getShaderTypeName(mat));
break;
}
} // initTextures
@ -445,7 +451,10 @@ void initTexturesTransparent(GLMesh &mesh)
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
}
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
insertTextureHandle(mesh.TextureHandles[0]);
}
}
#endif
} // initTexturesTransparent

View File

@ -53,11 +53,11 @@ struct GLMesh
GLenum IndexType;
size_t IndexCount;
size_t Stride;
core::matrix4 TextureMatrix;
core::vector2df texture_trans;
size_t vaoBaseVertex;
size_t vaoOffset;
video::E_VERTEX_TYPE VAOType;
uint64_t TextureHandles[6];
uint64_t TextureHandles[8];
scene::IMeshBuffer *mb;
RenderInfo* m_render_info;
Material* m_material;
@ -112,28 +112,31 @@ public:
// ----------------------------------------------------------------------------
class ListMatDefault : public MeshList<ListMatDefault, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatAlphaRef : public MeshList<ListMatAlphaRef, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatNormalMap : public MeshList<ListMatNormalMap, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatGrass : public MeshList<ListMatGrass, GLMesh *, core::matrix4,
core::matrix4, core::vector3df>
core::matrix4, core::vector3df, core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatSphereMap : public MeshList<ListMatSphereMap, GLMesh *,
core::matrix4, core::matrix4,
core::matrix4>
core::vector2df>
{};
// ----------------------------------------------------------------------------
@ -143,12 +146,12 @@ class ListMatSplatting : public MeshList<ListMatSplatting, GLMesh *,
// ----------------------------------------------------------------------------
class ListMatUnlit : public MeshList<ListMatUnlit, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatDetails : public MeshList<ListMatDetails, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
@ -159,38 +162,38 @@ class MiscList : public Singleton<T>, public std::vector<STK::Tuple<Args...> >
// ----------------------------------------------------------------------------
class ListBlendTransparent : public MiscList<ListBlendTransparent, GLMesh *,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
float>
{};
// ----------------------------------------------------------------------------
class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentStandard : public MiscList<ListTranslucentStandard,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentTangents : public MiscList<ListTranslucentTangents,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucent2TCoords : public MiscList<ListTranslucent2TCoords,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
GLMesh *, core::matrix4,
core::matrix4, float, float,
core::vector2df, float, float,
float, float, float,
video::SColorf>
{};
@ -198,7 +201,7 @@ class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
// ----------------------------------------------------------------------------
class ListAdditiveTransparentFog : public MiscList<ListAdditiveTransparentFog,
GLMesh *, core::matrix4,
core::matrix4, float, float,
core::vector2df, float, float,
float, float, float,
video::SColorf>
{};

View File

@ -240,9 +240,18 @@ void STKMeshSceneNode::updateNoGL()
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
if (mb != NULL)
{
// Test if texture matrix needs to be updated every frame
const core::matrix4& mat = getMaterial(i).getTextureMatrix(0);
if (mat.isIdentity())
continue;
else
{
GLmeshes[i].texture_trans.X = mat[8];
GLmeshes[i].texture_trans.Y = mat[9];
}
}
}
}
@ -365,7 +374,10 @@ void STKMeshSceneNode::render()
::getInstance()->m_sampler_ids[0]);
}
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
insertTextureHandle(mesh.TextureHandles[0]);
}
Shaders::ObjectPass1Shader::getInstance()->setTextureHandles(mesh.TextureHandles[0]);
}
else
@ -418,23 +430,32 @@ void STKMeshSceneNode::render()
if (!mesh.TextureHandles[0])
mesh.TextureHandles[0] =
glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]);
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
insertTextureHandle(mesh.TextureHandles[0]);
}
if (!mesh.TextureHandles[1])
mesh.TextureHandles[1] =
glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[1]),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]);
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[1]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[1]);
insertTextureHandle(mesh.TextureHandles[1]);
}
if (!mesh.TextureHandles[2])
mesh.TextureHandles[2] =
glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[7]),
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]);
glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[2]),
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[2]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[2]);
insertTextureHandle(mesh.TextureHandles[2]);
}
Shaders::ObjectPass2Shader::getInstance()
->setTextureHandles(DiffuseHandle, SpecularHandle, SSAOHandle,
@ -449,9 +470,10 @@ void STKMeshSceneNode::render()
irr_driver->getRenderTargetTexture(RTT_HALF1_R),
getTextureGLuint(mesh.textures[0]),
getTextureGLuint(mesh.textures[1]),
getTextureGLuint(mesh.textures[7]));
getTextureGLuint(mesh.textures[2]));
Shaders::ObjectPass2Shader::getInstance()->setUniforms(AbsoluteTransformation,
mesh.TextureMatrix);
mesh.texture_trans,
core::vector2df(0.0f, 0.0f));
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
@ -522,9 +544,12 @@ void STKMeshSceneNode::render()
if (!mesh.TextureHandles[0])
mesh.TextureHandles[0] =
glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]),
Shaders::TransparentFogShader::getInstance()->m_sampler_ids[0]);
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
insertTextureHandle(mesh.TextureHandles[0]);
}
Shaders::TransparentFogShader::getInstance()
->setTextureHandles(mesh.TextureHandles[0]);
}
@ -535,7 +560,7 @@ void STKMeshSceneNode::render()
->setTextureUnits(getTextureGLuint(mesh.textures[0]));
}
Shaders::TransparentFogShader::getInstance()
->setUniforms(AbsoluteTransformation, mesh.TextureMatrix,
->setUniforms(AbsoluteTransformation, mesh.texture_trans,
fogmax, startH, endH, start, end, col);
assert(mesh.vao);
@ -562,16 +587,19 @@ void STKMeshSceneNode::render()
if (!mesh.TextureHandles[0])
mesh.TextureHandles[0] =
glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]),
Shaders::TransparentShader::getInstance()->m_sampler_ids[0]);
Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
{
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
insertTextureHandle(mesh.TextureHandles[0]);
}
Shaders::TransparentShader::getInstance()->setTextureHandles(mesh.TextureHandles[0]);
}
else
#endif
Shaders::TransparentShader::getInstance()->setTextureUnits(getTextureGLuint(mesh.textures[0]));
Shaders::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, 1.0f);
Shaders::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.texture_trans, 1.0f);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);

View File

@ -124,7 +124,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, FontWithFace* fo
buffer = new scene::SMeshBuffer();
buffer->getMaterial().setTexture(0, m_chars[i].m_texture);
buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
buffer->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
buffer->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
buffer->getMaterial().MaterialType = Shaders::getShader(ES_OBJECT_UNLIT);
buffers[m_chars[i].m_texture] = buffer;
}

View File

@ -21,6 +21,7 @@
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/shaders.hpp"
#if defined(USE_GLES2)
#define _IRR_COMPILE_WITH_OGLES2_
@ -57,12 +58,30 @@ GLuint getDepthTexture(irr::video::ITexture *tex)
static std::set<irr::video::ITexture *> AlreadyTransformedTexture;
static std::map<int, video::ITexture*> unicolor_cache;
static std::vector<uint64_t> texture_handles;
void resetTextureTable()
{
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
// Driver seems to crash if texture handles are not cleared...
for (uint64_t& handle : texture_handles)
{
glMakeTextureHandleNonResidentARB(handle);
}
Shaders::ObjectPass1Shader::getInstance()->recreateTrilinearSampler(0);
texture_handles.clear();
}
#endif
AlreadyTransformedTexture.clear();
}
void insertTextureHandle(uint64_t handle)
{
texture_handles.push_back(handle);
}
void cleanUnicolorTextures()
{
for (std::pair<const int, video::ITexture*>& uc : unicolor_cache)

View File

@ -33,5 +33,6 @@ void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = f
bool loadCompressedTexture(const std::string& compressed_tex);
void saveCompressedTexture(const std::string& compressed_tex);
irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c);
void insertTextureHandle(uint64_t handle);
#endif

View File

@ -245,13 +245,18 @@ public:
for (unsigned i = 0; i < m_sampler_ids.size(); i++)
glDeleteSamplers(1, &m_sampler_ids[i]);
} // ~TextureShader
/** Override this class and return true if a shader has changeable color.
// ------------------------------------------------------------------------
/** For AZDO to remove the old texture handles, according to specification,
* they can only be removed when the underlying texture or sampler objects
* are finally deleted. This deletion will happen only when no handle
* using the texture or sampler object is resident on any context.
*/
virtual bool changeableColor(float hue = 0.0f, float min_sat = 0.0f) const
void recreateTrilinearSampler(int sampler_id)
{
return false;
} // changeableColor
glDeleteSamplers(1, &m_sampler_ids[sampler_id]);
m_sampler_ids[sampler_id] =
createSamplers(ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // recreateTrilinearSampler
}; // class TextureShader

View File

@ -44,13 +44,13 @@ VAOManager::VAOManager()
#if !defined(USE_GLES2)
if (CVS->supportsAsyncInstanceUpload())
{
glBufferStorage(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataDualTex), 0, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
Ptr[i] = glMapBufferRange(GL_ARRAY_BUFFER, 0, 10000 * sizeof(InstanceDataDualTex), GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
glBufferStorage(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataThreeTex), 0, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
Ptr[i] = glMapBufferRange(GL_ARRAY_BUFFER, 0, 10000 * sizeof(InstanceDataThreeTex), GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
}
else
#endif
{
glBufferData(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataDualTex), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataThreeTex), 0, GL_STREAM_DRAW);
}
}
}
@ -160,20 +160,8 @@ template<>
void VAOInstanceUtil<InstanceDataSingleTex>::SetVertexAttrib()
{
SetVertexAttrib_impl();
glEnableVertexAttribArray(10);
glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataSingleTex), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(10, 1);
}
template<>
void VAOInstanceUtil<InstanceDataDualTex>::SetVertexAttrib()
{
SetVertexAttrib_impl();
glEnableVertexAttribArray(10);
glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(10, 1);
glEnableVertexAttribArray(11);
glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned)));
glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataSingleTex), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(11, 1);
}
@ -182,23 +170,47 @@ void VAOInstanceUtil<InstanceDataThreeTex>::SetVertexAttrib()
{
SetVertexAttrib_impl();
glEnableVertexAttribArray(10);
glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float)));
glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(10, 1);
glEnableVertexAttribArray(11);
glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned)));
glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float)));
glVertexAttribDivisorARB(11, 1);
glEnableVertexAttribArray(12);
glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 2 * sizeof(unsigned)));
glVertexAttribDivisorARB(12, 1);
glEnableVertexAttribArray(13);
glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float) + 4 * sizeof(unsigned)));
glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned)));
glVertexAttribDivisorARB(13, 1);
}
template<>
void VAOInstanceUtil<InstanceDataFourTex>::SetVertexAttrib()
{
SetVertexAttrib_impl();
glEnableVertexAttribArray(10);
glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, sizeof(InstanceDataFourTex), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(10, 1);
glEnableVertexAttribArray(11);
glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float)));
glVertexAttribDivisorARB(11, 1);
glEnableVertexAttribArray(12);
glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float) + 2 * sizeof(unsigned)));
glVertexAttribDivisorARB(12, 1);
glEnableVertexAttribArray(13);
glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned)));
glVertexAttribDivisorARB(13, 1);
glEnableVertexAttribArray(14);
glVertexAttribIPointer(14, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float) + 6 * sizeof(unsigned)));
glVertexAttribDivisorARB(14, 1);
}
template<>
void VAOInstanceUtil<GlowInstanceData>::SetVertexAttrib()
{
SetVertexAttrib_impl();
glEnableVertexAttribArray(12);
glVertexAttribPointer(12, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlowInstanceData), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(12, 1);
glEnableVertexAttribArray(15);
glVertexAttribPointer(15, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlowInstanceData), (GLvoid*)(9 * sizeof(float)));
glVertexAttribDivisorARB(15, 1);
}
@ -213,15 +225,15 @@ void VAOManager::regenerateInstancedVAO()
if (!vbo[tp] || !ibo[tp])
continue;
GLuint vao = createVAO(vbo[tp], ibo[tp], tp);
glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeDualTex]);
VAOInstanceUtil<InstanceDataDualTex>::SetVertexAttrib();
InstanceVAO[std::pair<video::E_VERTEX_TYPE, InstanceType>(tp, InstanceTypeDualTex)] = vao;
vao = createVAO(vbo[tp], ibo[tp], tp);
glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeThreeTex]);
VAOInstanceUtil<InstanceDataThreeTex>::SetVertexAttrib();
InstanceVAO[std::pair<video::E_VERTEX_TYPE, InstanceType>(tp, InstanceTypeThreeTex)] = vao;
vao = createVAO(vbo[tp], ibo[tp], tp);
glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeFourTex]);
VAOInstanceUtil<InstanceDataFourTex>::SetVertexAttrib();
InstanceVAO[std::pair<video::E_VERTEX_TYPE, InstanceType>(tp, InstanceTypeFourTex)] = vao;
vao = createVAO(vbo[tp], ibo[tp], tp);
glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeShadow]);
VAOInstanceUtil<InstanceDataSingleTex>::SetVertexAttrib();

View File

@ -30,8 +30,8 @@ class RenderInfo;
enum InstanceType
{
InstanceTypeDualTex,
InstanceTypeThreeTex,
InstanceTypeFourTex,
InstanceTypeShadow,
InstanceTypeRSM,
InstanceTypeGlow,
@ -68,34 +68,6 @@ struct InstanceDataSingleTex
} __attribute__((packed));
#endif
struct InstanceDataDualTex
{
struct
{
float X;
float Y;
float Z;
} Origin;
struct
{
float X;
float Y;
float Z;
} Orientation;
struct
{
float X;
float Y;
float Z;
} Scale;
uint64_t Texture;
uint64_t SecondTexture;
#ifdef WIN32
};
#else
} __attribute__((packed));
#endif
struct InstanceDataThreeTex
{
struct
@ -116,6 +88,13 @@ struct InstanceDataThreeTex
float Y;
float Z;
} Scale;
struct
{
float X;
float Y;
float Z;
float W;
} MiscData;
uint64_t Texture;
uint64_t SecondTexture;
uint64_t ThirdTexture;
@ -125,6 +104,43 @@ struct InstanceDataThreeTex
} __attribute__((packed));
#endif
struct InstanceDataFourTex
{
struct
{
float X;
float Y;
float Z;
} Origin;
struct
{
float X;
float Y;
float Z;
} Orientation;
struct
{
float X;
float Y;
float Z;
} Scale;
struct
{
float X;
float Y;
float Z;
float W;
} MiscData;
uint64_t Texture;
uint64_t SecondTexture;
uint64_t ThirdTexture;
uint64_t FourthTexture;
#ifdef WIN32
};
#else
} __attribute__((packed));
#endif
struct GlowInstanceData
{
struct

View File

@ -273,12 +273,12 @@ void MultitouchDevice::handleControls(MultitouchButton* button)
if (button->axis_y < -m_deadzone_center)
{
float factor = getSteeringFactor(std::abs(button->axis_y));
controller->action(PA_ACCEL, factor * Input::MAX_VALUE);
controller->action(PA_ACCEL, int(factor * Input::MAX_VALUE));
}
else if (button->axis_y > m_deadzone_center)
{
float factor = getSteeringFactor(std::abs(button->axis_y));
controller->action(PA_BRAKE, factor * Input::MAX_VALUE);
controller->action(PA_BRAKE, int(factor * Input::MAX_VALUE));
}
else
{
@ -289,12 +289,12 @@ void MultitouchDevice::handleControls(MultitouchButton* button)
if (button->axis_x < -m_deadzone_center)
{
float factor = getSteeringFactor(std::abs(button->axis_x));
controller->action(PA_STEER_LEFT, factor * Input::MAX_VALUE);
controller->action(PA_STEER_LEFT, int(factor * Input::MAX_VALUE));
}
else if (button->axis_x > m_deadzone_center)
{
float factor = getSteeringFactor(std::abs(button->axis_x));
controller->action(PA_STEER_RIGHT, factor * Input::MAX_VALUE);
controller->action(PA_STEER_RIGHT, int(factor * Input::MAX_VALUE));
}
else
{

View File

@ -29,6 +29,10 @@
#include "utils/log.hpp"
#include "utils/string_utils.hpp"
#ifdef ANDROID
#include "io/assets_android.hpp"
#endif
#include <irrlicht.h>
#include <stdio.h>
@ -145,6 +149,11 @@ FileManager::FileManager()
m_file_system = irr::io::createFileSystem();
#ifdef ANDROID
AssetsAndroid android_assets(this);
android_assets.init();
#endif
std::string exe_path;
// Search for the root directory
@ -1236,10 +1245,8 @@ void FileManager::listFiles(std::set<std::string>& result,
{
result.clear();
#ifndef ANDROID
if(!isDirectory(dir))
return;
#endif
io::path previous_cwd = m_file_system->getWorkingDirectory();
@ -1306,26 +1313,37 @@ bool FileManager::removeDirectory(const std::string &name) const
{
std::set<std::string> files;
listFiles(files, name, /*is full path*/ true);
for(std::set<std::string>::iterator i=files.begin(); i!=files.end(); i++)
for (std::string file : files)
{
if((*i)=="." || (*i)=="..") continue;
if(UserConfigParams::logMisc())
if (file == "." || file == ".." || file == name + "/." ||
file == name + "/..")
continue;
if (UserConfigParams::logMisc())
Log::verbose("FileManager", "Deleting directory '%s'.",
(*i).c_str());
if(isDirectory(*i))
file.c_str());
if (isDirectory(file))
{
// This should not be necessary (since this function is only
// used to remove addons), and it limits the damage in case
// of any bugs - i.e. if name should be "/" or so.
// removeDirectory(full_path);
// We need to remove whole data directory on Android though, i.e.
// when we install newer STK version and new assets are extracted.
// So enable it only for Android for now.
#ifdef ANDROID
removeDirectory(file);
#endif
}
else
{
removeFile(*i);
removeFile(file);
}
}
#if defined(WIN32)
return RemoveDirectory(name.c_str())==TRUE;
return RemoveDirectory(name.c_str())==TRUE;
#else
return remove(name.c_str())==0;
#endif

View File

@ -194,8 +194,10 @@ public:
*/
bool hitKart(const Vec3 &xyz, const AbstractKart *kart=NULL) const
{
Vec3 diff = (xyz - m_xyz);
diff.setY(diff.getY() / 2.0f); // don't be too strict if the kart is a bit above the item
return (m_event_handler!=kart || m_deactive_time <=0) &&
(xyz-m_xyz).length2()<m_distance_2;
diff.length2()<m_distance_2;
} // hitKart
protected:

View File

@ -74,7 +74,7 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
// Gloss
mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
// Colorization mask
mb->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
mb->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
#endif
updatePosition();
m_node = irr_driver->addMesh(m_mesh, "rubberband");

View File

@ -2539,30 +2539,6 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model)
m_attachment = new Attachment(this);
createPhysics();
// Attach Particle System
Track *track = World::getWorld()->getTrack();
#ifndef SERVER_ONLY
if (type == RaceManager::KT_PLAYER &&
UserConfigParams::m_weather_effects &&
track->getSkyParticles() != NULL)
{
track->getSkyParticles()->setBoxSizeXZ(150.0f, 150.0f);
m_sky_particles_emitter =
new ParticleEmitter(track->getSkyParticles(),
core::vector3df(0.0f, 30.0f, 100.0f),
getNode(),
true);
// FIXME: in multiplayer mode, this will result in several instances
// of the heightmap being calculated and kept in memory
m_sky_particles_emitter->addHeightMapAffector(track);
}
#endif
Vec3 position(0, getKartHeight()*0.35f, -getKartLength()*0.35f);
m_slipstream = new SlipStream(this);
if (m_kart_properties->getSkidEnabled())

View File

@ -119,9 +119,9 @@ void ThreeStrikesBattle::reset()
scene::ISceneNode* kart_node = m_karts[n]->getNode();
// FIXME: sorry for this ugly const_cast, irrlicht doesn't seem to allow getting a writable list of children, wtf??
core::list<scene::ISceneNode*>& children = const_cast<core::list<scene::ISceneNode*>&>(kart_node->getChildren());
for (core::list<scene::ISceneNode*>::Iterator it = children.begin(); it != children.end(); it++)
core::list<scene::ISceneNode*>& children = kart_node->getChildren();
for (core::list<scene::ISceneNode*>::Iterator it = children.begin();
it != children.end(); it++)
{
scene::ISceneNode* curr = *it;
@ -295,11 +295,7 @@ void ThreeStrikesBattle::kartHit(const unsigned int kart_id)
}
scene::ISceneNode* kart_node = m_karts[kart_id]->getNode();
// FIXME: sorry for this ugly const_cast, irrlicht doesn't seem to allow
// getting a writable list of children, wtf??
core::list<scene::ISceneNode*>& children =
const_cast<core::list<scene::ISceneNode*>&>(kart_node->getChildren());
core::list<scene::ISceneNode*>& children = kart_node->getChildren();
for (core::list<scene::ISceneNode*>::Iterator it = children.begin();
it != children.end(); it++)
{
@ -608,8 +604,7 @@ void ThreeStrikesBattle::addKartLife(unsigned int id)
updateKartRanks();
scene::ISceneNode* kart_node = m_karts[id]->getNode();
core::list<scene::ISceneNode*>& children =
const_cast<core::list<scene::ISceneNode*>&>(kart_node->getChildren());
core::list<scene::ISceneNode*>& children = kart_node->getChildren();
for (core::list<scene::ISceneNode*>::Iterator it = children.begin();
it != children.end(); it++)
{

View File

@ -407,7 +407,11 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
}
else if (selection == "quit")
{
#ifdef ANDROID
ANativeActivity_finish(global_android_app->activity);
#else
StateManager::get()->popMenu();
#endif
return;
}
else if (selection == "about")

View File

@ -925,22 +925,23 @@ void RaceGUI::initMultitouchSteering()
int(0.5f * margin), int(h - 0.5f * margin - btn2_size),
int(btn2_size), int(btn2_size));
device->addButton(BUTTON_ESCAPE,
top_margin, int(small_ratio * margin),
int(top_margin), int(small_ratio * margin),
int(small_ratio * btn_size), int(small_ratio * btn_size));
device->addButton(BUTTON_RESCUE,
int(top_margin + small_ratio * col_size), int(small_ratio * margin),
int(top_margin + small_ratio * col_size),
int(small_ratio * margin),
int(small_ratio * btn_size), int(small_ratio * btn_size));
device->addButton(BUTTON_NITRO,
w - 1 * col_size, h - 2 * col_size,
int(w - 1 * col_size), int(h - 2 * col_size),
int(btn_size), int(btn_size));
device->addButton(BUTTON_SKIDDING,
w - 1 * col_size, h - 1 * col_size,
int(w - 1 * col_size), int(h - 1 * col_size),
int(btn_size), int(btn_size));
device->addButton(BUTTON_FIRE,
w - 2 * col_size, h - 2 * col_size,
int(w - 2 * col_size), int(h - 2 * col_size),
int(btn_size), int(btn_size));
device->addButton(BUTTON_LOOK_BACKWARDS,
w - 2 * col_size, h - 1 * col_size,
int(w - 2 * col_size), int(h - 1 * col_size),
int(btn_size), int(btn_size));
} // initMultitouchSteering
@ -984,8 +985,8 @@ void RaceGUI::drawMultitouchSteering(const AbstractKart* kart,
float w = (float)(button->width) / 20.0f;
float h = (float)(button->height) / 20.0f;
core::rect<s32> pos2(round(x - w), round(y - h),
round(x + w), round(y + h));
core::rect<s32> pos2(int(round(x - w)), int(round(y - h)),
int(round(x + w)), int(round(y + h)) );
draw2DImage(tex, pos2, coords, NULL, NULL, true);
}
@ -993,10 +994,10 @@ void RaceGUI::drawMultitouchSteering(const AbstractKart* kart,
{
if (button->pressed)
{
core::rect<s32> pos2(button->x - button->width * 0.2f,
button->y - button->height * 0.2f,
button->x + button->width * 1.2f,
button->y + button->height * 1.2f);
core::rect<s32> pos2(int(button->x - button->width * 0.2f),
int(button->y - button->height * 0.2f),
int(button->x + button->width * 1.2f),
int(button->y + button->height * 1.2f) );
video::ITexture* tex = irr_driver->getTexture(FileManager::GUI,
"icons-frame.png");

View File

@ -105,7 +105,7 @@ CheckLine::CheckLine(const XMLNode &node, unsigned int index)
buffer->recalculateBoundingBox();
buffer->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180)));
buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
buffer->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
buffer->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
buffer->getMaterial().BackfaceCulling = false;
//mesh->setBoundingBox(buffer->getBoundingBox());
m_debug_node = irr_driver->addMesh(mesh, "checkdebug");

View File

@ -110,7 +110,7 @@ void Graph::createMesh(bool show_invisible, bool enable_transparency,
m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
m.setTexture(0, getUnicolorTexture(video::SColor(255, 255, 255, 255)));
m.setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m.setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m.setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m_mesh = irr_driver->createQuadMesh(&m);
m_mesh_buffer = m_mesh->getMeshBuffer(0);
assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD);

View File

@ -159,7 +159,13 @@ void ModelDefinitionLoader::clear()
scene::IMesh* ModelDefinitionLoader::getFirstMeshFor(const std::string& name)
{
return irr_driver->getMesh(m_lod_groups[name][0].m_model_file);
if (name.size() > 0)
{
const std::vector<ModelDefinition>& md = m_lod_groups[name];
if (!md.empty())
return irr_driver->getMesh(md[0].m_model_file);
}
return NULL;
} // getFirstMeshFor
// ----------------------------------------------------------------------------

View File

@ -801,7 +801,7 @@ void Track::createPhysicsModel(unsigned int main_track_count)
#ifndef SERVER_ONLY
mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
// Colorization mask
mb->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
mb->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
#endif
}
else
@ -1837,8 +1837,9 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
// ---- Set ambient color
m_ambient_color = m_default_ambient_color;
irr_driver->setAmbientLight(m_ambient_color, false);
irr_driver->setAmbientLight(m_ambient_color,
m_spherical_harmonics_textures.size() != 6/*force_SH_computation*/);
// ---- Create sun (non-ambient directional light)
if (m_sun_position.getLengthSQ() < 0.03f)
{

View File

@ -31,6 +31,7 @@
#include "physics/physical_object.hpp"
#include "race/race_manager.hpp"
#include "scriptengine/script_engine.hpp"
#include "tracks/model_definition_loader.hpp"
#include "utils/helpers.hpp"
#include <ISceneManager.h>
@ -187,6 +188,9 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
xml_node.get("model", &model_name);
bool colorizable = false;
scene::IMesh* mesh = NULL;
// Only non-lod groups can use dynamic hue for different parts of mesh
bool use_dynamic_hue = true;
float static_hue = 0.0f;
if (model_name.size() > 0)
{
mesh = irr_driver->getMesh(model_name);
@ -199,15 +203,48 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
Material* m = material_manager->getMaterialFor(mb
->getMaterial().getTexture(0), mb);
colorizable = colorizable || m->isColorizable();
if (colorizable) break;
}
}
}
else
{
std::string group_name = "";
xml_node.get("lod_group", &group_name);
// Try to get the first mesh from lod groups
mesh = model_def_loader.getFirstMeshFor(group_name);
if (mesh != NULL)
{
use_dynamic_hue = false;
unsigned int n = mesh->getMeshBufferCount();
for (unsigned int i = 0; i < n; i++)
{
scene::IMeshBuffer *mb = mesh->getMeshBuffer(i);
Material* m = material_manager->getMaterialFor(mb
->getMaterial().getTexture(0), mb);
if (m->isColorizable())
{
// Use the first texture to determine static hue
// Other texture that is non-colorizable will be
// untouched, otherwise they will be colorized the
// same hue
colorizable = true;
static_hue = m->getRandomHue();
break;
}
}
}
}
// If at least one material is colorizable, add RenderInfo for it
if (colorizable)
{
m_render_info = new RenderInfo();
m_render_info->setDynamicHue(mesh);
if (use_dynamic_hue)
m_render_info->setDynamicHue(mesh);
else
m_render_info->setHue(static_hue);
}
scene::ISceneNode *glownode = NULL;