diff --git a/src/core.h b/src/core.h index 1145593..be7892c 100644 --- a/src/core.h +++ b/src/core.h @@ -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; diff --git a/src/debug.h b/src/debug.h index 9bec144..e7583cf 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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(); diff --git a/src/gapi/gl.h b/src/gapi/gl.h index 5c132db..13bcbb4 100644 --- a/src/gapi/gl.h +++ b/src/gapi/gl.h @@ -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) { diff --git a/src/inventory.h b/src/inventory.h index cce2406..dec19cb 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -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; diff --git a/src/level.h b/src/level.h index 91964de..c4bc395 100644 --- a/src/level.h +++ b/src/level.h @@ -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();