mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 23:50:05 +00:00 
			
		
		
		
	Adding custom offset and scaling for color table to fragment shader
This commit is contained in:
		
							parent
							
								
									3e92847901
								
							
						
					
					
						commit
						aa48d8610a
					
				
					 6 changed files with 60 additions and 14 deletions
				
			
		|  | @ -53,6 +53,8 @@ public: | |||
|    gl::ShaderProgram     shaderProgram_; | ||||
|    GLint                 uMVPMatrixLocation_; | ||||
|    GLint                 uMapScreenCoordLocation_; | ||||
|    GLint                 uDataMomentOffsetLocation_; | ||||
|    GLint                 uDataMomentScaleLocation_; | ||||
|    std::array<GLuint, 2> vbo_; | ||||
|    GLuint                vao_; | ||||
|    GLuint                texture_; | ||||
|  | @ -95,6 +97,24 @@ void RadarProductLayer::initialize() | |||
|          << logPrefix_ << "Could not find uMapScreenCoord"; | ||||
|    } | ||||
| 
 | ||||
|    p->uDataMomentOffsetLocation_ = | ||||
|       gl.glGetUniformLocation(p->shaderProgram_.id(), "uDataMomentOffset"); | ||||
|    if (p->uDataMomentOffsetLocation_ == -1) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(warning) | ||||
|          << logPrefix_ << "Could not find uDataMomentOffset"; | ||||
|    } | ||||
| 
 | ||||
|    p->uDataMomentScaleLocation_ = | ||||
|       gl.glGetUniformLocation(p->shaderProgram_.id(), "uDataMomentScale"); | ||||
|    if (p->uDataMomentScaleLocation_ == -1) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(warning) | ||||
|          << logPrefix_ << "Could not find uDataMomentScale"; | ||||
|    } | ||||
| 
 | ||||
|    p->shaderProgram_.Use(); | ||||
| 
 | ||||
|    // Generate a vertex array object
 | ||||
|    gl.glGenVertexArrays(1, &p->vao_); | ||||
| 
 | ||||
|  | @ -187,6 +207,8 @@ void RadarProductLayer::render( | |||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
| 
 | ||||
|    p->shaderProgram_.Use(); | ||||
| 
 | ||||
|    if (p->colorTableNeedsUpdate_) | ||||
|    { | ||||
|       UpdateColorTable(); | ||||
|  | @ -197,8 +219,6 @@ void RadarProductLayer::render( | |||
|       UpdateSweep(); | ||||
|    } | ||||
| 
 | ||||
|    p->shaderProgram_.Use(); | ||||
| 
 | ||||
|    const float scale = std::pow(2.0, params.zoom) * 2.0f * | ||||
|                        mbgl::util::tileSize / mbgl::util::DEGREES_MAX; | ||||
|    const float xScale = scale / params.width; | ||||
|  | @ -252,12 +272,18 @@ void RadarProductLayer::UpdateColorTable() | |||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "UpdateColorTable()"; | ||||
| 
 | ||||
|    uint16_t rangeMin; | ||||
|    uint16_t rangeMax; | ||||
|    float    scale; | ||||
| 
 | ||||
|    p->colorTableNeedsUpdate_ = false; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
| 
 | ||||
|    const std::vector<boost::gil::rgba8_pixel_t>& colorTable = | ||||
|       p->radarProductView_->color_table(); | ||||
|       p->radarProductView_->color_table(rangeMin, rangeMax); | ||||
| 
 | ||||
|    scale = rangeMax - rangeMin; | ||||
| 
 | ||||
|    gl.glActiveTexture(GL_TEXTURE0); | ||||
|    gl.glBindTexture(GL_TEXTURE_1D, p->texture_); | ||||
|  | @ -270,6 +296,9 @@ void RadarProductLayer::UpdateColorTable() | |||
|                    GL_UNSIGNED_BYTE, | ||||
|                    colorTable.data()); | ||||
|    gl.glGenerateMipmap(GL_TEXTURE_1D); | ||||
| 
 | ||||
|    gl.glUniform1ui(p->uDataMomentOffsetLocation_, rangeMin); | ||||
|    gl.glUniform1f(p->uDataMomentScaleLocation_, rangeMax - rangeMin); | ||||
| } | ||||
| 
 | ||||
| void RadarProductLayer::UpdateColorTableNextFrame() | ||||
|  |  | |||
|  | @ -47,7 +47,9 @@ public: | |||
|        longitude_ {}, | ||||
|        sweepTime_ {}, | ||||
|        colorTable_ {}, | ||||
|        colorTableLut_ {} | ||||
|        colorTableLut_ {}, | ||||
|        colorTableMin_ {2}, | ||||
|        colorTableMax_ {254} | ||||
|    { | ||||
|       auto it = blockTypes_.find(product); | ||||
| 
 | ||||
|  | @ -81,6 +83,8 @@ public: | |||
| 
 | ||||
|    std::shared_ptr<common::ColorTable>    colorTable_; | ||||
|    std::vector<boost::gil::rgba8_pixel_t> colorTableLut_; | ||||
|    uint16_t                               colorTableMin_; | ||||
|    uint16_t                               colorTableMax_; | ||||
| 
 | ||||
|    std::shared_ptr<common::ColorTable> savedColorTable_; | ||||
|    float                               savedScale_; | ||||
|  | @ -100,14 +104,16 @@ Level2ProductView::Level2ProductView( | |||
| Level2ProductView::~Level2ProductView() = default; | ||||
| 
 | ||||
| const std::vector<boost::gil::rgba8_pixel_t>& | ||||
| Level2ProductView::color_table() const | ||||
| Level2ProductView::color_table(uint16_t& minValue, uint16_t& maxValue) const | ||||
| { | ||||
|    if (p->colorTableLut_.size() == 0) | ||||
|    { | ||||
|       return RadarProductView::color_table(); | ||||
|       return RadarProductView::color_table(minValue, maxValue); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       minValue = p->colorTableMin_; | ||||
|       maxValue = p->colorTableMax_; | ||||
|       return p->colorTableLut_; | ||||
|    } | ||||
| } | ||||
|  | @ -216,6 +222,9 @@ void Level2ProductView::UpdateColorTable() | |||
|                     lut[i - *dataRange.begin()] = p->colorTable_->Color(f); | ||||
|                  }); | ||||
| 
 | ||||
|    p->colorTableMin_ = rangeMin; | ||||
|    p->colorTableMax_ = rangeMax; | ||||
| 
 | ||||
|    p->savedColorTable_ = p->colorTable_; | ||||
|    p->savedOffset_     = offset; | ||||
|    p->savedScale_      = scale; | ||||
|  |  | |||
|  | @ -28,9 +28,10 @@ public: | |||
|       std::shared_ptr<manager::RadarProductManager> radarProductManager); | ||||
|    ~Level2ProductView(); | ||||
| 
 | ||||
|    const std::vector<boost::gil::rgba8_pixel_t>& color_table() const override; | ||||
|    std::chrono::system_clock::time_point         sweep_time() const override; | ||||
|    const std::vector<float>&                     vertices() const override; | ||||
|    const std::vector<boost::gil::rgba8_pixel_t>& | ||||
|    color_table(uint16_t& minValue, uint16_t& maxValue) const override; | ||||
|    std::chrono::system_clock::time_point sweep_time() const override; | ||||
|    const std::vector<float>&             vertices() const override; | ||||
| 
 | ||||
|    void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable) override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -18,6 +18,8 @@ static const std::vector<boost::gil::rgba8_pixel_t> DEFAULT_COLOR_TABLE = { | |||
|    boost::gil::rgba8_pixel_t(0, 128, 0, 255), | ||||
|    boost::gil::rgba8_pixel_t(255, 192, 0, 255), | ||||
|    boost::gil::rgba8_pixel_t(255, 0, 0, 255)}; | ||||
| static const uint16_t DEFAULT_COLOR_TABLE_MIN = 2u; | ||||
| static const uint16_t DEFAULT_COLOR_TABLE_MAX = 255u; | ||||
| 
 | ||||
| class RadarProductViewImpl | ||||
| { | ||||
|  | @ -31,8 +33,10 @@ RadarProductView::RadarProductView() : | |||
| RadarProductView::~RadarProductView() = default; | ||||
| 
 | ||||
| const std::vector<boost::gil::rgba8_pixel_t>& | ||||
| RadarProductView::color_table() const | ||||
| RadarProductView::color_table(uint16_t& minValue, uint16_t& maxValue) const | ||||
| { | ||||
|    minValue = DEFAULT_COLOR_TABLE_MIN; | ||||
|    maxValue = DEFAULT_COLOR_TABLE_MAX; | ||||
|    return DEFAULT_COLOR_TABLE; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,9 +25,10 @@ public: | |||
|    explicit RadarProductView(); | ||||
|    ~RadarProductView(); | ||||
| 
 | ||||
|    virtual const std::vector<boost::gil::rgba8_pixel_t>& color_table() const; | ||||
|    virtual std::chrono::system_clock::time_point         sweep_time() const; | ||||
|    virtual const std::vector<float>&                     vertices() const = 0; | ||||
|    virtual const std::vector<boost::gil::rgba8_pixel_t>& | ||||
|    color_table(uint16_t& minValue, uint16_t& maxValue) const; | ||||
|    virtual std::chrono::system_clock::time_point sweep_time() const; | ||||
|    virtual const std::vector<float>&             vertices() const = 0; | ||||
| 
 | ||||
|    void Initialize(); | ||||
|    virtual void | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat