filterview

This commit is contained in:
2026-01-23 17:18:02 +13:00
parent 87cafe3a05
commit 7dd7ec43cd
8 changed files with 247 additions and 90 deletions

View File

@@ -8,20 +8,6 @@
==============================================================================
*/
#include <JuceHeader.h>
#include "FilterView.h"
//==============================================================================
/*
* ==============================================================================
*
* FilterView.cpp
* Created: 16 Jan 2026 5:05:38pm
* Author: esca
*
* ==============================================================================
*/
#include <JuceHeader.h>
#include "FilterView.h"
#include "BinaryData.h"
@@ -31,32 +17,81 @@
//==============================================================================
FilterView::FilterView()
{
float startingColour[4] = {128.0f, 255.0f, 255.0f, 255.0f};
cutoff = &tempcutoff;
mix = &tempmix;
//generate filter arrays for first time
for(unsigned int i=0; i<FILTERVIEW_SAMPLECOUNT; i++){
filterVertices.push_back(Vertex{{0,0}, COLOUR});
filterIndices.push_back(i);
filterBackgroundVertices.push_back(Vertex{{0,0}, BGCOLOUR});
//BACKGROUND INDICES
if(i!=0&&i%2==0){
filterBackgroundIndices.insert(filterBackgroundIndices.end(), { i-2, i-1, i });
}
backgroundVertices.push_back(VertexTexture{{-1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{-1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 1.0f}});
backgroundVertices.push_back(VertexTexture{{1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 1.0f}});
backgroundIndices = {0,1,2,1,2,3};
if(i!=1&&i%2!=0){
filterBackgroundIndices.insert(filterBackgroundIndices.end(), { i-2, i-1, i });
}
}
genFilterArrays();
antialiasing.multisamplingLevel = 3;
ctx.setPixelFormat(antialiasing);
float startingColour[4] = {128.0f, 255.0f, 255.0f, 255.0f};
backgroundVertices.push_back(VertexTexture{{-1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{-1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 1.0f}});
backgroundVertices.push_back(VertexTexture{{1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 1.0f}});
backgroundIndices = {0,1,2,1,2,3};
setOpaque(true);
ctx.setContinuousRepainting(true);
ctx.setRenderer(this);
ctx.attachTo(*this);
setOpaque(true);
}
FilterView::~FilterView()
{
bgTexture.bind();
bgTexture.release();
shaderProgramFilter->release();
shaderProgramFilterFill->release();
shaderProgramBackground->release();
ctx.detach();
// ctx.detach(); //failing here
}
void FilterView::genFilterArrays(){
int i = 0;
float yposition = *mix;
for(Vertex &v : filterVertices){
float xposition = (float)i/FILTERVIEW_SAMPLECOUNT;
float deltaCutoff = xposition-*cutoff;
v.position[0] = xposition;
if(deltaCutoff>0){
v.position[1] = yposition-5*(deltaCutoff*deltaCutoff);
if(v.position[1]<0){
v.position[1]=0;
}
}
else v.position[1] = yposition;
i++;
}
vScale(filterVertices, 2, 2);
vTransform(filterVertices, -1, -1);
genFilterFillArrays();
}
void FilterView::genFilterFillArrays(){
for(unsigned int i = 0; i<FILTERVIEW_SAMPLECOUNT; i++){
if(i%2==0){
filterBackgroundVertices.at(i) = filterVertices.at(i);
filterBackgroundVertices.at(i).position[1]=-1;
}
else{
filterBackgroundVertices.at(i) = filterVertices.at(i-1);
}
}
}
void FilterView::paint (juce::Graphics& g)
@@ -74,8 +109,8 @@ void FilterView::resized()
void FilterView::newOpenGLContextCreated(){
background = juce::ImageCache::getFromMemory(BinaryData::panel_png, BinaryData::panel_pngSize);
background.duplicateIfShared();
bgTexture.loadImage(background);
//GENERATE BUFFERS
ctx.extensions.glGenBuffers(1, &vboBackground);
@@ -87,7 +122,6 @@ void FilterView::newOpenGLContextCreated(){
ctx.extensions.glGenBuffers(1, &vboFilter);
ctx.extensions.glGenBuffers(1, &iboFilter);
//BIND BACKGROUND BUFFERS
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
@@ -99,16 +133,23 @@ void FilterView::newOpenGLContextCreated(){
//BIND FILTER FILL BUFFERS
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilterFill);
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*filterVertices.size(), filterVertices.data(), juce::gl::GL_STATIC_DRAW);
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*filterBackgroundVertices.size(), filterBackgroundVertices.data(), juce::gl::GL_STATIC_DRAW);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboFilterFill);
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * filterBackgroundIndices.size(), filterBackgroundIndices.data(), juce::gl::GL_STATIC_DRAW);
//BIND FILTER BUFFERS
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilter);
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*filterVertices.size(), filterVertices.data(), juce::gl::GL_STATIC_DRAW);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboFilter);
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * filterIndices.size(), filterIndices.data(), juce::gl::GL_STATIC_DRAW);
//SHADERS
vertexShaderFilter = "placeholder";
fragmentShaderFilter = "placeholder";
vertexShaderFilterFill = "placeholder";
fragmentShaderFilterFill = "placeholder";
vertexShaderFilter = VERTEXSHADERFILTER;
fragmentShaderFilter = FRAGSHADERFILTER;
vertexShaderFilterFill = VERTEXSHADERFILTERFILL;
fragmentShaderFilterFill = FRAGSHADERFILTER;
vertexShaderBackground = VERTEXSHADERBACKGROUND;
fragmentShaderBackground = FRAGSHADERBACKGROUND;
@@ -130,6 +171,7 @@ void FilterView::newOpenGLContextCreated(){
shaderProgramFilter->addFragmentShader(fragmentShaderFilter);
shaderProgramFilter->link();
shaderProgramFilter->use();
}
void FilterView::renderOpenGL(){
@@ -139,7 +181,6 @@ void FilterView::renderOpenGL(){
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboBackground);
//RENDER BACKGROUND
shaderProgramBackground->use();
bgTexture.bind();
@@ -155,7 +196,6 @@ void FilterView::renderOpenGL(){
ctx.extensions.glEnableVertexAttribArray(2);
juce::gl::glDrawElements(juce::gl::GL_TRIANGLES, backgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
bgTexture.unbind();
//RENDER FILTER FILL
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilterFill);
@@ -166,7 +206,7 @@ void FilterView::renderOpenGL(){
ctx.extensions.glEnableVertexAttribArray(2);
ctx.extensions.glVertexAttribPointer(1, 4, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float)*2));
ctx.extensions.glEnableVertexAttribArray(3);
juce::gl::glDrawElements(juce::gl::GL_LINE_STRIP, filterBackgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
juce::gl::glDrawElements(juce::gl::GL_TRIANGLES, filterBackgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
//RENDER FILTER
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilter);
@@ -183,4 +223,3 @@ void FilterView::renderOpenGL(){
void FilterView::openGLContextClosing(){
}