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:
@@ -255,6 +255,7 @@ namespace Core {
|
|||||||
int texMinSize;
|
int texMinSize;
|
||||||
bool shaderBinary;
|
bool shaderBinary;
|
||||||
bool VAO;
|
bool VAO;
|
||||||
|
bool VBO;
|
||||||
bool depthTexture;
|
bool depthTexture;
|
||||||
bool shadowSampler;
|
bool shadowSampler;
|
||||||
bool discardFrame;
|
bool discardFrame;
|
||||||
@@ -484,7 +485,7 @@ struct PSO {
|
|||||||
uint32 renderState;
|
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;
|
typedef uint32 Index;
|
||||||
#else
|
#else
|
||||||
typedef uint16 Index;
|
typedef uint16 Index;
|
||||||
|
@@ -48,7 +48,10 @@ namespace Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
|
#ifndef FFP
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glUseProgram(0);
|
||||||
|
#endif
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadMatrixf((GLfloat*)&Core::mProj);
|
glLoadMatrixf((GLfloat*)&Core::mProj);
|
||||||
@@ -59,7 +62,6 @@ namespace Debug {
|
|||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
glPointSize(32);
|
glPointSize(32);
|
||||||
|
|
||||||
glUseProgram(0);
|
|
||||||
Core::active.shader = NULL;
|
Core::active.shader = NULL;
|
||||||
Core::active.textures[0] = NULL;
|
Core::active.textures[0] = NULL;
|
||||||
Core::validateRenderState();
|
Core::validateRenderState();
|
||||||
|
@@ -922,8 +922,9 @@ namespace GAPI {
|
|||||||
|
|
||||||
void generateMipMap() {
|
void generateMipMap() {
|
||||||
bind(0);
|
bind(0);
|
||||||
|
if (glGenerateMipmap) {
|
||||||
glGenerateMipmap(target);
|
glGenerateMipmap(target);
|
||||||
|
}
|
||||||
if ((opt & (OPT_VOLUME | OPT_CUBEMAP | OPT_NEAREST)) == 0 && (Core::support.maxAniso > 0)) {
|
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));
|
glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, min(int(Core::support.maxAniso), 8));
|
||||||
if (Core::support.texMaxLevel) {
|
if (Core::support.texMaxLevel) {
|
||||||
@@ -945,7 +946,13 @@ namespace GAPI {
|
|||||||
|
|
||||||
if (Core::active.textures[sampler] != this) {
|
if (Core::active.textures[sampler] != this) {
|
||||||
Core::active.textures[sampler] = this;
|
Core::active.textures[sampler] = this;
|
||||||
|
#ifdef FFP
|
||||||
|
if (sampler != sDiffuse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
glActiveTexture(GL_TEXTURE0 + sampler);
|
glActiveTexture(GL_TEXTURE0 + sampler);
|
||||||
|
#endif
|
||||||
glBindTexture(target, ID);
|
glBindTexture(target, ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -953,7 +960,13 @@ namespace GAPI {
|
|||||||
void unbind(int sampler) {
|
void unbind(int sampler) {
|
||||||
if (Core::active.textures[sampler]) {
|
if (Core::active.textures[sampler]) {
|
||||||
Core::active.textures[sampler] = NULL;
|
Core::active.textures[sampler] = NULL;
|
||||||
|
#ifdef FFP
|
||||||
|
if (sampler != sDiffuse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
glActiveTexture(GL_TEXTURE0 + sampler);
|
glActiveTexture(GL_TEXTURE0 + sampler);
|
||||||
|
#endif
|
||||||
glBindTexture(target, 0);
|
glBindTexture(target, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -996,21 +1009,27 @@ namespace GAPI {
|
|||||||
if (Core::support.VAO)
|
if (Core::support.VAO)
|
||||||
glBindVertexArray(Core::active.VAO = 0);
|
glBindVertexArray(Core::active.VAO = 0);
|
||||||
|
|
||||||
|
bool useVBO = Core::support.VBO;
|
||||||
|
|
||||||
#ifdef DYNGEOM_NO_VBO
|
#ifdef DYNGEOM_NO_VBO
|
||||||
if (!vertices && !indices) {
|
if (!vertices && !indices) {
|
||||||
iBuffer = new Index[iCount];
|
useVBO = false;
|
||||||
vBuffer = new GAPI::Vertex[vCount];
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ASSERT(sizeof(GAPI::Vertex) == sizeof(::Vertex));
|
ASSERT(sizeof(GAPI::Vertex) == sizeof(::Vertex));
|
||||||
|
|
||||||
|
if (useVBO) {
|
||||||
glGenBuffers(2, ID);
|
glGenBuffers(2, ID);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID[0]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID[0]);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, ID[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, ID[1]);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, iCount * sizeof(Index), indices, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
|
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);
|
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) {
|
if (Core::support.VAO && aCount) {
|
||||||
VAO = new GLuint[aCount];
|
VAO = new GLuint[aCount];
|
||||||
@@ -1078,9 +1097,9 @@ namespace GAPI {
|
|||||||
|
|
||||||
void bind(const MeshRange &range) const {
|
void bind(const MeshRange &range) const {
|
||||||
if (range.aIndex == -1) {
|
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]);
|
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]);
|
glBindBuffer(GL_ARRAY_BUFFER, Core::active.vBuffer = ID[1]);
|
||||||
setupFVF(vBuffer + range.vStart);
|
setupFVF(vBuffer + range.vStart);
|
||||||
} else {
|
} else {
|
||||||
@@ -1261,6 +1280,7 @@ namespace GAPI {
|
|||||||
|
|
||||||
support.shaderBinary = extSupport(ext, "_program_binary");
|
support.shaderBinary = extSupport(ext, "_program_binary");
|
||||||
support.VAO = GLES3 || extSupport(ext, "_vertex_array_object");
|
support.VAO = GLES3 || extSupport(ext, "_vertex_array_object");
|
||||||
|
support.VBO = glGenBuffers != NULL;
|
||||||
support.depthTexture = GLES3 || extSupport(ext, "_depth_texture");
|
support.depthTexture = GLES3 || extSupport(ext, "_depth_texture");
|
||||||
support.shadowSampler = _GL_EXT_shadow_samplers || _GL_ARB_shadow;
|
support.shadowSampler = _GL_EXT_shadow_samplers || _GL_ARB_shadow;
|
||||||
support.discardFrame = extSupport(ext, "_discard_framebuffer");
|
support.discardFrame = extSupport(ext, "_discard_framebuffer");
|
||||||
@@ -1314,8 +1334,6 @@ namespace GAPI {
|
|||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&defaultFBO);
|
|
||||||
glGenFramebuffers(1, &FBO);
|
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
#ifdef FFP
|
#ifdef FFP
|
||||||
@@ -1333,6 +1351,9 @@ namespace GAPI {
|
|||||||
|
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
#else
|
#else
|
||||||
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&defaultFBO);
|
||||||
|
glGenFramebuffers(1, &FBO);
|
||||||
|
|
||||||
char extHeader[256];
|
char extHeader[256];
|
||||||
GLSL_HEADER_VERT[0] = GLSL_HEADER_FRAG[0] = extHeader[0] = 0;
|
GLSL_HEADER_VERT[0] = GLSL_HEADER_FRAG[0] = extHeader[0] = 0;
|
||||||
if (_GL_OES_standard_derivatives) {
|
if (_GL_OES_standard_derivatives) {
|
||||||
@@ -1405,6 +1426,9 @@ namespace GAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deinit() {
|
void deinit() {
|
||||||
|
#ifdef FFP
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glDeleteFramebuffers(1, &FBO);
|
glDeleteFramebuffers(1, &FBO);
|
||||||
|
|
||||||
@@ -1442,10 +1466,16 @@ namespace GAPI {
|
|||||||
void resetState() {
|
void resetState() {
|
||||||
if (Core::support.VAO)
|
if (Core::support.VAO)
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
#ifndef FFP
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glUseProgram(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (Core::support.VBO) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glUseProgram(0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cacheRenderTarget(bool depth, int width, int height) {
|
int cacheRenderTarget(bool depth, int width, int height) {
|
||||||
|
@@ -1452,6 +1452,10 @@ struct Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void prepareBackground() {
|
void prepareBackground() {
|
||||||
|
#ifdef FFP
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
|
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1468,13 +1472,6 @@ struct Inventory {
|
|||||||
Core::setDepthTest(false);
|
Core::setDepthTest(false);
|
||||||
Core::setBlendMode(bmNone);
|
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;
|
int viewsCount = (Core::settings.detail.stereo == Core::Settings::STEREO_OFF) ? 1 : 2;
|
||||||
|
|
||||||
mat4 mProj, mView;
|
mat4 mProj, mView;
|
||||||
|
15
src/level.h
15
src/level.h
@@ -356,13 +356,14 @@ struct Level : IGame {
|
|||||||
delete shadow[0];
|
delete shadow[0];
|
||||||
delete shadow[1];
|
delete shadow[1];
|
||||||
shadow[0] = shadow[1] = NULL;
|
shadow[0] = shadow[1] = NULL;
|
||||||
|
#ifndef FFP
|
||||||
if (Core::settings.detail.shadows > Core::Settings::LOW) {
|
if (Core::settings.detail.shadows > Core::Settings::LOW) {
|
||||||
if (level.isTitle())
|
if (level.isTitle())
|
||||||
shadow[0] = new Texture(32, 32, 1, FMT_SHADOW); // init dummy shadow map
|
shadow[0] = new Texture(32, 32, 1, FMT_SHADOW); // init dummy shadow map
|
||||||
else
|
else
|
||||||
shadow[0] = new Texture(SHADOW_TEX_SIZE, SHADOW_TEX_SIZE, 1, FMT_SHADOW, OPT_TARGET);
|
shadow[0] = new Texture(SHADOW_TEX_SIZE, SHADOW_TEX_SIZE, 1, FMT_SHADOW, OPT_TARGET);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void applySettings(const Core::Settings &settings) {
|
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) {
|
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
|
#ifdef _GAPI_SW
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
@@ -1021,7 +1026,7 @@ struct Level : IGame {
|
|||||||
delete zoneCache;
|
delete zoneCache;
|
||||||
|
|
||||||
delete atlasRooms;
|
delete atlasRooms;
|
||||||
#if !defined(_GAPI_SW) && !defined(_GAPI_GU)
|
#ifndef FFP
|
||||||
delete atlasObjects;
|
delete atlasObjects;
|
||||||
delete atlasSprites;
|
delete atlasSprites;
|
||||||
delete atlasGlyphs;
|
delete atlasGlyphs;
|
||||||
@@ -1710,7 +1715,7 @@ struct Level : IGame {
|
|||||||
short4 uv = t.getMinMax();
|
short4 uv = t.getMinMax();
|
||||||
uv.z++;
|
uv.z++;
|
||||||
uv.w++;
|
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++) {
|
for (int i = 0; i < level.spriteTexturesCount; i++) {
|
||||||
@@ -1718,7 +1723,7 @@ struct Level : IGame {
|
|||||||
short4 uv = t.getMinMax();
|
short4 uv = t.getMinMax();
|
||||||
uv.z++;
|
uv.z++;
|
||||||
uv.w++;
|
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++) {
|
for (int i = 0; i < level.tilesCount; i++) {
|
||||||
@@ -3136,6 +3141,7 @@ struct Level : IGame {
|
|||||||
ambientCache->processQueue();
|
ambientCache->processQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FFP
|
||||||
if (shadow[0] && players[0]) {
|
if (shadow[0] && players[0]) {
|
||||||
player = players[0];
|
player = players[0];
|
||||||
renderShadows(player->getRoomIndex(), shadow[0]);
|
renderShadows(player->getRoomIndex(), shadow[0]);
|
||||||
@@ -3149,6 +3155,7 @@ struct Level : IGame {
|
|||||||
renderShadows(player->getRoomIndex(), shadow[1]);
|
renderShadows(player->getRoomIndex(), shadow[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (copyBg) {
|
if (copyBg) {
|
||||||
inventory->prepareBackground();
|
inventory->prepareBackground();
|
||||||
|
Reference in New Issue
Block a user