mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 07:30:04 +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
				
			
		|  | @ -73,7 +73,7 @@ public: | |||
| }; | ||||
| 
 | ||||
| Rectangle::Rectangle(std::shared_ptr<GlContext> context) : | ||||
|     DrawItem(context->gl()), p(std::make_unique<Impl>(context)) | ||||
|     DrawItem(), p(std::make_unique<Impl>(context)) | ||||
| { | ||||
| } | ||||
| Rectangle::~Rectangle() = default; | ||||
|  | @ -83,41 +83,39 @@ Rectangle& Rectangle::operator=(Rectangle&&) noexcept = default; | |||
| 
 | ||||
| void Rectangle::Initialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|    p->shaderProgram_ = | ||||
|       p->context_->GetShaderProgram(":/gl/color.vert", ":/gl/color.frag"); | ||||
| 
 | ||||
|    p->uMVPMatrixLocation_ = | ||||
|       gl.glGetUniformLocation(p->shaderProgram_->id(), "uMVPMatrix"); | ||||
|       glGetUniformLocation(p->shaderProgram_->id(), "uMVPMatrix"); | ||||
|    if (p->uMVPMatrixLocation_ == -1) | ||||
|    { | ||||
|       logger_->warn("Could not find uMVPMatrix"); | ||||
|    } | ||||
| 
 | ||||
|    gl.glGenVertexArrays(1, &p->vao_); | ||||
|    gl.glGenBuffers(1, &p->vbo_); | ||||
|    glGenVertexArrays(1, &p->vao_); | ||||
|    glGenBuffers(1, &p->vbo_); | ||||
| 
 | ||||
|    gl.glBindVertexArray(p->vao_); | ||||
|    gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_); | ||||
|    gl.glBufferData( | ||||
|    glBindVertexArray(p->vao_); | ||||
|    glBindBuffer(GL_ARRAY_BUFFER, p->vbo_); | ||||
|    glBufferData( | ||||
|       GL_ARRAY_BUFFER, sizeof(float) * BUFFER_LENGTH, nullptr, GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|    gl.glVertexAttribPointer(0, | ||||
|                             3, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             POINTS_PER_VERTEX * sizeof(float), | ||||
|                             static_cast<void*>(0)); | ||||
|    gl.glEnableVertexAttribArray(0); | ||||
|    glVertexAttribPointer(0, | ||||
|                          3, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          POINTS_PER_VERTEX * sizeof(float), | ||||
|                          static_cast<void*>(0)); | ||||
|    glEnableVertexAttribArray(0); | ||||
| 
 | ||||
|    gl.glVertexAttribPointer(1, | ||||
|                             4, | ||||
|                             GL_FLOAT, | ||||
|                             GL_FALSE, | ||||
|                             POINTS_PER_VERTEX * sizeof(float), | ||||
|                             reinterpret_cast<void*>(3 * sizeof(float))); | ||||
|    gl.glEnableVertexAttribArray(1); | ||||
|    glVertexAttribPointer(1, | ||||
|                          4, | ||||
|                          GL_FLOAT, | ||||
|                          GL_FALSE, | ||||
|                          POINTS_PER_VERTEX * sizeof(float), | ||||
|                          reinterpret_cast<void*>(3 * sizeof(float))); | ||||
|    glEnableVertexAttribArray(1); | ||||
| 
 | ||||
|    p->dirty_ = true; | ||||
| } | ||||
|  | @ -126,10 +124,8 @@ void Rectangle::Render(const QMapLibre::CustomLayerRenderParameters& params) | |||
| { | ||||
|    if (p->visible_) | ||||
|    { | ||||
|       gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|       gl.glBindVertexArray(p->vao_); | ||||
|       gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_); | ||||
|       glBindVertexArray(p->vao_); | ||||
|       glBindBuffer(GL_ARRAY_BUFFER, p->vbo_); | ||||
| 
 | ||||
|       p->Update(); | ||||
|       p->shaderProgram_->Use(); | ||||
|  | @ -138,23 +134,21 @@ void Rectangle::Render(const QMapLibre::CustomLayerRenderParameters& params) | |||
|       if (p->fillColor_.has_value()) | ||||
|       { | ||||
|          // Draw fill
 | ||||
|          gl.glDrawArrays(GL_TRIANGLES, 24, 6); | ||||
|          glDrawArrays(GL_TRIANGLES, 24, 6); | ||||
|       } | ||||
| 
 | ||||
|       if (p->borderWidth_ > 0.0f) | ||||
|       { | ||||
|          // Draw border
 | ||||
|          gl.glDrawArrays(GL_TRIANGLES, 0, 24); | ||||
|          glDrawArrays(GL_TRIANGLES, 0, 24); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void Rectangle::Deinitialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|    gl.glDeleteVertexArrays(1, &p->vao_); | ||||
|    gl.glDeleteBuffers(1, &p->vbo_); | ||||
|    glDeleteVertexArrays(1, &p->vao_); | ||||
|    glDeleteBuffers(1, &p->vbo_); | ||||
| } | ||||
| 
 | ||||
| void Rectangle::SetBorder(float width, boost::gil::rgba8_pixel_t color) | ||||
|  | @ -206,8 +200,6 @@ void Rectangle::Impl::Update() | |||
| { | ||||
|    if (dirty_) | ||||
|    { | ||||
|       gl::OpenGLFunctions& gl = context_->gl(); | ||||
| 
 | ||||
|       const float lox = x_; | ||||
|       const float rox = x_ + width_; | ||||
|       const float boy = y_; | ||||
|  | @ -289,10 +281,10 @@ void Rectangle::Impl::Update() | |||
|              {lox, toy, z_, fc0, fc1, fc2, fc3}  // TL
 | ||||
|           }}; | ||||
| 
 | ||||
|       gl.glBufferData(GL_ARRAY_BUFFER, | ||||
|                       sizeof(float) * BUFFER_LENGTH, | ||||
|                       buffer, | ||||
|                       GL_DYNAMIC_DRAW); | ||||
|       glBufferData(GL_ARRAY_BUFFER, | ||||
|                    sizeof(float) * BUFFER_LENGTH, | ||||
|                    buffer, | ||||
|                    GL_DYNAMIC_DRAW); | ||||
| 
 | ||||
|       dirty_ = false; | ||||
|    } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat