This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] merge gl::ObjectStore into gl::Context
- Loading branch information
1 parent
ce42d22
commit 44c7e9d
Showing
76 changed files
with
555 additions
and
580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <mbgl/gl/context.hpp> | ||
|
||
namespace mbgl { | ||
namespace gl { | ||
|
||
Context::~Context() { | ||
reset(); | ||
} | ||
|
||
void Context::reset() { | ||
std::copy(pooledTextures.begin(), pooledTextures.end(), std::back_inserter(abandonedTextures)); | ||
pooledTextures.resize(0); | ||
performCleanup(); | ||
} | ||
|
||
namespace { | ||
|
||
template <typename Fn> | ||
void applyStateFunction(Context& context, Fn&& fn) { | ||
fn(context.stencilFunc); | ||
fn(context.stencilMask); | ||
fn(context.stencilTest); | ||
fn(context.stencilOp); | ||
fn(context.depthRange); | ||
fn(context.depthMask); | ||
fn(context.depthTest); | ||
fn(context.depthFunc); | ||
fn(context.blend); | ||
fn(context.blendFunc); | ||
fn(context.blendColor); | ||
fn(context.colorMask); | ||
fn(context.clearDepth); | ||
fn(context.clearColor); | ||
fn(context.clearStencil); | ||
fn(context.program); | ||
fn(context.lineWidth); | ||
fn(context.activeTexture); | ||
fn(context.bindFramebuffer); | ||
fn(context.viewport); | ||
#ifndef GL_ES_VERSION_2_0 | ||
fn(context.pixelZoom); | ||
fn(context.rasterPos); | ||
#endif // GL_ES_VERSION_2_0 | ||
for (auto& tex : context.texture) { | ||
fn(tex); | ||
} | ||
fn(context.vertexBuffer); | ||
fn(context.elementBuffer); | ||
fn(context.vertexArrayObject); | ||
} | ||
|
||
} // namespace | ||
|
||
void Context::resetState() { | ||
applyStateFunction(*this, [](auto& state) { state.reset(); }); | ||
} | ||
|
||
void Context::setDirtyState() { | ||
applyStateFunction(*this, [](auto& state) { state.setDirty(); }); | ||
} | ||
|
||
void Context::performCleanup() { | ||
for (GLuint id : abandonedPrograms) { | ||
MBGL_CHECK_ERROR(glDeleteProgram(id)); | ||
} | ||
abandonedPrograms.clear(); | ||
|
||
for (GLuint id : abandonedShaders) { | ||
MBGL_CHECK_ERROR(glDeleteShader(id)); | ||
} | ||
abandonedShaders.clear(); | ||
|
||
if (!abandonedBuffers.empty()) { | ||
MBGL_CHECK_ERROR(glDeleteBuffers(int(abandonedBuffers.size()), abandonedBuffers.data())); | ||
abandonedBuffers.clear(); | ||
} | ||
|
||
if (!abandonedTextures.empty()) { | ||
MBGL_CHECK_ERROR(glDeleteTextures(int(abandonedTextures.size()), abandonedTextures.data())); | ||
abandonedTextures.clear(); | ||
} | ||
|
||
if (!abandonedVAOs.empty()) { | ||
MBGL_CHECK_ERROR(gl::DeleteVertexArrays(int(abandonedVAOs.size()), abandonedVAOs.data())); | ||
abandonedVAOs.clear(); | ||
} | ||
|
||
if (!abandonedFBOs.empty()) { | ||
MBGL_CHECK_ERROR(glDeleteFramebuffers(int(abandonedFBOs.size()), abandonedFBOs.data())); | ||
abandonedFBOs.clear(); | ||
} | ||
} | ||
|
||
} // namespace gl | ||
} // namespace mbgl |
Oops, something went wrong.