Skip to content

Commit

Permalink
Merge pull request #13491 from ywwg/ywwg/fix-high-details
Browse files Browse the repository at this point in the history
fix high details waveforms wrapping around after visual index 65K
  • Loading branch information
JoergAtGithub authored Jul 25, 2024
2 parents 02a6f26 + 017c7fd commit 7a3c515
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
5 changes: 0 additions & 5 deletions res/shaders/filteredsignal.frag
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ uniform sampler2D waveformDataTexture;

vec4 getWaveformData(float index) {
vec2 uv_data;
// The Waveform data is composed of 8 bytes per sample, (low, mid, high, all,
// stem1, stem2, stem3, stem4), see WaveformData struct. Currently, shaders
// don't support stem rendering.
index = 2 * index;

uv_data.y = floor(index / float(textureStride));
uv_data.x = floor(index - uv_data.y * float(textureStride));
// Divide again to convert to normalized UV coordinates.
Expand Down
15 changes: 2 additions & 13 deletions res/shaders/rgbsignal.frag
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,8 @@ uniform sampler2D waveformDataTexture;

vec4 getWaveformData(float index) {
vec2 uv_data;
// The Waveform data is composed of 8 bytes per sample, (low, mid, high,
// all, stem1, stem2, stem3, stem4), see WaveformData struct. Currently,
// shaders don't support stem rendering.
index = 2 * index;

uv_data.y = splitStereoSignal
? floor(index / float(textureStride))
: max(floor(index / float(textureStride)),
floor((index + 2) / float(textureStride)));
uv_data.x = splitStereoSignal
? floor(index - uv_data.y * float(textureStride))
: max(floor(index - uv_data.y * float(textureStride)),
floor((index + 2) - uv_data.y * float(textureStride)));
uv_data.y = splitStereoSignal ? floor(index / float(textureStride)) : max(floor(index / float(textureStride)), floor((index + 1) / float(textureStride)));
uv_data.x = splitStereoSignal ? floor(index - uv_data.y * float(textureStride)) : max(floor(index - uv_data.y * float(textureStride)), floor((index + 1) - uv_data.y * float(textureStride)));
// Divide again to convert to normalized UV coordinates.
return texture2D(waveformDataTexture, uv_data / float(textureStride));
}
Expand Down
5 changes: 0 additions & 5 deletions res/shaders/stackedsignal.frag
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ uniform sampler2D waveformDataTexture;

vec4 getWaveformData(float index) {
vec2 uv_data;
// The Waveform data is composed of 8 bytes per sample, (low, mid, high, all,
// stem1, stem2, stem3, stem4), see WaveformData struct. Currently, shaders
// don't support stem rendering.
index = 2 * index;

uv_data.y = floor(index / float(textureStride));
uv_data.x = floor(index - uv_data.y * float(textureStride));
// Divide again to convert to normalized UV coordinates.
Expand Down
17 changes: 12 additions & 5 deletions src/waveform/renderers/allshader/waveformrenderertextured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "moc_waveformrenderertextured.cpp"
#include "track/track.h"
#include "waveform/renderers/waveformwidgetrenderer.h"
#include "waveform/waveform.h"

namespace allshader {

Expand Down Expand Up @@ -130,6 +129,15 @@ bool WaveformRendererTextured::loadTexture() {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

if (pWaveform != nullptr && data != nullptr) {
// Make a copy of the waveform data, stripping the stems portion. Note that the datasize is
// different from the texture size -- we want the full texture size so the upload works. See
// m_data in waveform/waveform.h.
if (m_data.size() == 0 || static_cast<int>(m_data.size()) != pWaveform->getTextureSize()) {
m_data.resize(pWaveform->getTextureSize());
}
for (int i = 0; i < pWaveform->getDataSize(); i++) {
m_data[i] = data[i].filtered;
}
// Waveform ensures that getTextureSize is a multiple of
// getTextureStride so there is no rounding here.
int textureWidth = pWaveform->getTextureStride();
Expand All @@ -143,7 +151,7 @@ bool WaveformRendererTextured::loadTexture() {
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
data);
m_data.data());
int error = glGetError();
if (error) {
qDebug() << "WaveformRendererTextured::loadTexture - glTexImage2D error" << error;
Expand Down Expand Up @@ -296,8 +304,7 @@ void WaveformRendererTextured::paintGL() {
return;
}

const WaveformData* data = pWaveform->data();
if (data == nullptr) {
if (pWaveform->data() == nullptr) {
return;
}

Expand All @@ -307,7 +314,7 @@ void WaveformRendererTextured::paintGL() {
}

// NOTE(vRince): completion can change during loadTexture
// do not remove currenCompletion temp variable !
// do not remove currentCompletion temp variable !
const int currentCompletion = pWaveform->getCompletion();
if (m_textureRenderedWaveformCompletion < currentCompletion) {
loadTexture();
Expand Down
10 changes: 10 additions & 0 deletions src/waveform/renderers/allshader/waveformrenderertextured.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "waveform/renderers/allshader/rgbdata.h"
#include "waveform/renderers/allshader/vertexdata.h"
#include "waveform/renderers/allshader/waveformrenderersignalbase.h"
#include "waveform/waveform.h"
#include "waveform/widgets/waveformwidgettype.h"

class QOpenGLFramebufferObject;
Expand Down Expand Up @@ -43,6 +44,13 @@ class allshader::WaveformRendererTextured : public QObject,
void slotWaveformUpdated();

private:
struct WaveformTexture {
unsigned char low;
unsigned char mid;
unsigned char high;
unsigned char all;
};

static QString fragShaderForType(WaveformWidgetType::Type t);
bool loadShaders();
bool loadTexture();
Expand All @@ -56,6 +64,8 @@ class allshader::WaveformRendererTextured : public QObject,
TrackPointer m_loadedTrack;
int m_textureRenderedWaveformCompletion;

std::vector<WaveformFilteredData> m_data;

// Frame buffer for two pass rendering.
std::unique_ptr<QOpenGLFramebufferObject> m_framebuffer;

Expand Down
14 changes: 8 additions & 6 deletions src/waveform/waveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
enum FilterIndex { Low = 0, Mid = 1, High = 2, FilterCount = 3};
enum ChannelIndex { Left = 0, Right = 1, ChannelCount = 2};

struct WaveformFilteredData {
unsigned char low;
unsigned char mid;
unsigned char high;
unsigned char all;
};

struct WaveformData {
struct {
unsigned char low;
unsigned char mid;
unsigned char high;
unsigned char all;
} filtered;
WaveformFilteredData filtered;
unsigned char stems[mixxx::kMaxSupportedStem];
};

Expand Down

0 comments on commit 7a3c515

Please sign in to comment.