From 27a79526b1c9b66f9e8b732a8278b5f066f49d92 Mon Sep 17 00:00:00 2001 From: Deve Date: Mon, 2 Oct 2017 23:05:12 +0200 Subject: [PATCH] Allow to use particles heightmap simulation in GLES --- data/shaders/particlesimheightmap.vert | 10 ++++++++++ src/graphics/gpu_particles.cpp | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/data/shaders/particlesimheightmap.vert b/data/shaders/particlesimheightmap.vert index 5095c837b..5aa23edf6 100644 --- a/data/shaders/particlesimheightmap.vert +++ b/data/shaders/particlesimheightmap.vert @@ -7,7 +7,12 @@ uniform float track_x; uniform float track_z; uniform float track_x_len; uniform float track_z_len; + +#ifndef GL_ES uniform samplerBuffer heightmap; +#else +uniform sampler2D heightmap; +#endif #ifdef Explicit_Attrib_Location_Usable layout (location = 4) in vec3 particle_position_initial; @@ -45,7 +50,12 @@ void main(void) int i = int(i_as_float); int j = int(j_as_float); +#ifndef GL_ES float h = particle_position.y - texelFetch(heightmap, i * 256 + j).r; +#else + float h = particle_position.y - texelFetch(heightmap, ivec2(j, i), 0).r; +#endif + reset = h < 0.; vec4 initialposition = sourcematrix * vec4(particle_position_initial, 1.0); diff --git a/src/graphics/gpu_particles.cpp b/src/graphics/gpu_particles.cpp index 962a174f3..766bbdb4a 100644 --- a/src/graphics/gpu_particles.cpp +++ b/src/graphics/gpu_particles.cpp @@ -91,7 +91,6 @@ public: // ============================================================================ /** */ -#if !defined(USE_GLES2) class HeightmapSimulationShader : public TextureShader > &hm, float f1, float f2, float f3, float f4) { -#if !defined(USE_GLES2) track_x = f1, track_z = f2, track_x_len = f3, track_z_len = f4; unsigned width = (unsigned)hm.size(); @@ -200,6 +201,8 @@ void ParticleSystemProxy::setHeightmap(const std::vector > &h } } has_height_map = true; + +#if !defined(USE_GLES2) glGenBuffers(1, &heighmapbuffer); glBindBuffer(GL_TEXTURE_BUFFER, heighmapbuffer); glBufferData(GL_TEXTURE_BUFFER, width * height * sizeof(float), hm_array, GL_STREAM_COPY); @@ -208,9 +211,14 @@ void ParticleSystemProxy::setHeightmap(const std::vector > &h glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, heighmapbuffer); glBindBuffer(GL_TEXTURE_BUFFER, 0); glBindTexture(GL_TEXTURE_BUFFER, 0); +#else + glGenTextures(1, &heightmaptexture); + glBindTexture(GL_TEXTURE_2D, heightmaptexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, height, 0, GL_RED, GL_FLOAT, hm_array); + glBindTexture(GL_TEXTURE_2D, 0); +#endif delete[] hm_array; -#endif } static @@ -505,11 +513,9 @@ void ParticleSystemProxy::simulate() glEnable(GL_RASTERIZER_DISCARD); if (has_height_map) { -#if !defined(USE_GLES2) HeightmapSimulationShader::getInstance()->use(); HeightmapSimulationShader::getInstance()->setTextureUnits(heightmaptexture); HeightmapSimulationShader::getInstance()->setUniforms(matrix, timediff, active_count, size_increase_factor, track_x, track_x_len, track_z, track_z_len); -#endif } else {