mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:20:05 +00:00 
			
		
		
		
	Use GLEW instead of QOpenGLFunctions
This commit is contained in:
		
							parent
							
								
									4bd749d976
								
							
						
					
					
						commit
						331b2d855f
					
				
					 33 changed files with 788 additions and 959 deletions
				
			
		|  | @ -144,7 +144,7 @@ public: | |||
| }; | ||||
| 
 | ||||
| GeoIcons::GeoIcons(const std::shared_ptr<GlContext>& context) : | ||||
|     DrawItem(context->gl()), p(std::make_unique<Impl>(context)) | ||||
|     DrawItem(), p(std::make_unique<Impl>(context)) | ||||
| { | ||||
| } | ||||
| GeoIcons::~GeoIcons() = default; | ||||
|  | @ -165,8 +165,6 @@ void GeoIcons::set_thresholded(bool thresholded) | |||
| 
 | ||||
| void GeoIcons::Initialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|    p->shaderProgram_ = p->context_->GetShaderProgram( | ||||
|       {{GL_VERTEX_SHADER, ":/gl/geo_texture2d.vert"}, | ||||
|        {GL_GEOMETRY_SHADER, ":/gl/threshold.geom"}, | ||||
|  | @ -181,87 +179,87 @@ void GeoIcons::Initialize() | |||
|    p->uSelectedTimeLocation_ = | ||||
|       p->shaderProgram_->GetUniformLocation("uSelectedTime"); | ||||
| 
 | ||||
|    gl.glGenVertexArrays(1, &p->vao_); | ||||
|    gl.glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); | ||||
|    glGenVertexArrays(1, &p->vao_); | ||||
|    glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); | ||||
| 
 | ||||
|    gl.glBindVertexArray(p->vao_); | ||||
|    gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[0]); | ||||
|    gl.glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW); | ||||
|    glBindVertexArray(p->vao_); | ||||
|    glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[0]); | ||||
|    glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|    // aLatLong
 | ||||
|    gl.glVertexAttribPointer(0, | ||||
|                             2, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             kPointsPerVertex * sizeof(float), | ||||
|                             static_cast<void*>(0)); | ||||
|    gl.glEnableVertexAttribArray(0); | ||||
|    glVertexAttribPointer(0, | ||||
|                          2, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          kPointsPerVertex * sizeof(float), | ||||
|                          static_cast<void*>(0)); | ||||
|    glEnableVertexAttribArray(0); | ||||
| 
 | ||||
|    // aXYOffset
 | ||||
|    gl.glVertexAttribPointer(1, | ||||
|                             2, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             kPointsPerVertex * sizeof(float), | ||||
|                             reinterpret_cast<void*>(2 * sizeof(float))); | ||||
|    gl.glEnableVertexAttribArray(1); | ||||
|    glVertexAttribPointer(1, | ||||
|                          2, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          kPointsPerVertex * sizeof(float), | ||||
|                          reinterpret_cast<void*>(2 * sizeof(float))); | ||||
|    glEnableVertexAttribArray(1); | ||||
| 
 | ||||
|    // aModulate
 | ||||
|    gl.glVertexAttribPointer(3, | ||||
|                             4, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             kPointsPerVertex * sizeof(float), | ||||
|                             reinterpret_cast<void*>(4 * sizeof(float))); | ||||
|    gl.glEnableVertexAttribArray(3); | ||||
|    glVertexAttribPointer(3, | ||||
|                          4, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          kPointsPerVertex * sizeof(float), | ||||
|                          reinterpret_cast<void*>(4 * sizeof(float))); | ||||
|    glEnableVertexAttribArray(3); | ||||
| 
 | ||||
|    // aAngle
 | ||||
|    gl.glVertexAttribPointer(4, | ||||
|                             1, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             kPointsPerVertex * sizeof(float), | ||||
|                             reinterpret_cast<void*>(8 * sizeof(float))); | ||||
|    gl.glEnableVertexAttribArray(4); | ||||
|    glVertexAttribPointer(4, | ||||
|                          1, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          kPointsPerVertex * sizeof(float), | ||||
|                          reinterpret_cast<void*>(8 * sizeof(float))); | ||||
|    glEnableVertexAttribArray(4); | ||||
| 
 | ||||
|    gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[1]); | ||||
|    gl.glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW); | ||||
|    glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[1]); | ||||
|    glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|    // aTexCoord
 | ||||
|    gl.glVertexAttribPointer(2, | ||||
|                             3, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             kPointsPerTexCoord * sizeof(float), | ||||
|                             static_cast<void*>(0)); | ||||
|    gl.glEnableVertexAttribArray(2); | ||||
|    glVertexAttribPointer(2, | ||||
|                          3, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          kPointsPerTexCoord * sizeof(float), | ||||
|                          static_cast<void*>(0)); | ||||
|    glEnableVertexAttribArray(2); | ||||
| 
 | ||||
|    gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[2]); | ||||
|    gl.glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW); | ||||
|    glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[2]); | ||||
|    glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|    // aThreshold
 | ||||
|    gl.glVertexAttribIPointer(5, //
 | ||||
|                              1, | ||||
|                              GL_INT, | ||||
|                              0, | ||||
|                              static_cast<void*>(0)); | ||||
|    gl.glEnableVertexAttribArray(5); | ||||
|    glVertexAttribIPointer(5, //
 | ||||
|                           1, | ||||
|                           GL_INT, | ||||
|                           0, | ||||
|                           static_cast<void*>(0)); | ||||
|    glEnableVertexAttribArray(5); | ||||
| 
 | ||||
|    // aTimeRange
 | ||||
|    gl.glVertexAttribIPointer(6, //
 | ||||
|                              2, | ||||
|                              GL_INT, | ||||
|                              kIntegersPerVertex_ * sizeof(GLint), | ||||
|                              reinterpret_cast<void*>(1 * sizeof(GLint))); | ||||
|    gl.glEnableVertexAttribArray(6); | ||||
|    glVertexAttribIPointer(6, //
 | ||||
|                           2, | ||||
|                           GL_INT, | ||||
|                           kIntegersPerVertex_ * sizeof(GLint), | ||||
|                           reinterpret_cast<void*>(1 * sizeof(GLint))); | ||||
|    glEnableVertexAttribArray(6); | ||||
| 
 | ||||
|    // aDisplayed
 | ||||
|    gl.glVertexAttribIPointer(7, | ||||
|                              1, | ||||
|                              GL_INT, | ||||
|                              kIntegersPerVertex_ * sizeof(GLint), | ||||
|                              reinterpret_cast<void*>(3 * sizeof(GLint))); | ||||
|    gl.glEnableVertexAttribArray(7); | ||||
|    glVertexAttribIPointer(7, | ||||
|                           1, | ||||
|                           GL_INT, | ||||
|                           kIntegersPerVertex_ * sizeof(GLint), | ||||
|                           reinterpret_cast<void*>(3 * sizeof(GLint))); | ||||
|    glEnableVertexAttribArray(7); | ||||
| 
 | ||||
|    p->dirty_ = true; | ||||
| } | ||||
|  | @ -283,9 +281,7 @@ void GeoIcons::Render(const QMapLibre::CustomLayerRenderParameters& params, | |||
| 
 | ||||
|    if (!p->currentIconList_.empty()) | ||||
|    { | ||||
|       gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|       gl.glBindVertexArray(p->vao_); | ||||
|       glBindVertexArray(p->vao_); | ||||
| 
 | ||||
|       p->Update(textureAtlasChanged); | ||||
|       p->shaderProgram_->Use(); | ||||
|  | @ -298,12 +294,12 @@ void GeoIcons::Render(const QMapLibre::CustomLayerRenderParameters& params, | |||
|          // If thresholding is enabled, set the map distance
 | ||||
|          units::length::nautical_miles<float> mapDistance = | ||||
|             util::maplibre::GetMapDistance(params); | ||||
|          gl.glUniform1f(p->uMapDistanceLocation_, mapDistance.value()); | ||||
|          glUniform1f(p->uMapDistanceLocation_, mapDistance.value()); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          // If thresholding is disabled, set the map distance to 0
 | ||||
|          gl.glUniform1f(p->uMapDistanceLocation_, 0.0f); | ||||
|          glUniform1f(p->uMapDistanceLocation_, 0.0f); | ||||
|       } | ||||
| 
 | ||||
|       // Selected time
 | ||||
|  | @ -311,27 +307,25 @@ void GeoIcons::Render(const QMapLibre::CustomLayerRenderParameters& params, | |||
|          (p->selectedTime_ == std::chrono::system_clock::time_point {}) ? | ||||
|             std::chrono::system_clock::now() : | ||||
|             p->selectedTime_; | ||||
|       gl.glUniform1i( | ||||
|       glUniform1i( | ||||
|          p->uSelectedTimeLocation_, | ||||
|          static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>( | ||||
|                                selectedTime.time_since_epoch()) | ||||
|                                .count())); | ||||
| 
 | ||||
|       // Interpolate texture coordinates
 | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
|       glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
| 
 | ||||
|       // Draw icons
 | ||||
|       gl.glDrawArrays(GL_TRIANGLES, 0, p->numVertices_); | ||||
|       glDrawArrays(GL_TRIANGLES, 0, p->numVertices_); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void GeoIcons::Deinitialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|    gl.glDeleteVertexArrays(1, &p->vao_); | ||||
|    gl.glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); | ||||
|    glDeleteVertexArrays(1, &p->vao_); | ||||
|    glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); | ||||
| 
 | ||||
|    std::unique_lock lock {p->iconMutex_}; | ||||
| 
 | ||||
|  | @ -847,8 +841,6 @@ void GeoIcons::Impl::UpdateModifiedIconBuffers() | |||
| 
 | ||||
| void GeoIcons::Impl::Update(bool textureAtlasChanged) | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = context_->gl(); | ||||
| 
 | ||||
|    UpdateModifiedIconBuffers(); | ||||
| 
 | ||||
|    // If the texture atlas has changed
 | ||||
|  | @ -864,11 +856,11 @@ void GeoIcons::Impl::Update(bool textureAtlasChanged) | |||
|       UpdateTextureBuffer(); | ||||
| 
 | ||||
|       // Buffer texture data
 | ||||
|       gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]); | ||||
|       gl.glBufferData(GL_ARRAY_BUFFER, | ||||
|                       sizeof(float) * textureBuffer_.size(), | ||||
|                       textureBuffer_.data(), | ||||
|                       GL_DYNAMIC_DRAW); | ||||
|       glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]); | ||||
|       glBufferData(GL_ARRAY_BUFFER, | ||||
|                    sizeof(float) * textureBuffer_.size(), | ||||
|                    textureBuffer_.data(), | ||||
|                    GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|       lastTextureAtlasChanged_ = false; | ||||
|    } | ||||
|  | @ -877,18 +869,18 @@ void GeoIcons::Impl::Update(bool textureAtlasChanged) | |||
|    if (dirty_) | ||||
|    { | ||||
|       // Buffer vertex data
 | ||||
|       gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]); | ||||
|       gl.glBufferData(GL_ARRAY_BUFFER, | ||||
|                       sizeof(float) * currentIconBuffer_.size(), | ||||
|                       currentIconBuffer_.data(), | ||||
|                       GL_DYNAMIC_DRAW); | ||||
|       glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]); | ||||
|       glBufferData(GL_ARRAY_BUFFER, | ||||
|                    sizeof(float) * currentIconBuffer_.size(), | ||||
|                    currentIconBuffer_.data(), | ||||
|                    GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|       // Buffer threshold data
 | ||||
|       gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]); | ||||
|       gl.glBufferData(GL_ARRAY_BUFFER, | ||||
|                       sizeof(GLint) * currentIntegerBuffer_.size(), | ||||
|                       currentIntegerBuffer_.data(), | ||||
|                       GL_DYNAMIC_DRAW); | ||||
|       glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]); | ||||
|       glBufferData(GL_ARRAY_BUFFER, | ||||
|                    sizeof(GLint) * currentIntegerBuffer_.size(), | ||||
|                    currentIntegerBuffer_.data(), | ||||
|                    GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|       numVertices_ = | ||||
|          static_cast<GLsizei>(currentIconBuffer_.size() / kPointsPerVertex); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat