mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:40: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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue