GUI: new osc renderer, part 21

part 11? I must have been drunk
alternate approach for OpenGL ES (no more hangs)
This commit is contained in:
tildearrow 2024-02-19 15:49:56 -05:00
parent 89249d4a2b
commit cfee9b3810
6 changed files with 82 additions and 40 deletions

View file

@ -182,16 +182,30 @@ void FurnaceGUI::drawChanOsc() {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Checkbox("Randomize phase on note",&chanOscRandomPhase)) { if (ImGui::Checkbox("Randomize phase on note",&chanOscRandomPhase)) {
} }
ImGui::EndTable();
}
ImGui::AlignTextToFramePadding(); ImGui::TableNextRow();
ImGui::Text("Amplitude"); ImGui::TableNextColumn();
ImGui::SameLine(); ImGui::AlignTextToFramePadding();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); ImGui::Text("Amplitude");
if (CWSliderFloat("##COSAmp",&chanOscAmplify,0.0f,2.0f)) { ImGui::SameLine();
if (chanOscAmplify<0.0f) chanOscAmplify=0.0f; ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (chanOscAmplify>2.0f) chanOscAmplify=2.0f; if (CWSliderFloat("##COSAmp",&chanOscAmplify,0.0f,2.0f)) {
if (chanOscAmplify<0.0f) chanOscAmplify=0.0f;
if (chanOscAmplify>2.0f) chanOscAmplify=2.0f;
}
ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::Text("Line size");
ImGui::SameLine();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (CWSliderFloat("##COSLine",&chanOscLineSize,0.25f,16.0f)) {
if (chanOscLineSize<0.25f) chanOscLineSize=0.26f;
if (chanOscLineSize>16.0f) chanOscLineSize=16.0f;
}
ImGui::EndTable();
} }
ImGui::Checkbox("Gradient",&chanOscUseGrad); ImGui::Checkbox("Gradient",&chanOscUseGrad);
@ -706,6 +720,7 @@ void FurnaceGUI::drawChanOsc() {
fft->drawOp.pos0=inRect.Min; fft->drawOp.pos0=inRect.Min;
fft->drawOp.pos1=inRect.Max; fft->drawOp.pos1=inRect.Max;
fft->drawOp.color=ImGui::ColorConvertU32ToFloat4(color); fft->drawOp.color=ImGui::ColorConvertU32ToFloat4(color);
fft->drawOp.lineSize=dpiScale*chanOscLineSize;
dl->AddCallback(_drawOsc,&fft->drawOp); dl->AddCallback(_drawOsc,&fft->drawOp);
dl->AddCallback(ImDrawCallback_ResetRenderState,NULL); dl->AddCallback(ImDrawCallback_ResetRenderState,NULL);
@ -713,7 +728,7 @@ void FurnaceGUI::drawChanOsc() {
//ImGui::PushClipRect(inRect.Min,inRect.Max,false); //ImGui::PushClipRect(inRect.Min,inRect.Max,false);
//ImDrawListFlags prevFlags=dl->Flags; //ImDrawListFlags prevFlags=dl->Flags;
//dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex); //dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex);
dl->AddPolyline(waveform,precision,color,ImDrawFlags_None,dpiScale); dl->AddPolyline(waveform,precision,color,ImDrawFlags_None,dpiScale*chanOscLineSize);
//dl->Flags=prevFlags; //dl->Flags=prevFlags;
//ImGui::PopClipRect(); //ImGui::PopClipRect();
} }

View file

@ -6613,6 +6613,7 @@ bool FurnaceGUI::init() {
chanOscTextX=e->getConfFloat("chanOscTextX",0.0f); chanOscTextX=e->getConfFloat("chanOscTextX",0.0f);
chanOscTextY=e->getConfFloat("chanOscTextY",0.0f); chanOscTextY=e->getConfFloat("chanOscTextY",0.0f);
chanOscAmplify=e->getConfFloat("chanOscAmplify",0.95f); chanOscAmplify=e->getConfFloat("chanOscAmplify",0.95f);
chanOscLineSize=e->getConfFloat("chanOscLineSize",1.0f);
chanOscWindowSize=e->getConfFloat("chanOscWindowSize",20.0f); chanOscWindowSize=e->getConfFloat("chanOscWindowSize",20.0f);
chanOscWaveCorr=e->getConfBool("chanOscWaveCorr",true); chanOscWaveCorr=e->getConfBool("chanOscWaveCorr",true);
chanOscOptions=e->getConfBool("chanOscOptions",false); chanOscOptions=e->getConfBool("chanOscOptions",false);
@ -6935,8 +6936,6 @@ bool FurnaceGUI::init() {
} }
} }
newOscLineWidth=dpiScale;
updateWindowTitle(); updateWindowTitle();
rend->clear(ImVec4(0.0,0.0,0.0,1.0)); rend->clear(ImVec4(0.0,0.0,0.0,1.0));
@ -7165,6 +7164,7 @@ void FurnaceGUI::commitState() {
e->setConf("chanOscTextX",chanOscTextX); e->setConf("chanOscTextX",chanOscTextX);
e->setConf("chanOscTextY",chanOscTextY); e->setConf("chanOscTextY",chanOscTextY);
e->setConf("chanOscAmplify",chanOscAmplify); e->setConf("chanOscAmplify",chanOscAmplify);
e->setConf("chanOscLineSize",chanOscLineSize);
e->setConf("chanOscWindowSize",chanOscWindowSize); e->setConf("chanOscWindowSize",chanOscWindowSize);
e->setConf("chanOscWaveCorr",chanOscWaveCorr); e->setConf("chanOscWaveCorr",chanOscWaveCorr);
e->setConf("chanOscOptions",chanOscOptions); e->setConf("chanOscOptions",chanOscOptions);
@ -7314,7 +7314,6 @@ FurnaceGUI::FurnaceGUI():
shallDetectScale(0), shallDetectScale(0),
cpuCores(0), cpuCores(0),
secondTimer(0.0f), secondTimer(0.0f),
newOscLineWidth(2.0f),
userEvents(0xffffffff), userEvents(0xffffffff),
mobileMenuPos(0.0f), mobileMenuPos(0.0f),
autoButtonSize(0.0f), autoButtonSize(0.0f),
@ -7680,6 +7679,7 @@ FurnaceGUI::FurnaceGUI():
chanOscTextX(0.0f), chanOscTextX(0.0f),
chanOscTextY(0.0f), chanOscTextY(0.0f),
chanOscAmplify(0.95f), chanOscAmplify(0.95f),
chanOscLineSize(1.0f),
chanOscWaveCorr(true), chanOscWaveCorr(true),
chanOscOptions(false), chanOscOptions(false),
updateChanOscGradTex(true), updateChanOscGradTex(true),

View file

@ -1455,13 +1455,15 @@ struct PendingDrawOsc {
ImVec2 pos0; ImVec2 pos0;
ImVec2 pos1; ImVec2 pos1;
ImVec4 color; ImVec4 color;
float lineSize;
PendingDrawOsc(): PendingDrawOsc():
gui(NULL), gui(NULL),
data(NULL), data(NULL),
len(0), len(0),
pos0(0,0), pos0(0,0),
pos1(0,0), pos1(0,0),
color(0,0,0,0) {} color(0,0,0,0),
lineSize(0.0f) {}
}; };
class FurnaceGUI { class FurnaceGUI {
@ -1521,7 +1523,7 @@ class FurnaceGUI {
int wheelCalmDown; int wheelCalmDown;
int shallDetectScale; int shallDetectScale;
int cpuCores; int cpuCores;
float secondTimer, newOscLineWidth; float secondTimer;
unsigned int userEvents; unsigned int userEvents;
float mobileMenuPos, autoButtonSize, mobileEditAnim; float mobileMenuPos, autoButtonSize, mobileEditAnim;
ImVec2 mobileEditButtonPos, mobileEditButtonSize; ImVec2 mobileEditButtonPos, mobileEditButtonSize;
@ -1684,6 +1686,7 @@ class FurnaceGUI {
int oscEscapesBoundary; int oscEscapesBoundary;
int oscMono; int oscMono;
int oscAntiAlias; int oscAntiAlias;
float oscLineSize;
int separateFMColors; int separateFMColors;
int insEditColorize; int insEditColorize;
int metroVol; int metroVol;
@ -1886,6 +1889,7 @@ class FurnaceGUI {
oscEscapesBoundary(0), oscEscapesBoundary(0),
oscMono(1), oscMono(1),
oscAntiAlias(1), oscAntiAlias(1),
oscLineSize(1.0f),
separateFMColors(0), separateFMColors(0),
insEditColorize(0), insEditColorize(0),
metroVol(100), metroVol(100),
@ -2284,7 +2288,7 @@ class FurnaceGUI {
// per-channel oscilloscope // per-channel oscilloscope
int chanOscCols, chanOscAutoColsType, chanOscColorX, chanOscColorY; int chanOscCols, chanOscAutoColsType, chanOscColorX, chanOscColorY;
float chanOscWindowSize, chanOscTextX, chanOscTextY, chanOscAmplify; float chanOscWindowSize, chanOscTextX, chanOscTextY, chanOscAmplify, chanOscLineSize;
bool chanOscWaveCorr, chanOscOptions, updateChanOscGradTex, chanOscUseGrad, chanOscNormalize, chanOscRandomPhase; bool chanOscWaveCorr, chanOscOptions, updateChanOscGradTex, chanOscUseGrad, chanOscNormalize, chanOscRandomPhase;
String chanOscTextFormat; String chanOscTextFormat;
ImVec4 chanOscColor, chanOscTextColor; ImVec4 chanOscColor, chanOscTextColor;

View file

@ -110,7 +110,7 @@ void FurnaceGUI::readOsc() {
avg+=oscValues[j][i]; avg+=oscValues[j][i];
} }
avg/=e->getAudioDescGot().outChans; avg/=e->getAudioDescGot().outChans;
oscValuesAverage[i]=avg; oscValuesAverage[i]=avg*oscZoom;
} }
/*for (int i=0; i<oscWidth; i++) { /*for (int i=0; i<oscWidth; i++) {
@ -150,7 +150,7 @@ static void _drawOsc(const ImDrawList* drawList, const ImDrawCmd* cmd) {
} }
void FurnaceGUI::runPendingDrawOsc(PendingDrawOsc* which) { void FurnaceGUI::runPendingDrawOsc(PendingDrawOsc* which) {
rend->drawOsc(which->data,which->len,which->pos0,which->pos1,which->color,ImVec2(canvasW,canvasH),newOscLineWidth); rend->drawOsc(which->data,which->len,which->pos0,which->pos1,which->color,ImVec2(canvasW,canvasH),which->lineSize);
} }
void FurnaceGUI::drawOsc() { void FurnaceGUI::drawOsc() {
@ -300,6 +300,7 @@ void FurnaceGUI::drawOsc() {
_do.pos0=inRect.Min; _do.pos0=inRect.Min;
_do.pos1=inRect.Max; _do.pos1=inRect.Max;
_do.color=isClipping?uiColors[GUI_COLOR_OSC_WAVE_PEAK]:uiColors[GUI_COLOR_OSC_WAVE]; _do.color=isClipping?uiColors[GUI_COLOR_OSC_WAVE_PEAK]:uiColors[GUI_COLOR_OSC_WAVE];
_do.lineSize=dpiScale*settings.oscLineSize;
dl->AddCallback(_drawOsc,&_do); dl->AddCallback(_drawOsc,&_do);
dl->AddCallback(ImDrawCallback_ResetRenderState,NULL); dl->AddCallback(ImDrawCallback_ResetRenderState,NULL);
@ -316,37 +317,49 @@ void FurnaceGUI::drawOsc() {
if (settings.oscEscapesBoundary) { if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen(); dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize);
dl->PopClipRect(); dl->PopClipRect();
} else { } else {
dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize);
} }
} }
} else { } else {
for (int ch=0; ch<e->getAudioDescGot().outChans; ch++) { for (int ch=0; ch<e->getAudioDescGot().outChans; ch++) {
for (int i=0; i<oscWidth-24; i++) { if (!isClipping) {
float x=(float)i/(float)(oscWidth-24); color=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_WAVE_CH0+ch]);
float y=oscValues[ch][i+12]*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
} }
if (!isClipping) { if (rend->supportsDrawOsc() && settings.shaderOsc) {
//color=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_WAVE_CH0+ch]); _do.gui=this;
} _do.data=&oscValues[ch][12];
_do.len=oscWidth-24;
/* _do.pos0=inRect.Min;
if (settings.oscEscapesBoundary) { _do.pos1=inRect.Max;
dl->PushClipRectFullScreen(); _do.color=isClipping?uiColors[GUI_COLOR_OSC_WAVE_PEAK]:uiColors[GUI_COLOR_OSC_WAVE_CH0+ch];
dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); _do.lineSize=dpiScale*settings.oscLineSize;
dl->PopClipRect();
dl->AddCallback(_drawOsc,&_do);
dl->AddCallback(ImDrawCallback_ResetRenderState,NULL);
} else { } else {
dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); for (int i=0; i<oscWidth-24; i++) {
float x=(float)i/(float)(oscWidth-24);
float y=oscValues[ch][i+12]*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize);
}
} }
*/
} }
} }
} }

View file

@ -116,7 +116,8 @@ const char* sh_oscRender_srcF=
" float slope=abs(valmax-valmin)*uResolution.y*0.5;\n" " float slope=abs(valmax-valmin)*uResolution.y*0.5;\n"
" float slopeDiv=min(uAdvance,(uAdvance/slope));\n" " float slopeDiv=min(uAdvance,(uAdvance/slope));\n"
" float xRight=uv.x+((uLineWidth)/uResolution.x);\n" " float xRight=uv.x+((uLineWidth)/uResolution.x);\n"
" for (float x=max(0.0,uv.x-(uLineWidth/uResolution.x)); x<=xRight; x+=slopeDiv) {\n" " for (float s=0.0; s<max(1,slope); s+=1.0) {\n"
" float x=max(0.0,uv.x-(uLineWidth/uResolution.x)+s*slopeDiv);\n"
" float val=texture2D(oscVal,vec2(x,1.0)).x*uResolution.y*0.5;\n" " float val=texture2D(oscVal,vec2(x,1.0)).x*uResolution.y*0.5;\n"
" alpha+=clamp(uLineWidth-distance(vec2(fur_fragCoord.x,fur_fragCoord.y),vec2(x*uResolution.x,val)),0.0,1.0);\n" " alpha+=clamp(uLineWidth-distance(vec2(fur_fragCoord.x,fur_fragCoord.y),vec2(x*uResolution.x,val)),0.0,1.0);\n"
" }\n" " }\n"

View file

@ -3200,6 +3200,12 @@ void FurnaceGUI::drawSettings() {
settingsChanged=true; settingsChanged=true;
} }
if (ImGui::SliderFloat("Line size",&settings.oscLineSize,0.25f,16.0f,"%.1f")) {
if (settings.oscLineSize<0.25f) settings.oscLineSize=0.25f;
if (settings.oscLineSize>16.0f) settings.oscLineSize=16.0f;
settingsChanged=true;
} rightClickable
// SUBSECTION WINDOWS // SUBSECTION WINDOWS
CONFIG_SUBSECTION("Windows"); CONFIG_SUBSECTION("Windows");
bool roundedWindowsB=settings.roundedWindows; bool roundedWindowsB=settings.roundedWindows;
@ -3977,6 +3983,7 @@ void FurnaceGUI::readConfig(DivConfig& conf, FurnaceGUISettingGroups groups) {
settings.oscEscapesBoundary=conf.getInt("oscEscapesBoundary",0); settings.oscEscapesBoundary=conf.getInt("oscEscapesBoundary",0);
settings.oscMono=conf.getInt("oscMono",1); settings.oscMono=conf.getInt("oscMono",1);
settings.oscAntiAlias=conf.getInt("oscAntiAlias",1); settings.oscAntiAlias=conf.getInt("oscAntiAlias",1);
settings.oscLineSize=conf.getFloat("oscLineSize",1.0f);
settings.channelColors=conf.getInt("channelColors",1); settings.channelColors=conf.getInt("channelColors",1);
settings.channelTextColors=conf.getInt("channelTextColors",0); settings.channelTextColors=conf.getInt("channelTextColors",0);
@ -4263,6 +4270,7 @@ void FurnaceGUI::readConfig(DivConfig& conf, FurnaceGUISettingGroups groups) {
clampSetting(settings.basicColors,0,1); clampSetting(settings.basicColors,0,1);
clampSetting(settings.playbackTime,0,1); clampSetting(settings.playbackTime,0,1);
clampSetting(settings.shaderOsc,0,1); clampSetting(settings.shaderOsc,0,1);
clampSetting(settings.oscLineSize,0.25f,16.0f);
if (settings.exportLoops<0.0) settings.exportLoops=0.0; if (settings.exportLoops<0.0) settings.exportLoops=0.0;
if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0; if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0;
@ -4443,6 +4451,7 @@ void FurnaceGUI::writeConfig(DivConfig& conf, FurnaceGUISettingGroups groups) {
conf.set("oscEscapesBoundary",settings.oscEscapesBoundary); conf.set("oscEscapesBoundary",settings.oscEscapesBoundary);
conf.set("oscMono",settings.oscMono); conf.set("oscMono",settings.oscMono);
conf.set("oscAntiAlias",settings.oscAntiAlias); conf.set("oscAntiAlias",settings.oscAntiAlias);
conf.set("oscLineSize",settings.oscLineSize);
conf.set("channelColors",settings.channelColors); conf.set("channelColors",settings.channelColors);
conf.set("channelTextColors",settings.channelTextColors); conf.set("channelTextColors",settings.channelTextColors);