kopia lustrzana https://github.com/jameshball/osci-render
105 wiersze
3.9 KiB
C++
105 wiersze
3.9 KiB
C++
#pragma once
|
|
|
|
#include <JuceHeader.h>
|
|
#include "VisualiserSettings.h"
|
|
#include "../audio/SampleRateManager.h"
|
|
#include "../shape/OsciPoint.h"
|
|
|
|
struct Texture {
|
|
GLuint id;
|
|
int width;
|
|
int height;
|
|
};
|
|
|
|
class VisualiserOpenGLComponent : public juce::Component, public juce::OpenGLRenderer, public juce::AsyncUpdater {
|
|
public:
|
|
VisualiserOpenGLComponent(VisualiserSettings& settings, SampleRateManager& sampleRateManager);
|
|
~VisualiserOpenGLComponent() override;
|
|
|
|
void newOpenGLContextCreated() override;
|
|
void renderOpenGL() override;
|
|
void openGLContextClosing() override;
|
|
void resized() override;
|
|
void paint(juce::Graphics& g) override;
|
|
void updateBuffer(const std::vector<OsciPoint>& buffer);
|
|
void setPaused(bool paused);
|
|
void handleAsyncUpdate() override;
|
|
|
|
private:
|
|
juce::OpenGLContext openGLContext;
|
|
|
|
float renderScale = 1.0f;
|
|
|
|
GLuint quadIndexBuffer = 0;
|
|
GLuint vertexIndexBuffer = 0;
|
|
GLuint vertexBuffer = 0;
|
|
|
|
int nPoints = 0;
|
|
int nEdges = 0;
|
|
|
|
juce::CriticalSection samplesLock;
|
|
bool needsReattach = true;
|
|
std::vector<float> xSamples{2};
|
|
std::vector<float> ySamples;
|
|
std::vector<float> zSamples;
|
|
std::vector<float> smoothedXSamples;
|
|
std::vector<float> smoothedYSamples;
|
|
std::vector<float> smoothedZSamples;
|
|
|
|
std::vector<float> scratchVertices;
|
|
std::vector<float> fullScreenQuad;
|
|
|
|
GLuint frameBuffer = 0;
|
|
Texture lineTexture;
|
|
Texture blur1Texture;
|
|
Texture blur2Texture;
|
|
Texture blur3Texture;
|
|
Texture blur4Texture;
|
|
juce::OpenGLTexture screenOpenGLTexture;
|
|
juce::Image screenTextureImage = juce::ImageFileFormat::loadFrom(BinaryData::noise_jpg, BinaryData::noise_jpgSize);
|
|
juce::Image emptyScreenImage = juce::ImageFileFormat::loadFrom(BinaryData::empty_jpg, BinaryData::empty_jpgSize);
|
|
Texture screenTexture;
|
|
std::optional<Texture> targetTexture = std::nullopt;
|
|
|
|
std::unique_ptr<juce::OpenGLShaderProgram> simpleShader;
|
|
std::unique_ptr<juce::OpenGLShaderProgram> texturedShader;
|
|
std::unique_ptr<juce::OpenGLShaderProgram> blurShader;
|
|
std::unique_ptr<juce::OpenGLShaderProgram> lineShader;
|
|
std::unique_ptr<juce::OpenGLShaderProgram> outputShader;
|
|
juce::OpenGLShaderProgram* currentShader;
|
|
|
|
VisualiserSettings& settings;
|
|
SampleRateManager& sampleRateManager;
|
|
float fadeAmount;
|
|
bool smudgesEnabled = settings.getSmudgesEnabled();
|
|
bool graticuleEnabled = settings.getGraticuleEnabled();
|
|
|
|
bool paused = false;
|
|
|
|
const double RESAMPLE_RATIO = 6.0;
|
|
double sampleRate = -1;
|
|
chowdsp::ResamplingTypes::LanczosResampler<2048, 8> xResampler;
|
|
chowdsp::ResamplingTypes::LanczosResampler<2048, 8> yResampler;
|
|
chowdsp::ResamplingTypes::LanczosResampler<2048, 8> zResampler;
|
|
|
|
Texture makeTexture(int width, int height);
|
|
void setupArrays(int num_points);
|
|
void setupTextures();
|
|
void drawLineTexture(const std::vector<float>& xPoints, const std::vector<float>& yPoints, const std::vector<float>& zPoints);
|
|
void saveTextureToFile(GLuint textureID, int width, int height, const juce::File& file);
|
|
void activateTargetTexture(std::optional<Texture> texture);
|
|
void setShader(juce::OpenGLShaderProgram* program);
|
|
void drawTexture(std::optional<Texture> texture0, std::optional<Texture> texture1 = std::nullopt, std::optional<Texture> texture2 = std::nullopt, std::optional<Texture> texture3 = std::nullopt);
|
|
void setAdditiveBlending();
|
|
void setNormalBlending();
|
|
void drawLine(const std::vector<float>& xPoints, const std::vector<float>& yPoints, const std::vector<float>& zPoints);
|
|
void fade();
|
|
void drawCRT();
|
|
void checkGLErrors(const juce::String& location);
|
|
void viewportChanged();
|
|
Texture createScreenTexture();
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VisualiserOpenGLComponent)
|
|
};
|
|
|