void LineAtlas::upload(gl::Context& context, gl::TextureUnit unit) { if (!texture) { texture = context.createTexture(image, unit); } else if (dirty) { context.updateTexture(*texture, image, unit); } dirty = false; }
void CircleBucket::upload(gl::Context& context) { vertexBuffer = context.createVertexBuffer(std::move(vertices)); indexBuffer = context.createIndexBuffer(std::move(triangles)); for (auto& pair : paintPropertyBinders) { pair.second.upload(context); } uploaded = true; }
static Program createProgram(gl::Context& context, const ProgramParameters& programParameters, const char* name, const char* vertexSource_, const char* fragmentSource_) { #if MBGL_HAS_BINARY_PROGRAMS optional<std::string> cachePath = programParameters.cachePath(name); if (cachePath && context.supportsProgramBinaries()) { const std::string vertexSource = shaders::vertexSource(programParameters, vertexSource_); const std::string fragmentSource = shaders::fragmentSource(programParameters, fragmentSource_); const std::string identifier = shaders::programIdentifier(vertexSource, fragmentSource_); try { if (auto cachedBinaryProgram = util::readFile(*cachePath)) { const BinaryProgram binaryProgram(std::move(*cachedBinaryProgram)); if (binaryProgram.identifier() == identifier) { return Program { context, binaryProgram }; } else { Log::Warning(Event::OpenGL, "Cached program %s changed. Recompilation required.", name); } } } catch (std::runtime_error& error) { Log::Warning(Event::OpenGL, "Could not load cached program: %s", error.what()); } // Compile the shader Program result{ context, vertexSource, fragmentSource }; try { if (const auto binaryProgram = result.template get<BinaryProgram>(context, identifier)) { util::write_file(*cachePath, binaryProgram->serialize()); Log::Warning(Event::OpenGL, "Caching program in: %s", (*cachePath).c_str()); } } catch (std::runtime_error& error) { Log::Warning(Event::OpenGL, "Failed to cache program: %s", error.what()); } return std::move(result); } #endif (void)name; return Program { context, shaders::vertexSource(programParameters, vertexSource_), shaders::fragmentSource(programParameters, fragmentSource_) }; }
void LineAtlas::bind(gl::Context& context, gl::TextureUnit unit) { bool first = false; if (!texture) { texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); first = true; } else if (context.texture[unit] != *texture) { context.activeTexture = unit; context.texture[unit] = *texture; } if (dirty) { context.activeTexture = unit; if (first) { MBGL_CHECK_ERROR(glTexImage2D( GL_TEXTURE_2D, // GLenum target 0, // GLint level GL_ALPHA, // GLint internalformat width, // GLsizei width height, // GLsizei height 0, // GLint border GL_ALPHA, // GLenum format GL_UNSIGNED_BYTE, // GLenum type data.get() // const GLvoid * data )); } else { MBGL_CHECK_ERROR(glTexSubImage2D( GL_TEXTURE_2D, // GLenum target 0, // GLint level 0, // GLint xoffset 0, // GLint yoffset width, // GLsizei width height, // GLsizei height GL_ALPHA, // GLenum format GL_UNSIGNED_BYTE, // GLenum type data.get() // const GLvoid *pixels )); } dirty = false; } }
void Raster::upload(gl::Context& context, uint32_t unit) { if (!images.empty() && !texture) { texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; updateFilter(); #ifndef GL_ES_VERSION_2_0 MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, images.size())); #endif MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); GLint level = 0; for (auto& img : images) { MBGL_CHECK_ERROR(glTexImage2D( GL_TEXTURE_2D, level++, GL_RGBA, static_cast<GLsizei>(img.width), static_cast<GLsizei>(img.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.get())); } size = { { images.front().width, images.front().height } }; images.clear(); images.shrink_to_fit(); } }
bool SharedProgramState::reserveSupported(GL::Context& context) const { context.createSharedUniform("wyM", GL::UNIFORM_MAT4, SHARED_MODEL_MATRIX); context.createSharedUniform("wyV", GL::UNIFORM_MAT4, SHARED_VIEW_MATRIX); context.createSharedUniform("wyP", GL::UNIFORM_MAT4, SHARED_PROJECTION_MATRIX); context.createSharedUniform("wyMV", GL::UNIFORM_MAT4, SHARED_MODELVIEW_MATRIX); context.createSharedUniform("wyVP", GL::UNIFORM_MAT4, SHARED_VIEWPROJECTION_MATRIX); context.createSharedUniform("wyMVP", GL::UNIFORM_MAT4, SHARED_MODELVIEWPROJECTION_MATRIX); context.createSharedUniform("wyInvM", GL::UNIFORM_MAT4, SHARED_INVERSE_MODEL_MATRIX); context.createSharedUniform("wyInvV", GL::UNIFORM_MAT4, SHARED_INVERSE_VIEW_MATRIX); context.createSharedUniform("wyInvP", GL::UNIFORM_MAT4, SHARED_INVERSE_PROJECTION_MATRIX); context.createSharedUniform("wyInvMV", GL::UNIFORM_MAT4, SHARED_INVERSE_MODELVIEW_MATRIX); context.createSharedUniform("wyInvVP", GL::UNIFORM_MAT4, SHARED_INVERSE_VIEWPROJECTION_MATRIX); context.createSharedUniform("wyInvMVP", GL::UNIFORM_MAT4, SHARED_INVERSE_MODELVIEWPROJECTION_MATRIX); context.createSharedUniform("wyCameraNearZ", GL::UNIFORM_FLOAT, SHARED_CAMERA_NEAR_Z); context.createSharedUniform("wyCameraFarZ", GL::UNIFORM_FLOAT, SHARED_CAMERA_FAR_Z); context.createSharedUniform("wyCameraAspectRatio", GL::UNIFORM_FLOAT, SHARED_CAMERA_ASPECT_RATIO); context.createSharedUniform("wyCameraFOV", GL::UNIFORM_FLOAT, SHARED_CAMERA_FOV); context.createSharedUniform("wyCameraPosition", GL::UNIFORM_VEC3, SHARED_CAMERA_POSITION); context.createSharedUniform("wyViewportWidth", GL::UNIFORM_FLOAT, SHARED_VIEWPORT_WIDTH); context.createSharedUniform("wyViewportHeight", GL::UNIFORM_FLOAT, SHARED_VIEWPORT_HEIGHT); context.createSharedUniform("wyTime", GL::UNIFORM_FLOAT, SHARED_TIME); return true; }
void RasterBucket::upload(gl::Context& context) { texture = context.createTexture(image); image = {}; uploaded = true; }
void LineAtlas::bind(gl::Context& context, gl::TextureUnit unit) { upload(context, unit); context.bindTexture(*texture, unit, gl::TextureFilter::Linear, gl::TextureMipMap::No, gl::TextureWrap::Repeat, gl::TextureWrap::Clamp); }