mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-20 03:41:33 +02:00
#23 fix water effect for most mobile devices; fix water in inventory background
This commit is contained in:
30
src/cache.h
30
src/cache.h
@@ -402,9 +402,9 @@ struct WaterCache {
|
||||
size = vec3(float((maxX - minX) * 512), 1.0f, float((maxZ - minZ) * 512)); // half size
|
||||
pos = vec3(r.info.x + minX * 1024 + size.x, float(posY), r.info.z + minZ * 1024 + size.z);
|
||||
|
||||
data[0] = new Texture(w * 64, h * 64, Texture::RGBA_HALF, false);
|
||||
data[1] = new Texture(w * 64, h * 64, Texture::RGBA_HALF, false);
|
||||
caustics = new Texture(512, 512, Texture::RGB16, false);
|
||||
data[0] = new Texture(w * 64, h * 64, Texture::RGBA_HALF);
|
||||
data[1] = new Texture(w * 64, h * 64, Texture::RGBA_HALF);
|
||||
caustics = new Texture(512, 512, Texture::RGB16);
|
||||
mask = new Texture(w, h, Texture::RGB16, false, m, false);
|
||||
delete[] m;
|
||||
|
||||
@@ -413,6 +413,7 @@ struct WaterCache {
|
||||
// texture may be initialized with trash, so...
|
||||
Core::setTarget(data[0], true);
|
||||
Core::validateRenderState(); // immediate clear
|
||||
Core::invalidateTarget(false, true);
|
||||
}
|
||||
|
||||
void free() {
|
||||
@@ -614,21 +615,31 @@ struct WaterCache {
|
||||
Core::setCulling(cfFront);
|
||||
}
|
||||
|
||||
void getRefract() {
|
||||
int w = int(Core::viewportDef.z);
|
||||
int h = int(Core::viewportDef.w);
|
||||
void getTargetSize(int &w, int &h) {
|
||||
if (Core::active.target != NULL) {
|
||||
w = Core::active.target->width;
|
||||
h = Core::active.target->height;
|
||||
} else {
|
||||
w = int(Core::viewportDef.z);
|
||||
h = int(Core::viewportDef.w);
|
||||
}
|
||||
}
|
||||
|
||||
void getRefract() {
|
||||
int w, h;
|
||||
getTargetSize(w, h);
|
||||
// get refraction texture
|
||||
if (!refract || w != refract->width || h != refract->height) {
|
||||
delete refract;
|
||||
refract = new Texture(w, h, Texture::RGBA, false);
|
||||
}
|
||||
Core::copyTarget(refract, 0, 0, int(Core::viewportDef.x), int(Core::viewportDef.y), w, h); // copy framebuffer into refraction texture
|
||||
Core::copyTarget(refract, 0, 0, 0, 0, w, h); // copy framebuffer into refraction texture
|
||||
}
|
||||
|
||||
void simulate() {
|
||||
// simulate water
|
||||
Core::setDepthTest(false);
|
||||
Core::setBlending(bmNone);
|
||||
for (int i = 0; i < count; i++) {
|
||||
Item &item = items[i];
|
||||
if (!item.visible) continue;
|
||||
@@ -702,7 +713,10 @@ struct WaterCache {
|
||||
game->setShader(Core::passWater, Shader::WATER_COMPOSE);
|
||||
Core::active.shader->setParam(uLightPos, Core::lightPos[0], 1);
|
||||
Core::active.shader->setParam(uLightColor, Core::lightColor[0], 1);
|
||||
Core::active.shader->setParam(uParam, vec4(Core::viewportDef.z / refract->width, Core::viewportDef.w / refract->height, 0.05f, 0.02f));
|
||||
|
||||
int w, h;
|
||||
getTargetSize(w, h);
|
||||
Core::active.shader->setParam(uParam, vec4(float(w) / refract->width, float(h) / refract->height, 0.05f, 0.02f));
|
||||
|
||||
float sx = item.size.x * DETAIL / (item.data[0]->width / 2);
|
||||
float sz = item.size.z * DETAIL / (item.data[0]->height / 2);
|
||||
|
52
src/core.h
52
src/core.h
@@ -19,13 +19,9 @@
|
||||
#define GL_TEXTURE_COMPARE_FUNC 0x884D
|
||||
#define GL_COMPARE_REF_TO_TEXTURE 0x884E
|
||||
|
||||
#undef GL_RGBA32F
|
||||
#undef GL_RGBA16F
|
||||
#undef GL_HALF_FLOAT
|
||||
|
||||
#define GL_RGBA32F GL_RGBA
|
||||
#define GL_RGBA16F GL_RGBA
|
||||
#define GL_HALF_FLOAT GL_HALF_FLOAT_OES
|
||||
#define GL_RGBA16F 0x881A
|
||||
#define GL_RGBA32F 0x8814
|
||||
#define GL_HALF_FLOAT 0x140B
|
||||
|
||||
#define GL_DEPTH_STENCIL GL_DEPTH_STENCIL_OES
|
||||
#define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES
|
||||
@@ -110,9 +106,6 @@
|
||||
#include <OpenGL/glext.h>
|
||||
#include <AGL/agl.h>
|
||||
|
||||
#define GL_RGBA32F GL_RGBA
|
||||
#define GL_RGBA16F GL_RGBA
|
||||
|
||||
#define GL_RGB565 GL_RGBA
|
||||
#define GL_TEXTURE_COMPARE_MODE 0x884C
|
||||
#define GL_TEXTURE_COMPARE_FUNC 0x884D
|
||||
@@ -133,14 +126,6 @@
|
||||
#include <GLES3/gl3.h>
|
||||
#include <GLES3/gl2ext.h>
|
||||
|
||||
#undef GL_RGBA32F
|
||||
#undef GL_RGBA16F
|
||||
#undef GL_HALF_FLOAT
|
||||
|
||||
#define GL_RGBA32F GL_RGBA
|
||||
#define GL_RGBA16F GL_RGBA
|
||||
#define GL_HALF_FLOAT GL_HALF_FLOAT_OES
|
||||
|
||||
#define GL_CLAMP_TO_BORDER GL_CLAMP_TO_BORDER_EXT
|
||||
#define GL_TEXTURE_BORDER_COLOR GL_TEXTURE_BORDER_COLOR_EXT
|
||||
|
||||
@@ -293,8 +278,8 @@ namespace Core {
|
||||
bool texNPOT;
|
||||
bool texRG;
|
||||
bool texBorder;
|
||||
bool texFloat, texFloatLinear;
|
||||
bool texHalf, texHalfLinear;
|
||||
bool colorFloat, texFloat, texFloatLinear;
|
||||
bool colorHalf, texHalf, texHalfLinear;
|
||||
#ifdef PROFILE
|
||||
bool profMarker;
|
||||
bool profTiming;
|
||||
@@ -409,6 +394,7 @@ namespace Core {
|
||||
}
|
||||
|
||||
void stop() {
|
||||
glFlush();
|
||||
if (fpsTime < getTime()) {
|
||||
LOG("FPS: %d DIP: %d TRI: %d\n", fps, dips, tris);
|
||||
#ifdef PROFILE
|
||||
@@ -522,8 +508,20 @@ namespace Core {
|
||||
|
||||
|
||||
char *ext = (char*)glGetString(GL_EXTENSIONS);
|
||||
LOG("%s\n", ext);
|
||||
|
||||
/*
|
||||
if (ext != NULL) {
|
||||
char buf[255];
|
||||
int len = strlen(ext);
|
||||
int start = 0;
|
||||
for (int i = 0; i < len; i++)
|
||||
if (ext[i] == ' ' || (i == len - 1)) {
|
||||
memcpy(buf, &ext[start], i - start);
|
||||
buf[i - start] = 0;
|
||||
LOG("%s\n", buf);
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
support.shaderBinary = extSupport(ext, "_program_binary");
|
||||
support.VAO = extSupport(ext, "_vertex_array_object");
|
||||
support.depthTexture = extSupport(ext, "_depth_texture");
|
||||
@@ -532,9 +530,11 @@ namespace Core {
|
||||
support.texNPOT = extSupport(ext, "_texture_npot") || extSupport(ext, "_texture_non_power_of_two");
|
||||
support.texRG = extSupport(ext, "_texture_rg "); // hope that isn't last extension in string ;)
|
||||
support.texBorder = extSupport(ext, "_texture_border_clamp");
|
||||
support.texFloatLinear = extSupport(ext, "GL_ARB_texture_float") || extSupport(ext, "_texture_float_linear");
|
||||
support.colorFloat = extSupport(ext, "_color_buffer_float");
|
||||
support.colorHalf = extSupport(ext, "_color_buffer_half_float") || extSupport(ext, "GL_ARB_half_float_pixel");
|
||||
support.texFloatLinear = support.colorFloat || extSupport(ext, "GL_ARB_texture_float") || extSupport(ext, "_texture_float_linear");
|
||||
support.texFloat = support.texFloatLinear || extSupport(ext, "_texture_float");
|
||||
support.texHalfLinear = extSupport(ext, "GL_ARB_texture_float") || extSupport(ext, "_texture_half_float_linear");
|
||||
support.texHalfLinear = support.colorHalf || extSupport(ext, "GL_ARB_texture_float") || extSupport(ext, "_texture_half_float_linear") || extSupport(ext, "_color_buffer_half_float");
|
||||
support.texHalf = support.texHalfLinear || extSupport(ext, "_texture_half_float");
|
||||
|
||||
#ifdef PROFILE
|
||||
@@ -556,8 +556,8 @@ namespace Core {
|
||||
LOG(" RG textures : %s\n", support.texRG ? "true" : "false");
|
||||
LOG(" border color : %s\n", support.texBorder ? "true" : "false");
|
||||
LOG(" float textures : float = %s, half = %s\n",
|
||||
support.texFloat ? (support.texFloatLinear ? "linear" : "nearest") : "false",
|
||||
support.texHalf ? (support.texHalfLinear ? "linear" : "nearest") : "false");
|
||||
support.colorFloat ? "full" : (support.texFloat ? (support.texFloatLinear ? "linear" : "nearest") : "false"),
|
||||
support.colorHalf ? "full" : (support.texHalf ? (support.texHalfLinear ? "linear" : "nearest") : "false"));
|
||||
LOG("\n");
|
||||
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&defaultFBO);
|
||||
|
@@ -383,8 +383,6 @@ struct Inventory {
|
||||
bool ready = active && phaseRing == 1.0f && phasePage == 1.0f;
|
||||
|
||||
if (index == targetIndex && targetPage == page && ready && !chosen) {
|
||||
float s = Input::touchTimerVis > 0.0f ? -1.0f : 1.0f;
|
||||
|
||||
if (Input::state[cLeft] || Input::joy.L.x < -0.5f || Input::joy.R.x > 0.5f) { phaseSelect = 0.0f; targetIndex = (targetIndex - 1 + count) % count; }
|
||||
if (Input::state[cRight] || Input::joy.L.x > 0.5f || Input::joy.R.x < -0.5f) { phaseSelect = 0.0f; targetIndex = (targetIndex + 1) % count; }
|
||||
if ((Input::state[cUp] || Input::joy.L.y < -0.5f || Input::joy.R.y > 0.5f) && page < PAGE_ITEMS && getItemsCount(page + 1)) { phasePage = 0.0f; targetPage = Page(page + 1); }
|
||||
|
@@ -11,7 +11,7 @@ struct Texture {
|
||||
Format format;
|
||||
bool cube;
|
||||
|
||||
Texture(int width, int height, Format format, bool cube, void *data = NULL, bool filter = true, bool mips = false) : cube(cube) {
|
||||
Texture(int width, int height, Format format, bool cube = false, void *data = NULL, bool filter = true, bool mips = false) : cube(cube) {
|
||||
if (!Core::support.texNPOT) {
|
||||
width = nextPow2(width);
|
||||
height = nextPow2(height);
|
||||
@@ -84,7 +84,15 @@ struct Texture {
|
||||
{ GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT }, // SHADOW
|
||||
};
|
||||
|
||||
FormatDesc &desc = formats[format];
|
||||
FormatDesc desc = formats[format];
|
||||
if ((format == RGBA_FLOAT && !Core::support.colorFloat) || (format == RGBA_HALF && !Core::support.colorHalf)) {
|
||||
desc.ifmt = GL_RGBA;
|
||||
#ifdef MOBILE
|
||||
if (format == RGBA_HALF)
|
||||
desc.type = GL_HALF_FLOAT_OES;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
glTexImage2D(cube ? (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) : GL_TEXTURE_2D, 0, desc.ifmt, width, height, 0, desc.fmt, desc.type, data);
|
||||
|
Reference in New Issue
Block a user