GUI: new osc renderer, part 26

sorry another window
This commit is contained in:
tildearrow 2024-02-20 15:40:48 -05:00
parent 086c792d33
commit e17df27f66
6 changed files with 71 additions and 5 deletions

View file

@ -4674,6 +4674,30 @@ bool FurnaceGUI::loop() {
MEASURE(effectList,drawEffectList());
}
// NEW CODE - REMOVE WHEN DONE
if (ImGui::Begin("Shader Editor 2024",NULL)) {
ImGui::PushFont(patFont);
ImGui::InputTextMultiline("##SHFragment",&newOscFragment,ImVec2(ImGui::GetContentRegionAvail().x,ImGui::GetContentRegionAvail().y-ImGui::GetFrameHeightWithSpacing()),ImGuiInputTextFlags_UndoRedo);
ImGui::PopFont();
if (ImGui::Button("Save")) {
FILE* f=ps_fopen("/storage/emulated/0/osc.fsh","w");
if (f==NULL) {
showError("Something happened");
} else {
fwrite(newOscFragment.c_str(),1,newOscFragment.size(),f);
fclose(f);
showError("Saved!");
}
}
ImGui::SameLine();
if (ImGui::Button("Apply")) {
if (!rend->regenOscShader(newOscFragment.c_str())) {
showError("Of course you screwed it up, again!");
}
}
}
ImGui::End();
// release selection if mouse released
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && selecting) {
if (!selectingFull) cursor=selEnd;
@ -6950,6 +6974,9 @@ bool FurnaceGUI::init() {
ImGui::CreateContext();
rend->initGUI(sdlWin);
// NEW CODE - REMOVE WHEN DONE
newOscFragment=rend->getStupidFragment();
applyUISettings();
logD("building font...");

View file

@ -1435,6 +1435,8 @@ class FurnaceGUIRender {
virtual void drawOsc(float* data, size_t len, ImVec2 pos0, ImVec2 pos1, ImVec4 color, ImVec2 canvasSize, float lineWidth);
virtual void present();
virtual bool supportsDrawOsc();
virtual const char* getStupidFragment();
virtual bool regenOscShader(const char* fragment);
virtual bool getOutputSize(int& w, int& h);
virtual int getWindowFlags();
virtual void preInit();
@ -1478,6 +1480,7 @@ class FurnaceGUI {
int sampleTexW, sampleTexH;
bool updateSampleTex;
String newOscFragment;
String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile, sysSearchQuery, newSongQuery, paletteQuery;
String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport;
String workingDirVGMExport, workingDirZSMExport, workingDirROMExport, workingDirFont, workingDirColors, workingDirKeybinds;

View file

@ -307,7 +307,7 @@ void FurnaceGUI::drawOsc() {
} else {
for (int i=0; i<oscWidth-24; i++) {
float x=(float)i/(float)(oscWidth-24);
float y=oscValuesAverage[i+12];
float y=oscValuesAverage[i+12]*0.5f;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;

View file

@ -110,5 +110,13 @@ bool FurnaceGUIRender::isDead() {
return false;
}
const char* FurnaceGUIRender::getStupidFragment() {
return "Only OpenGL";
}
bool FurnaceGUIRender::regenOscShader(const char* fragment) {
return false;
}
FurnaceGUIRender::~FurnaceGUIRender() {
}

View file

@ -46,6 +46,8 @@ PFNGLATTACHSHADERPROC furAttachShader=NULL;
PFNGLBINDATTRIBLOCATIONPROC furBindAttribLocation=NULL;
PFNGLCREATEPROGRAMPROC furCreateProgram=NULL;
PFNGLLINKPROGRAMPROC furLinkProgram=NULL;
PFNGLDELETEPROGRAMPROC furDeleteProgram=NULL;
PFNGLDELETESHADERPROC furDeleteShader=NULL;
PFNGLGETPROGRAMIVPROC furGetProgramiv=NULL;
PFNGLUSEPROGRAMPROC furUseProgram=NULL;
PFNGLGETUNIFORMLOCATIONPROC furGetUniformLocation=NULL;
@ -115,9 +117,9 @@ const char* sh_oscRender_srcF=
" if ((fur_fragCoord.y-uLineWidth)>valmax*uResolution.y) discard;\n"
" if ((fur_fragCoord.y+uLineWidth)<valmin*uResolution.y) discard;\n"
" float slope=abs(valmax-valmin)*uResolution.y;\n"
" float slopeDiv=min(1.0,1.0/slope);\n"
" float xRight=fur_fragCoord.x+uLineWidth;\n"
" for (float x=max(0.0,fur_fragCoord.x-uLineWidth); x<=xRight; x+=slopeDiv) {\n"
" float slopeDiv=min(1.0,2.0/ceil(slope));\n"
" float xRight=ceil(fur_fragCoord.x+uLineWidth);\n"
" for (float x=max(0.0,floor(fur_fragCoord.x-uLineWidth)); x<=xRight; x+=slopeDiv) {\n"
" float val0=texture2D(oscVal,vec2(floor(x)*oneStep,1.0)).x*uResolution.y;\n"
" float val1=texture2D(oscVal,vec2(floor(x+1.0)*oneStep,1.0)).x*uResolution.y;\n"
" float val=mix(val0,val1,fract(x));\n"
@ -437,7 +439,7 @@ void FurnaceGUIRenderGL::drawOsc(float* data, size_t len, ImVec2 pos0, ImVec2 po
//C(glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA));
//C(glEnable(GL_BLEND));
float width=fabs(pos1.x-pos0.x);
//float width=fabs(pos1.x-pos0.x);
float height=fabs(pos1.y-pos0.y)*0.5;
pos0.x=(2.0f*pos0.x/canvasSize.x)-1.0f;
@ -587,6 +589,8 @@ bool FurnaceGUIRenderGL::init(SDL_Window* win) {
LOAD_PROC_OPTIONAL(furLinkProgram,PFNGLLINKPROGRAMPROC,"glLinkProgram");
LOAD_PROC_OPTIONAL(furGetProgramiv,PFNGLGETPROGRAMIVPROC,"glGetProgramiv");
LOAD_PROC_OPTIONAL(furUseProgram,PFNGLUSEPROGRAMPROC,"glUseProgram");
LOAD_PROC_OPTIONAL(furDeleteProgram,PFNGLDELETEPROGRAMPROC,"glDeleteProgram");
LOAD_PROC_OPTIONAL(furDeleteShader,PFNGLDELETESHADERPROC,"glDeleteShader");
LOAD_PROC_OPTIONAL(furGetUniformLocation,PFNGLGETUNIFORMLOCATIONPROC,"glGetUniformLocation");
LOAD_PROC_OPTIONAL(furUniform1f,PFNGLUNIFORM1FPROC,"glUniform1f");
LOAD_PROC_OPTIONAL(furUniform2f,PFNGLUNIFORM2FPROC,"glUniform2f");
@ -630,6 +634,28 @@ bool FurnaceGUIRenderGL::init(SDL_Window* win) {
return true;
}
const char* FurnaceGUIRenderGL::getStupidFragment() {
return sh_oscRender_srcF;
}
bool FurnaceGUIRenderGL::regenOscShader(const char* fragment) {
if (sh_oscRender_have) {
furDeleteProgram(sh_oscRender_program);
furDeleteShader(sh_oscRender_vertex);
furDeleteShader(sh_oscRender_fragment);
}
if ((sh_oscRender_have=createShader(sh_oscRender_srcV,fragment,sh_oscRender_vertex,sh_oscRender_fragment,sh_oscRender_program,sh_oscRender_attrib))==true) {
sh_oscRender_uColor=furGetUniformLocation(sh_oscRender_program,"uColor");
sh_oscRender_uLineWidth=furGetUniformLocation(sh_oscRender_program,"uLineWidth");
sh_oscRender_uResolution=furGetUniformLocation(sh_oscRender_program,"uResolution");
sh_oscRender_oscVal=furGetUniformLocation(sh_oscRender_program,"oscVal");
return true;
}
return false;
}
void FurnaceGUIRenderGL::initGUI(SDL_Window* win) {
ImGui_ImplSDL2_InitForOpenGL(win,context);
ImGui_ImplOpenGL3_Init();

View file

@ -57,6 +57,8 @@ class FurnaceGUIRenderGL: public FurnaceGUIRender {
bool destroyTexture(FurnaceGUITexture* which);
void setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode);
void setBlendMode(FurnaceGUIBlendMode mode);
const char* getStupidFragment();
bool regenOscShader(const char* fragment);
void clear(ImVec4 color);
bool newFrame();
void createFontsTexture();