void Wave2Fbo:: draw() { // TaskTimer tt(boost::format("Wave2Fbo::draw %s") % b_->getInterval ()); GlException_CHECK_ERROR(); glBindBuffer(GL_ARRAY_BUFFER, vbo_); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, 0); // Draw clear rectangle glColor4f(0.f, 0.f, 0.f, 1.0f); glDrawArrays(GL_TRIANGLE_STRIP, N, 4); // Draw waveform glEnable (GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(.5f, 0.f, 0.f, 0.001f); glDrawArrays(GL_LINE_STRIP, 0, N); glDisable (GL_BLEND); glDisableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); GlException_CHECK_ERROR(); }
void PaintLine:: drawSlice(unsigned N, Heightmap::Position* pts, float r, float g, float b, float a) { if (0==N) return; GlException_CHECK_ERROR(); ToolGlBrush tgb; glColor4f( r, g, b, a); float y = 1; glBegin(GL_TRIANGLE_STRIP); for (unsigned k=0; k<N; k++) { glVertex3f( pts[k].time, 0, pts[k].scale ); glVertex3f( pts[k].time, y, pts[k].scale ); } glEnd(); glLineWidth(1.6f); glBegin(GL_LINE_STRIP); for (unsigned k=0; k<N; k++) { glVertex3f( pts[k].time, y, pts[k].scale ); } glEnd(); glLineWidth(0.5f); GlException_CHECK_ERROR(); }
void Vbo:: init(size_t size, unsigned vbo_type, unsigned access_pattern, void* data) { TIME_VBO TaskTimer tt("Vbo::init(%s, %u, %u, %p)", DataStorageVoid::getMemorySizeText(_sz).c_str(), vbo_type, access_pattern, data); GlException_CHECK_ERROR(); clear(); GlException_CHECK_ERROR(); // create buffer object glGenBuffers(1, &_vbo); glBindBuffer(vbo_type, _vbo); glBufferData(vbo_type, size, data, access_pattern); glBindBuffer(vbo_type, 0); TIME_VBO TaskInfo("Got vbo %u", _vbo) ; GlException_CHECK_ERROR(); _sz = size; _vbo_type = vbo_type; }
void RenderBlock:: endVboRendering() { GlException_CHECK_ERROR(); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glActiveTexture(GL_TEXTURE2); GlTexture::unbindTexture2D(); glActiveTexture(GL_TEXTURE0); glDisableClientState(GL_VERTEX_ARRAY); glUseProgram(0); GlException_CHECK_ERROR(); }
void RenderBlock::Renderer:: renderBlock( pBlock block ) { TIME_RENDERER_BLOCKS GlException_CHECK_ERROR(); Region r = block->getRegion (); glPushMatrixContext mc( GL_MODELVIEW ); TIME_RENDERER_BLOCKS TaskTimer tt(boost::format("renderBlock %s") % r); glTranslatef(r.a.time, 0, r.a.scale); glScalef(r.time(), 1, r.scale()); block->glblock->draw( vbo_size ); TIME_RENDERER_BLOCKS GlException_CHECK_ERROR(); }
// create index buffer for rendering quad mesh void RenderBlock:: createMeshIndexBuffer(int w, int h) { GlException_CHECK_ERROR(); // create index buffer if (_mesh_index_buffer) glDeleteBuffersARB(1, &_mesh_index_buffer); // edge dropout to eliminate visible glitches if (w>2) w+=2; if (h>2) h+=2; _mesh_width = w; _mesh_height = h; _vbo_size = ((w*2)+4)*(h-1); std::vector<BLOCKindexType> indicesdata(_vbo_size); BLOCKindexType *indices = &indicesdata[0]; if (indices) for(int y=0; y<h-1; y++) { *indices++ = y*w; for(int x=0; x<w; x++) { *indices++ = y*w+x; *indices++ = (y+1)*w+x; } // start new strip with degenerate triangle *indices++ = (y+1)*w+(w-1); *indices++ = (y+1)*w; *indices++ = (y+1)*w; } glGenBuffers(1, &_mesh_index_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _mesh_index_buffer); // fill with indices for rendering mesh as triangle strips GlException_SAFE_CALL( glBufferData(GL_ELEMENT_ARRAY_BUFFER, _vbo_size*sizeof(BLOCKindexType), &indicesdata[0], GL_STATIC_DRAW) ); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); GlException_CHECK_ERROR(); }
void GraphicsScene:: drawBackground(QPainter *painter, const QRectF & rectf) { if (!painter->device()) return; double T = last_frame_.elapsedAndRestart(); TIME_PAINTGL TaskTimer tt("GraphicsScene: Draw, last frame %.0f ms / %.0f fps", T*1e3, 1/T); if (update_timer_->isActive ()) TaskInfo("GraphicsScene: Forced redraw"); painter->beginNativePainting(); try { { GlException_CHECK_ERROR(); renderview_->initializeGL(); float dpr = painter->device ()->devicePixelRatio(); renderview_->model->render_settings.dpifactor = dpr; unsigned w = painter->device()->width(); unsigned h = painter->device()->height(); w *= dpr; h *= dpr; renderview_->setStates(); { TIME_PAINTGL_DETAILS TaskTimer tt("glClear"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } QRect rect = QRectF(rectf.topLeft(), QSizeF(rectf.width ()-1, rectf.height ()-1)).toRect (); // QRect rect = tool_selector->parentTool()->geometry(); rect.setWidth (rect.width ()*dpr); rect.setHeight (rect.height ()*dpr); rect.setLeft (rect.left ()*dpr); rect.setTop (rect.top ()*dpr); renderview_->resizeGL( rect, QSize(w,h) ); // This changes state. Shouldn't be a part of rendering. renderview_->model->recompute_extent (); renderview_->paintGL(); renderview_->defaultStates(); glFlush(); } GlException_CHECK_ERROR(); } catch (const std::exception& x) { TaskInfo(""); TaskInfo(boost::format("std::exception\n%s") % boost::diagnostic_information(x)); TaskInfo(""); } catch (...) { TaskInfo(boost::format("Not an std::exception\n%s") % boost::current_exception_diagnostic_information ()); } painter->endNativePainting(); if (0 < draw_more_) draw_more_--; if (0 < draw_more_) update_timer_->start(5); }
void RenderBlock:: beginVboRendering(BlockLayout block_size) { GlException_CHECK_ERROR(); //unsigned meshW = collection->samples_per_block(); //unsigned meshH = collection->scales_per_block(); createColorTexture(24); // These will be linearly interpolated when rendering, so a high resolution texture is not needed glActiveTexture(GL_TEXTURE2); _colorTexture->bindTexture2D(); glActiveTexture(GL_TEXTURE0); glUseProgram(_shader_prog); // TODO check if this takes any time { // Set default uniform variables parameters for the vertex and pixel shader TIME_RENDERER_BLOCKS TaskTimer tt("Setting shader parameters"); GLuint uniVertText0, uniVertText2, uniColorTextureFactor, uniFixedColor, uniClearColor, uniContourPlot, uniFlatness, uniYScale, uniYOffset, uniLogScale, uniScaleTex, uniOffsTex; uniVertText0 = glGetUniformLocation(_shader_prog, "tex"); glUniform1i(uniVertText0, 0); // GL_TEXTURE0 + i // uniVertText1 = glGetUniformLocation(_shader_prog, "tex_nearest"); // glUniform1i(uniVertText1, _mesh_width*_mesh_height>4 ? 0 : 0); uniVertText2 = glGetUniformLocation(_shader_prog, "tex_color"); glUniform1i(uniVertText2, 2); uniFixedColor = glGetUniformLocation(_shader_prog, "fixedColor"); switch (render_settings->color_mode) { case RenderSettings::ColorMode_Grayscale: glUniform4f(uniFixedColor, 0.f, 0.f, 0.f, 0.f); break; case RenderSettings::ColorMode_BlackGrayscale: glUniform4f(uniFixedColor, 1.f, 1.f, 1.f, 0.f); break; default: { tvector<4, float> fixed_color = render_settings->fixed_color; glUniform4f(uniFixedColor, fixed_color[0], fixed_color[1], fixed_color[2], fixed_color[3]); break; } } uniClearColor = glGetUniformLocation(_shader_prog, "clearColor"); tvector<4, float> clear_color = render_settings->clear_color; glUniform4f(uniClearColor, clear_color[0], clear_color[1], clear_color[2], clear_color[3]); uniColorTextureFactor = glGetUniformLocation(_shader_prog, "colorTextureFactor"); switch(render_settings->color_mode) { case RenderSettings::ColorMode_Rainbow: case RenderSettings::ColorMode_GreenRed: case RenderSettings::ColorMode_GreenWhite: case RenderSettings::ColorMode_Green: glUniform1f(uniColorTextureFactor, 1.f); break; default: glUniform1f(uniColorTextureFactor, 0.f); break; } uniContourPlot = glGetUniformLocation(_shader_prog, "contourPlot"); glUniform1f(uniContourPlot, render_settings->draw_contour_plot ? 1.f : 0.f ); uniFlatness = glGetUniformLocation(_shader_prog, "flatness"); float v = render_settings->draw_flat ? 0 : 2*render_settings->last_ysize; // as glScalef in setupGlStates glUniform1f(uniFlatness, v); uniYScale = glGetUniformLocation(_shader_prog, "yScale"); glUniform1f(uniYScale, render_settings->y_scale); uniYOffset = glGetUniformLocation(_shader_prog, "yOffset"); glUniform1f(uniYOffset, render_settings->y_offset); // yOffset specifies 'b' which says which 'v' that should render as 0 // yOffset=-1 => v>1 => fragColor>0 // yOffset=0 => v>L => fragColor>0 // yOffset=1 => v>0 => fragColor>0 float L = 0.00001; float tb = 1.0/L - 1.0; float tc = L/(1.0 - tb); float ta = L - tc; float b = ta * exp(-render_settings->y_offset * log(tb)) + tc; // yScale specifies which intensity 'v=1' should have // v<1 => fragColor < yScale // v=1 => fragColor = yScale // v>1 => fragColor > yScale float x1 = render_settings->y_scale / (log(1.0) - log(b)); float x2 = - log(b) * x1; uniLogScale = glGetUniformLocation(_shader_prog, "logScale"); glUniform3f(uniLogScale, render_settings->log_scale, x1, x2); float w = block_size.texels_per_row (), h = block_size.texels_per_column (); uniScaleTex = glGetUniformLocation(_shader_prog, "scale_tex"); glUniform2f(uniScaleTex, (w-1.f)/w, (h-1.f)/h); uniOffsTex = glGetUniformLocation(_shader_prog, "offset_tex"); glUniform2f(uniOffsTex, .5f/w, .5f/h); } glBindBuffer(GL_ARRAY_BUFFER, *_mesh_position); glVertexPointer(4, GL_FLOAT, 0, 0); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _mesh_index_buffer); GlException_CHECK_ERROR(); }
void GlTexture::bindTexture2D() { GlException_CHECK_ERROR(); glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, textureId); GlException_CHECK_ERROR(); }