mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-14 00:54:05 +02:00
#11 clear scene depth buffer before rendering inventory, reduce number of temporary background textures, fix for NPOT title screens
This commit is contained in:
18
src/cache.h
18
src/cache.h
@@ -305,7 +305,7 @@ struct AmbientCache {
|
||||
for (int j = 0; j < 6; j++) {
|
||||
Texture *src = textures[j * 4 + i - 1];
|
||||
Texture *dst = textures[j * 4 + i];
|
||||
Core::setTarget(dst, true);
|
||||
Core::setTarget(dst, CLEAR_ALL);
|
||||
src->bind(sDiffuse);
|
||||
game->getMesh()->renderQuad();
|
||||
}
|
||||
@@ -449,7 +449,7 @@ struct WaterCache {
|
||||
blank = false;
|
||||
|
||||
// texture may be initialized with trash, so...
|
||||
Core::setTarget(data[0], true);
|
||||
Core::setTarget(data[0], CLEAR_ALL);
|
||||
Core::validateRenderState(); // immediate clear
|
||||
Core::invalidateTarget(false, true);
|
||||
}
|
||||
@@ -585,7 +585,7 @@ struct WaterCache {
|
||||
Core::active.shader->setParam(uParam, vec4(p.x, p.z, drop.radius * DETAIL, drop.strength));
|
||||
|
||||
item.data[0]->bind(sDiffuse);
|
||||
Core::setTarget(item.data[1], true);
|
||||
Core::setTarget(item.data[1], CLEAR_ALL);
|
||||
Core::setViewport(0, 0, int(item.size.x * DETAIL * 2.0f + 0.5f), int(item.size.z * DETAIL * 2.0f + 0.5f));
|
||||
game->getMesh()->renderQuad();
|
||||
Core::invalidateTarget(false, true);
|
||||
@@ -603,7 +603,7 @@ struct WaterCache {
|
||||
while (item.timer >= SIMULATE_TIMESTEP) {
|
||||
// water step
|
||||
item.data[0]->bind(sDiffuse);
|
||||
Core::setTarget(item.data[1], true);
|
||||
Core::setTarget(item.data[1], CLEAR_ALL);
|
||||
Core::setViewport(0, 0, int(item.size.x * DETAIL * 2.0f + 0.5f), int(item.size.z * DETAIL * 2.0f + 0.5f));
|
||||
game->getMesh()->renderQuad();
|
||||
Core::invalidateTarget(false, true);
|
||||
@@ -623,12 +623,12 @@ struct WaterCache {
|
||||
|
||||
Core::whiteTex->bind(sReflect);
|
||||
item.data[0]->bind(sNormal);
|
||||
Core::setTarget(item.caustics, true);
|
||||
Core::setTarget(item.caustics, CLEAR_ALL);
|
||||
game->getMesh()->renderPlane();
|
||||
Core::invalidateTarget(false, true);
|
||||
#ifdef BLUR_CAUSTICS
|
||||
// v blur
|
||||
Core::setTarget(item.caustics_tmp, true);
|
||||
Core::setTarget(item.caustics_tmp, CLEAR_ALL);
|
||||
game->setShader(Core::passFilter, Shader::FILTER_BLUR, false, false);
|
||||
Core::active.shader->setParam(uParam, vec4(0, 1, 1.0f / item.caustics->width, 0));;
|
||||
item.caustics->bind(sDiffuse);
|
||||
@@ -636,7 +636,7 @@ struct WaterCache {
|
||||
Core::invalidateTarget(false, true);
|
||||
|
||||
// h blur
|
||||
Core::setTarget(item.caustics, true);
|
||||
Core::setTarget(item.caustics, CLEAR_ALL);
|
||||
game->setShader(Core::passFilter, Shader::FILTER_BLUR, false, false);
|
||||
Core::active.shader->setParam(uParam, vec4(1, 0, 1.0f / item.caustics->width, 0));;
|
||||
item.caustics_tmp->bind(sDiffuse);
|
||||
@@ -689,7 +689,7 @@ struct WaterCache {
|
||||
if (!refract || w != refract->width || h != refract->height) {
|
||||
delete refract;
|
||||
refract = new Texture(w, h, Texture::RGBA, false);
|
||||
Core::setTarget(refract, true);
|
||||
Core::setTarget(refract, CLEAR_ALL);
|
||||
Core::validateRenderState(); // immediate clear
|
||||
Core::invalidateTarget(false, true);
|
||||
Core::setTarget(NULL);
|
||||
@@ -728,7 +728,7 @@ struct WaterCache {
|
||||
}
|
||||
|
||||
// render mirror reflection
|
||||
Core::setTarget(reflect, true);
|
||||
Core::setTarget(reflect, CLEAR_ALL);
|
||||
Camera *camera = (Camera*)game->getCamera();
|
||||
game->setupBinding();
|
||||
|
||||
|
21
src/core.h
21
src/core.h
@@ -503,6 +503,12 @@ enum RenderState {
|
||||
RS_ALPHA_TEST = 1 << 14,
|
||||
};
|
||||
|
||||
enum ClearMode {
|
||||
CLEAR_COLOR = 1,
|
||||
CLEAR_DEPTH = 2,
|
||||
CLEAR_ALL = CLEAR_COLOR | CLEAR_DEPTH,
|
||||
};
|
||||
|
||||
typedef uint16 Index;
|
||||
|
||||
struct Vertex {
|
||||
@@ -653,7 +659,7 @@ namespace Core {
|
||||
|
||||
struct ReqTarget {
|
||||
Texture *texture;
|
||||
bool clear;
|
||||
uint8 clear;
|
||||
uint8 face;
|
||||
} reqTarget;
|
||||
|
||||
@@ -1278,7 +1284,7 @@ namespace Core {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FFP
|
||||
if (mask & RS_ALPHA_TEST) {
|
||||
#ifdef _PSP
|
||||
if (renderState & RS_ALPHA_TEST)
|
||||
@@ -1292,13 +1298,16 @@ namespace Core {
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
if (mask & RS_TARGET) {
|
||||
if (reqTarget.clear) {
|
||||
#ifdef _PSP
|
||||
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT | GU_FAST_CLEAR_BIT);
|
||||
sceGuClear(((reqTarget.clear & CLEAR_COLOR) ? GU_COLOR_BUFFER_BIT : 0) |
|
||||
((reqTarget.clear & CLEAR_DEPTH) ? GU_DEPTH_BUFFER_BIT : 0) |
|
||||
GU_FAST_CLEAR_BIT);
|
||||
#else
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glClear(((reqTarget.clear & CLEAR_COLOR) ? GL_COLOR_BUFFER_BIT : 0) |
|
||||
((reqTarget.clear & CLEAR_DEPTH) ? GL_DEPTH_BUFFER_BIT : 0));
|
||||
#endif
|
||||
}
|
||||
renderState &= ~RS_TARGET;
|
||||
@@ -1384,7 +1393,7 @@ namespace Core {
|
||||
#endif
|
||||
}
|
||||
|
||||
void setTarget(Texture *target, bool clear = false, int face = 0) {
|
||||
void setTarget(Texture *target, uint8 clear = 0, uint8 face = 0) {
|
||||
if (!target)
|
||||
target = defaultTarget;
|
||||
|
||||
|
@@ -104,7 +104,7 @@ struct OptionItem {
|
||||
}
|
||||
};
|
||||
|
||||
#define SETTINGS(x) offsetof(Core::Settings, x)
|
||||
#define SETTINGS(x) OFFSETOF(Core::Settings, x)
|
||||
|
||||
static const OptionItem optDetail[] = {
|
||||
OptionItem( OptionItem::TYPE_TITLE, STR_SELECT_DETAIL ),
|
||||
@@ -191,7 +191,7 @@ struct Inventory {
|
||||
};
|
||||
|
||||
IGame *game;
|
||||
Texture *background[3];
|
||||
Texture *background[2];
|
||||
|
||||
bool active;
|
||||
bool chosen;
|
||||
@@ -1097,28 +1097,30 @@ struct Inventory {
|
||||
//
|
||||
#else
|
||||
// vertical blur
|
||||
Core::setTarget(background[1], true);
|
||||
Core::setTarget(background[1], CLEAR_COLOR);
|
||||
game->setShader(Core::passFilter, Shader::FILTER_BLUR, false, false);
|
||||
Core::active.shader->setParam(uParam, vec4(0, 1, 1.0f / INVENTORY_BG_SIZE, 0));;
|
||||
background[0]->bind(sDiffuse);
|
||||
game->getMesh()->renderQuad();
|
||||
|
||||
// horizontal blur
|
||||
Core::setTarget(background[2], true);
|
||||
Core::setTarget(background[0], CLEAR_COLOR);
|
||||
game->setShader(Core::passFilter, Shader::FILTER_BLUR, false, false);
|
||||
Core::active.shader->setParam(uParam, vec4(1, 0, 1.0f / INVENTORY_BG_SIZE, 0));;
|
||||
background[1]->bind(sDiffuse);
|
||||
game->getMesh()->renderQuad();
|
||||
|
||||
// grayscale
|
||||
Core::setTarget(background[1], true);
|
||||
Core::setTarget(background[1], CLEAR_COLOR);
|
||||
game->setShader(Core::passFilter, Shader::FILTER_GRAYSCALE, false, false);
|
||||
Core::active.shader->setParam(uParam, vec4(1, 0, 0, 0));
|
||||
background[2]->bind(sDiffuse);
|
||||
background[0]->bind(sDiffuse);
|
||||
game->getMesh()->renderQuad();
|
||||
|
||||
swap(background[0], background[1]);
|
||||
#endif
|
||||
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, CLEAR_ALL); // TODO: ???
|
||||
|
||||
Core::setDepthTest(true);
|
||||
}
|
||||
@@ -1274,6 +1276,7 @@ struct Inventory {
|
||||
float aspectDst = float(Core::width) / float(Core::height);
|
||||
float aspectImg = aspectSrc / aspectDst;
|
||||
float ax = background[0]->origWidth / float(background[0]->width);
|
||||
float ay = background[0]->origHeight / float(background[0]->height);
|
||||
|
||||
#ifdef FFP
|
||||
mat4 m;
|
||||
@@ -1325,6 +1328,8 @@ struct Inventory {
|
||||
}
|
||||
|
||||
short tw = short(ax * 32767);
|
||||
short th = short(ay * 32767);
|
||||
|
||||
vertices[ 0].coord = short4(-size.x, size.y, 0, 0);
|
||||
vertices[ 1].coord = short4( size.x, size.y, 0, 0);
|
||||
vertices[ 2].coord = short4( size.x, -size.y, 0, 0);
|
||||
@@ -1343,10 +1348,10 @@ struct Inventory {
|
||||
vertices[10].light =
|
||||
vertices[11].light = ubyte4(0, 0, 0, alpha);
|
||||
|
||||
vertices[ 0].texCoord = short4( 0, 0, 0, 0);
|
||||
vertices[ 1].texCoord = short4(tw, 0, 0, 0);
|
||||
vertices[ 2].texCoord = short4(tw, 32767, 0, 0);
|
||||
vertices[ 3].texCoord = short4( 0, 32767, 0, 0);
|
||||
vertices[ 0].texCoord = short4( 0, 0, 0, 0);
|
||||
vertices[ 1].texCoord = short4(tw, 0, 0, 0);
|
||||
vertices[ 2].texCoord = short4(tw, th, 0, 0);
|
||||
vertices[ 3].texCoord = short4( 0, th, 0, 0);
|
||||
vertices[ 4].texCoord =
|
||||
vertices[ 5].texCoord =
|
||||
vertices[ 6].texCoord =
|
||||
@@ -1362,6 +1367,7 @@ struct Inventory {
|
||||
}
|
||||
|
||||
void renderGameBG() {
|
||||
Core::setTarget(NULL, CLEAR_DEPTH);
|
||||
#ifdef _PSP
|
||||
return;
|
||||
#endif
|
||||
@@ -1383,7 +1389,7 @@ struct Inventory {
|
||||
game->setShader(Core::passFilter, Shader::DEFAULT, false, false);
|
||||
|
||||
// blured grayscale image
|
||||
background[1]->bind(sDiffuse);
|
||||
background[0]->bind(sDiffuse);
|
||||
Core::setBlending(phaseRing < 1.0f ? bmAlpha : bmNone);
|
||||
game->getMesh()->renderBuffer(indices, COUNT(indices), vertices, COUNT(vertices));
|
||||
}
|
||||
|
20
src/level.h
20
src/level.h
@@ -388,7 +388,7 @@ struct Level : IGame {
|
||||
setupCubeCamera(pos, i);
|
||||
Core::pass = pass;
|
||||
Texture *target = (targets[0]->opt & Texture::CUBEMAP) ? targets[0] : targets[i * stride];
|
||||
Core::setTarget(target, true, i);
|
||||
Core::setTarget(target, CLEAR_ALL, i);
|
||||
renderView(roomIndex, false, false);
|
||||
Core::invalidateTarget(false, true);
|
||||
}
|
||||
@@ -1785,7 +1785,7 @@ struct Level : IGame {
|
||||
}
|
||||
|
||||
if (water) {
|
||||
Core::setTarget(NULL, Core::settings.detail.stereo == Core::Settings::STEREO_OFF && players[1] == NULL); // render to back buffer
|
||||
Core::setTarget(NULL, (Core::settings.detail.stereo == Core::Settings::STEREO_OFF && players[1] == NULL) ? CLEAR_ALL : 0); // render to back buffer
|
||||
setupBinding();
|
||||
}
|
||||
|
||||
@@ -1860,7 +1860,7 @@ struct Level : IGame {
|
||||
bool colorShadow = shadow->format == Texture::RGBA ? true : false;
|
||||
if (colorShadow)
|
||||
Core::setClearColor(vec4(1.0f));
|
||||
Core::setTarget(shadow, true);
|
||||
Core::setTarget(shadow, CLEAR_ALL);
|
||||
setupLightCamera();
|
||||
Core::setCulling(cfBack);
|
||||
|
||||
@@ -2117,7 +2117,7 @@ struct Level : IGame {
|
||||
ambientCache->processQueue();
|
||||
|
||||
//if (Core::settings.detail.stereo || Core::settings.detail.splitscreen) {
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, CLEAR_ALL);
|
||||
Core::validateRenderState();
|
||||
//}
|
||||
|
||||
@@ -2131,7 +2131,7 @@ struct Level : IGame {
|
||||
if (!cube360)
|
||||
cube360 = new Texture(1024, 1024, Texture::RGBA, true, NULL, true, false);
|
||||
renderEnvironment(camera->getRoomIndex(), camera->pos, &cube360, 0, Core::passCompose);
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, Core::CLEAR_ALL);
|
||||
setShader(Core::passFilter, Shader::FILTER_EQUIRECTANGULAR);
|
||||
cube360->bind(sEnvironment);
|
||||
mesh->renderQuad();
|
||||
@@ -2160,14 +2160,14 @@ struct Level : IGame {
|
||||
|
||||
Core::defaultTarget = Core::eyeTex[0];
|
||||
Core::viewportDef = vec4(0, 0, float(Core::defaultTarget->width), float(Core::defaultTarget->height));
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, CLEAR_ALL);
|
||||
Core::eye = -1.0f;
|
||||
setup();
|
||||
renderView(camera->getRoomIndex(), true, false);
|
||||
|
||||
Core::defaultTarget = Core::eyeTex[1];
|
||||
Core::viewportDef = vec4(0, 0, float(Core::defaultTarget->width), float(Core::defaultTarget->height));
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, CLEAR_ALL);
|
||||
Core::eye = 1.0f;
|
||||
setup();
|
||||
renderView(camera->getRoomIndex(), true, false);
|
||||
@@ -2175,7 +2175,7 @@ struct Level : IGame {
|
||||
Core::settings.detail.vr = false;
|
||||
|
||||
Core::defaultTarget = oldTarget;
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, CLEAR_ALL);
|
||||
Core::viewportDef = vp;
|
||||
}
|
||||
|
||||
@@ -2268,7 +2268,7 @@ struct Level : IGame {
|
||||
}
|
||||
|
||||
void renderInventory(bool clear) {
|
||||
Core::setTarget(NULL, clear);
|
||||
Core::setTarget(NULL, clear ? CLEAR_ALL : 0);
|
||||
|
||||
if (!(level.isTitle() || inventory.titleTimer > 0.0f))
|
||||
inventory.renderBackground();
|
||||
@@ -2289,7 +2289,7 @@ struct Level : IGame {
|
||||
lastTitle = title;
|
||||
|
||||
if (isEnded) {
|
||||
Core::setTarget(NULL, true);
|
||||
Core::setTarget(NULL, CLEAR_ALL);
|
||||
UI::begin();
|
||||
UI::textOut(vec2(0, 480 - 16), STR_LOADING, UI::aCenter, UI::width);
|
||||
UI::end();
|
||||
|
@@ -76,6 +76,7 @@ typedef unsigned int uint32;
|
||||
#define FOURCC(str) uint32(((uint8*)(str))[0] | (((uint8*)(str))[1] << 8) | (((uint8*)(str))[2] << 16) | (((uint8*)(str))[3] << 24) )
|
||||
|
||||
#define COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#define OFFSETOF(T, E) ((size_t)&(((T*)0)->E))
|
||||
|
||||
template <typename T>
|
||||
inline const T& min(const T &a, const T &b) {
|
||||
|
Reference in New Issue
Block a user