mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:30:04 +00:00 
			
		
		
		
	Use GL_TEXTURE_2D_ARRAY to enable multiple texture atlases
This commit is contained in:
		
							parent
							
								
									922e875b07
								
							
						
					
					
						commit
						7198d1c7af
					
				
					 8 changed files with 36 additions and 15 deletions
				
			
		
							
								
								
									
										16
									
								
								scwx-qt/gl/texture2d_array.frag
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								scwx-qt/gl/texture2d_array.frag
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| #version 330 core | ||||
| 
 | ||||
| // Lower the default precision to medium | ||||
| precision mediump float; | ||||
| 
 | ||||
| uniform sampler2DArray uTexture; | ||||
| 
 | ||||
| smooth in vec2 texCoord; | ||||
| smooth in vec4 color; | ||||
| 
 | ||||
| layout (location = 0) out vec4 fragColor; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|    fragColor = texture(uTexture, vec3(texCoord, 0.0)) * color; | ||||
| } | ||||
|  | @ -265,6 +265,7 @@ set(SHADER_FILES gl/color.frag | |||
|                  gl/texture1d.frag | ||||
|                  gl/texture1d.vert | ||||
|                  gl/texture2d.frag | ||||
|                  gl/texture2d_array.frag | ||||
|                  gl/threshold.geom) | ||||
| 
 | ||||
| set(CMAKE_FILES scwx-qt.cmake) | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ | |||
|         <file>gl/texture1d.frag</file> | ||||
|         <file>gl/texture1d.vert</file> | ||||
|         <file>gl/texture2d.frag</file> | ||||
|         <file>gl/texture2d_array.frag</file> | ||||
|         <file>gl/threshold.geom</file> | ||||
|         <file>res/config/radar_sites.json</file> | ||||
|         <file>res/fonts/din1451alt.ttf</file> | ||||
|  |  | |||
|  | @ -92,8 +92,8 @@ void GeoLine::Initialize() | |||
| { | ||||
|    gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
| 
 | ||||
|    p->shaderProgram_ = p->context_->GetShaderProgram(":/gl/geo_line.vert", | ||||
|                                                      ":/gl/texture2d.frag"); | ||||
|    p->shaderProgram_ = p->context_->GetShaderProgram( | ||||
|       ":/gl/geo_line.vert", ":/gl/texture2d_array.frag"); | ||||
| 
 | ||||
|    p->uMVPMatrixLocation_ = | ||||
|       gl.glGetUniformLocation(p->shaderProgram_->id(), "uMVPMatrix"); | ||||
|  |  | |||
|  | @ -151,7 +151,7 @@ void PlacefileIcons::Initialize() | |||
|    p->shaderProgram_ = p->context_->GetShaderProgram( | ||||
|       {{GL_VERTEX_SHADER, ":/gl/geo_texture2d.vert"}, | ||||
|        {GL_GEOMETRY_SHADER, ":/gl/threshold.geom"}, | ||||
|        {GL_FRAGMENT_SHADER, ":/gl/texture2d.frag"}}); | ||||
|        {GL_FRAGMENT_SHADER, ":/gl/texture2d_array.frag"}}); | ||||
| 
 | ||||
|    p->uMVPMatrixLocation_ = p->shaderProgram_->GetUniformLocation("uMVPMatrix"); | ||||
|    p->uMapMatrixLocation_ = p->shaderProgram_->GetUniformLocation("uMapMatrix"); | ||||
|  | @ -261,8 +261,8 @@ void PlacefileIcons::Render( | |||
|       } | ||||
| 
 | ||||
|       // Interpolate texture coordinates
 | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
| 
 | ||||
|       // Draw icons
 | ||||
|       gl.glDrawArrays(GL_TRIANGLES, 0, p->numVertices_); | ||||
|  |  | |||
|  | @ -129,7 +129,7 @@ void PlacefileImages::Initialize() | |||
|    p->shaderProgram_ = p->context_->GetShaderProgram( | ||||
|       {{GL_VERTEX_SHADER, ":/gl/geo_texture2d.vert"}, | ||||
|        {GL_GEOMETRY_SHADER, ":/gl/threshold.geom"}, | ||||
|        {GL_FRAGMENT_SHADER, ":/gl/texture2d.frag"}}); | ||||
|        {GL_FRAGMENT_SHADER, ":/gl/texture2d_array.frag"}}); | ||||
| 
 | ||||
|    p->uMVPMatrixLocation_ = p->shaderProgram_->GetUniformLocation("uMVPMatrix"); | ||||
|    p->uMapMatrixLocation_ = p->shaderProgram_->GetUniformLocation("uMapMatrix"); | ||||
|  | @ -230,8 +230,8 @@ void PlacefileImages::Render( | |||
|       } | ||||
| 
 | ||||
|       // Interpolate texture coordinates
 | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
| 
 | ||||
|       // Draw images
 | ||||
|       gl.glDrawArrays(GL_TRIANGLES, 0, p->numVertices_); | ||||
|  |  | |||
|  | @ -56,7 +56,7 @@ void DrawLayer::Render(const QMapLibreGL::CustomLayerRenderParameters& params) | |||
|       newTextureAtlasBuildCount != p->textureAtlasBuildCount_; | ||||
| 
 | ||||
|    gl.glActiveTexture(GL_TEXTURE0); | ||||
|    gl.glBindTexture(GL_TEXTURE_2D, p->textureAtlas_); | ||||
|    gl.glBindTexture(GL_TEXTURE_2D_ARRAY, p->textureAtlas_); | ||||
| 
 | ||||
|    for (auto& item : p->drawList_) | ||||
|    { | ||||
|  |  | |||
|  | @ -296,18 +296,21 @@ GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) | |||
|       lock.unlock(); | ||||
| 
 | ||||
|       gl.glGenTextures(1, &texture); | ||||
|       gl.glBindTexture(GL_TEXTURE_2D, texture); | ||||
|       gl.glBindTexture(GL_TEXTURE_2D_ARRAY, texture); | ||||
| 
 | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri( | ||||
|          GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||||
|       gl.glTexParameteri( | ||||
|          GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|       gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
| 
 | ||||
|       gl.glTexImage2D(GL_TEXTURE_2D, | ||||
|       gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, | ||||
|                       0, | ||||
|                       GL_RGBA, | ||||
|                       view.width(), | ||||
|                       view.height(), | ||||
|                       1u, | ||||
|                       0, | ||||
|                       GL_RGBA, | ||||
|                       GL_UNSIGNED_BYTE, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat