1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-11 23:54:09 +02:00

OpenGL FFP fixes

This commit is contained in:
XProger
2020-05-08 03:01:16 +03:00
parent 39137fc3c4
commit 6ad091f59c
5 changed files with 69 additions and 32 deletions

View File

@@ -255,6 +255,7 @@ namespace Core {
int texMinSize;
bool shaderBinary;
bool VAO;
bool VBO;
bool depthTexture;
bool shadowSampler;
bool discardFrame;
@@ -484,7 +485,7 @@ struct PSO {
uint32 renderState;
};
#if defined(_OS_WIN) || defined(_OS_LINUX) || defined(_OS_MAC) || defined(_OS_WEB)
#if !defined(FFP) && (defined(_OS_WIN) || defined(_OS_LINUX) || defined(_OS_MAC) || defined(_OS_WEB))
typedef uint32 Index;
#else
typedef uint16 Index;

View File

@@ -48,7 +48,10 @@ namespace Debug {
}
void begin() {
#ifndef FFP
glActiveTexture(GL_TEXTURE0);
glUseProgram(0);
#endif
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((GLfloat*)&Core::mProj);
@@ -59,7 +62,6 @@ namespace Debug {
glLineWidth(3);
glPointSize(32);
glUseProgram(0);
Core::active.shader = NULL;
Core::active.textures[0] = NULL;
Core::validateRenderState();

View File

@@ -922,8 +922,9 @@ namespace GAPI {
void generateMipMap() {
bind(0);
glGenerateMipmap(target);
if (glGenerateMipmap) {
glGenerateMipmap(target);
}
if ((opt & (OPT_VOLUME | OPT_CUBEMAP | OPT_NEAREST)) == 0 && (Core::support.maxAniso > 0)) {
glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, min(int(Core::support.maxAniso), 8));
if (Core::support.texMaxLevel) {
@@ -945,7 +946,13 @@ namespace GAPI {
if (Core::active.textures[sampler] != this) {
Core::active.textures[sampler] = this;
#ifdef FFP
if (sampler != sDiffuse) {
return;
}
#else
glActiveTexture(GL_TEXTURE0 + sampler);
#endif
glBindTexture(target, ID);
}
}
@@ -953,7 +960,13 @@ namespace GAPI {
void unbind(int sampler) {
if (Core::active.textures[sampler]) {
Core::active.textures[sampler] = NULL;
#ifdef FFP
if (sampler != sDiffuse) {
return;
}
#else
glActiveTexture(GL_TEXTURE0 + sampler);
#endif
glBindTexture(target, 0);
}
}
@@ -996,21 +1009,27 @@ namespace GAPI {
if (Core::support.VAO)
glBindVertexArray(Core::active.VAO = 0);
bool useVBO = Core::support.VBO;
#ifdef DYNGEOM_NO_VBO
if (!vertices && !indices) {
iBuffer = new Index[iCount];
vBuffer = new GAPI::Vertex[vCount];
return;
useVBO = false;
}
#endif
#endif
ASSERT(sizeof(GAPI::Vertex) == sizeof(::Vertex));
glGenBuffers(2, ID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID[0]);
glBindBuffer(GL_ARRAY_BUFFER, ID[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, iCount * sizeof(Index), indices, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vCount * sizeof(Vertex), vertices, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
if (useVBO) {
glGenBuffers(2, ID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID[0]);
glBindBuffer(GL_ARRAY_BUFFER, ID[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, iCount * sizeof(Index), indices, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vCount * sizeof(Vertex), vertices, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
} else {
iBuffer = new Index[iCount];
vBuffer = new GAPI::Vertex[vCount];
update(indices, iCount, vertices, vCount);
}
if (Core::support.VAO && aCount) {
VAO = new GLuint[aCount];
@@ -1078,9 +1097,9 @@ namespace GAPI {
void bind(const MeshRange &range) const {
if (range.aIndex == -1) {
if (Core::active.iBuffer != ID[0])
if (Core::support.VBO && Core::active.iBuffer != ID[0])
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Core::active.iBuffer = ID[0]);
if (Core::active.vBuffer != ID[1])
if (Core::support.VBO && Core::active.vBuffer != ID[1])
glBindBuffer(GL_ARRAY_BUFFER, Core::active.vBuffer = ID[1]);
setupFVF(vBuffer + range.vStart);
} else {
@@ -1261,6 +1280,7 @@ namespace GAPI {
support.shaderBinary = extSupport(ext, "_program_binary");
support.VAO = GLES3 || extSupport(ext, "_vertex_array_object");
support.VBO = glGenBuffers != NULL;
support.depthTexture = GLES3 || extSupport(ext, "_depth_texture");
support.shadowSampler = _GL_EXT_shadow_samplers || _GL_ARB_shadow;
support.discardFrame = extSupport(ext, "_discard_framebuffer");
@@ -1314,8 +1334,6 @@ namespace GAPI {
glEnable(GL_SCISSOR_TEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&defaultFBO);
glGenFramebuffers(1, &FBO);
glDepthFunc(GL_LEQUAL);
#ifdef FFP
@@ -1333,6 +1351,9 @@ namespace GAPI {
glClearColor(0, 0, 0, 0);
#else
glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&defaultFBO);
glGenFramebuffers(1, &FBO);
char extHeader[256];
GLSL_HEADER_VERT[0] = GLSL_HEADER_FRAG[0] = extHeader[0] = 0;
if (_GL_OES_standard_derivatives) {
@@ -1405,6 +1426,9 @@ namespace GAPI {
}
void deinit() {
#ifdef FFP
return;
#endif
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &FBO);
@@ -1442,10 +1466,16 @@ namespace GAPI {
void resetState() {
if (Core::support.VAO)
glBindVertexArray(0);
glActiveTexture(GL_TEXTURE0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
#ifndef FFP
glActiveTexture(GL_TEXTURE0);
glUseProgram(0);
#endif
if (Core::support.VBO) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
int cacheRenderTarget(bool depth, int width, int height) {

View File

@@ -1452,6 +1452,10 @@ struct Inventory {
}
void prepareBackground() {
#ifdef FFP
return;
#endif
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
return;
@@ -1468,13 +1472,6 @@ struct Inventory {
Core::setDepthTest(false);
Core::setBlendMode(bmNone);
#ifdef FFP
mat4 m;
m.identity();
Core::setViewProj(m, m);
Core::mModel.identity();
#endif
int viewsCount = (Core::settings.detail.stereo == Core::Settings::STEREO_OFF) ? 1 : 2;
mat4 mProj, mView;

View File

@@ -356,13 +356,14 @@ struct Level : IGame {
delete shadow[0];
delete shadow[1];
shadow[0] = shadow[1] = NULL;
#ifndef FFP
if (Core::settings.detail.shadows > Core::Settings::LOW) {
if (level.isTitle())
shadow[0] = new Texture(32, 32, 1, FMT_SHADOW); // init dummy shadow map
else
shadow[0] = new Texture(SHADOW_TEX_SIZE, SHADOW_TEX_SIZE, 1, FMT_SHADOW, OPT_TARGET);
}
#endif
}
virtual void applySettings(const Core::Settings &settings) {
@@ -607,6 +608,10 @@ struct Level : IGame {
}
virtual void renderEnvironment(int roomIndex, const vec3 &pos, Texture **targets, int stride = 0, Core::Pass pass = Core::passAmbient) {
#ifdef FFP
return;
#endif
#ifdef _GAPI_SW
return;
#endif
@@ -1021,7 +1026,7 @@ struct Level : IGame {
delete zoneCache;
delete atlasRooms;
#if !defined(_GAPI_SW) && !defined(_GAPI_GU)
#ifndef FFP
delete atlasObjects;
delete atlasSprites;
delete atlasGlyphs;
@@ -1710,7 +1715,7 @@ struct Level : IGame {
short4 uv = t.getMinMax();
uv.z++;
uv.w++;
level.fillObjectTexture((Tile32*)tiles[t.tile].data, uv, &t);
level.fillObjectTexture((AtlasTile*)tiles[t.tile].data, uv, &t);
}
for (int i = 0; i < level.spriteTexturesCount; i++) {
@@ -1718,7 +1723,7 @@ struct Level : IGame {
short4 uv = t.getMinMax();
uv.z++;
uv.w++;
level.fillObjectTexture((Tile32*)tiles[t.tile].data, uv, &t);
level.fillObjectTexture((AtlasTile*)tiles[t.tile].data, uv, &t);
}
for (int i = 0; i < level.tilesCount; i++) {
@@ -3136,6 +3141,7 @@ struct Level : IGame {
ambientCache->processQueue();
}
#ifndef FFP
if (shadow[0] && players[0]) {
player = players[0];
renderShadows(player->getRoomIndex(), shadow[0]);
@@ -3149,6 +3155,7 @@ struct Level : IGame {
renderShadows(player->getRoomIndex(), shadow[1]);
}
}
#endif
if (copyBg) {
inventory->prepareBackground();