Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3506f49e952d
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d83fe591bbd1
Choose a head ref
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Feb 22, 2020

  1. Cleaned up a bit of dead code from old rendering engine. Fixed #41 an…

    …d some other resource management issues when unrealizing/re-realizing waveform areas in new groups.
    azonenberg committed Feb 22, 2020
    Copy the full SHA
    d83fe59 View commit details
66 changes: 38 additions & 28 deletions glscopeclient/WaveformArea.cpp
Original file line number Diff line number Diff line change
@@ -80,13 +80,15 @@ void WaveformArea::SharedCtorInit()
m_overlayTime = 0;
m_prepareTime = 0;
m_downloadTime = 0;
m_indexTime = 0;
m_updatingContextMenu = false;
m_selectedChannel = m_channel;
m_dragState = DRAG_NONE;
m_padding = 2;
m_lastFrameStart = -1;
m_persistenceClear = true;
m_geometryDirty = true;
m_firstFrame = false;

set_has_alpha();

@@ -432,6 +434,10 @@ void WaveformArea::on_realize()
Gtk::GLArea::on_realize();
make_current();

//We're about to draw the first frame after realization.
//This means we need to save some configuration (like the current FBO) that GTK doesn't tell us directly
m_firstFrame = true;

//Set stuff up for each rendering pass
InitializeWaveformPass();
InitializeColormapPass();
@@ -442,50 +448,54 @@ void WaveformArea::on_realize()

void WaveformArea::on_unrealize()
{
m_waveformProgram.Destroy();
make_current();

CleanupGLHandles();

Gtk::GLArea::on_unrealize();
}

void WaveformArea::CleanupGLHandles()
{
//Clean up old shaders
m_waveformComputeProgram.Destroy();
m_colormapProgram.Destroy();
m_colormapVAO.Destroy();
m_colormapVBO.Destroy();
m_persistProgram.Destroy();
m_persistVAO.Destroy();
m_persistVBO.Destroy();
m_eyeProgram.Destroy();
m_cairoProgram.Destroy();

//Clean up old VAOs
m_colormapVAO.Destroy();
m_persistVAO.Destroy();
m_cairoVAO.Destroy();
m_eyeVAO.Destroy();

//Clean up old VBOs
m_colormapVBO.Destroy();
m_persistVBO.Destroy();
m_cairoVBO.Destroy();
m_windowFramebuffer.Detach();
m_eyeVBO.Destroy();

//Clean up old textures
m_waveformTextureResolved.Destroy();
m_cairoTexture.Destroy();
m_cairoTextureOver.Destroy();
m_eyeProgram.Destroy();
m_eyeVAO.Destroy();
m_eyeVBO.Destroy();
for(auto& e : m_eyeColorRamp)
e.Destroy();

Gtk::GLArea::on_unrealize();
//Clean up old SSBOs
m_waveformStorageBuffer.Destroy();
m_waveformConfigBuffer.Destroy();
m_waveformIndexBuffer.Destroy();

//Detach the FBO so we don't destroy it!!
//GTK manages this, and it might be used by more than one waveform area within the application.
m_windowFramebuffer.Detach();
}

void WaveformArea::InitializeWaveformPass()
{
//ProfileBlock pb("Load waveform shaders");
VertexShader dvs;
FragmentShader dfs;
if(!dvs.Load("shaders/waveform-vertex.glsl") || !dfs.Load("shaders/waveform-fragment.glsl"))
{
LogError("failed to load default shaders, aborting");
exit(1);
}

//Create the programs
m_waveformProgram.Add(dvs);
m_waveformProgram.Add(dfs);
if(!m_waveformProgram.Link())
{
LogError("failed to link shader program, aborting");
exit(1);
}

//Create the shader stuff
ComputeShader wc;
if(!wc.Load("shaders/waveform-compute.glsl"))
{
5 changes: 2 additions & 3 deletions glscopeclient/WaveformArea.h
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@ class WaveformArea : public Gtk::GLArea

virtual void on_realize();
virtual void on_unrealize();
void CleanupGLHandles();
virtual void on_resize (int width, int height);
virtual bool on_render(const Glib::RefPtr<Gdk::GLContext>& context);
virtual bool on_button_press_event(GdkEventButton* event);
@@ -222,15 +223,12 @@ class WaveformArea : public Gtk::GLArea
bool m_persistence;
bool m_persistenceClear;

//GL stuff (TODO organize)
Program m_waveformProgram;
Framebuffer m_windowFramebuffer;

//Trace rendering
bool PrepareGeometry();
void RenderTrace();
void InitializeWaveformPass();
glm::mat4 m_projection;
size_t m_waveformLength;
std::vector<float> m_traceBuffer;
float m_xoff;
@@ -354,6 +352,7 @@ class WaveformArea : public Gtk::GLArea
} m_dragState;

bool m_geometryDirty;
bool m_firstFrame;
};

#endif
16 changes: 1 addition & 15 deletions glscopeclient/WaveformArea_events.cpp
Original file line number Diff line number Diff line change
@@ -66,24 +66,10 @@ void WaveformArea::on_resize(int width, int height)
//Reset camera configuration
glViewport(0, 0, width, height);

//transformation matrix from screen to pixel coordinates
m_projection = translate(
scale(mat4(1.0f), vec3(2.0f / width, 2.0f / height, 1)), //scale to window size
vec3(-width/2, -height/2, 0) //put origin at bottom left
);
err = glGetError();
if(err != 0)
LogNotice("resize 2, err = %x\n", err);

//GTK creates a FBO for us, but doesn't tell us what it is!
//We need to glGet the FBO ID the first time we're resized.
if(!m_windowFramebuffer.IsInitialized())
m_windowFramebuffer.InitializeFromCurrentFramebuffer();

err = glGetError();
if(err != 0)
LogNotice("resize 3, err = %x\n", err);

//Allocate waveform texture
m_waveformTextureResolved.Bind();
m_waveformTextureResolved.SetData(width, height, NULL, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA32F);
@@ -93,7 +79,7 @@ void WaveformArea::on_resize(int width, int height)

err = glGetError();
if(err != 0)
LogNotice("resize 4, err = %x\n", err);
LogNotice("resize 3, err = %x\n", err);

//double dt = GetTime() - start;
//LogDebug("Resize time: %.3f ms\n", dt*1000);
10 changes: 9 additions & 1 deletion glscopeclient/WaveformArea_rendering.cpp
Original file line number Diff line number Diff line change
@@ -176,6 +176,13 @@ bool WaveformArea::on_render(const Glib::RefPtr<Gdk::GLContext>& /*context*/)
LogIndenter li;
//LogTrace("Rendering %s\n", m_channel->m_displayname.c_str());

//On the first frame, figure out what the actual screen surface FBO is.
if(m_firstFrame)
{
m_windowFramebuffer.InitializeFromCurrentFramebuffer();
m_firstFrame = false;
}

double start = GetTime();
double dt = start - m_lastFrameStart;
if(m_lastFrameStart > 0)
@@ -204,6 +211,7 @@ bool WaveformArea::on_render(const Glib::RefPtr<Gdk::GLContext>& /*context*/)

//Render the Cairo layers with the GL waveform sandwiched in between
RenderCairoUnderlays();

if(IsEye())
RenderEye();
else if(IsWaterfall())
@@ -216,7 +224,7 @@ bool WaveformArea::on_render(const Glib::RefPtr<Gdk::GLContext>& /*context*/)
RenderCairoOverlays();

//Sanity check
int err = glGetError();
GLint err = glGetError();
if(err != 0)
LogNotice("Render: err = %x\n", err);

2 changes: 2 additions & 0 deletions glscopeclient/shaders/waveform-compute.glsl
Original file line number Diff line number Diff line change
@@ -98,7 +98,9 @@ void main()

//Fill in the space between min and max for this segment
for(int y=ymin; y <= ymax; y++)
{
g_workingBuffer[y] += alpha;
}

//TODO: antialiasing
//TODO: decimation at very wide zooms
9 changes: 0 additions & 9 deletions glscopeclient/shaders/waveform-fragment.glsl

This file was deleted.

20 changes: 0 additions & 20 deletions glscopeclient/shaders/waveform-vertex.glsl

This file was deleted.