shader sync toimii

This commit is contained in:
2025-06-24 15:54:17 +03:00
parent 47cb2c965f
commit 134a85111e
11 changed files with 992 additions and 791 deletions

View File

@ -28,9 +28,8 @@
#pragma data_seg(".shader")
#include "shaders/post.inl"
#endif
#ifdef SU_LOAD_GMDLS
su_load_gmdls();
#endif // SU_LOAD_GMDLS
#pragma data_seg(".pids")
// static allocation saves a few bytes
static int pidMain;
@ -66,13 +65,15 @@ int __cdecl main(int argc, char* argv[])
// initalize opengl context
SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
wglMakeCurrent(hDC, wglCreateContext(hDC));
// create and compile shader programs
pidMain = ((PFNGLCREATESHADERPROGRAMVPROC)wglGetProcAddress("glCreateShaderProgramv"))(GL_FRAGMENT_SHADER, 1, &fragment_frag);
#if POST_PASS
pidPost = ((PFNGLCREATESHADERPROGRAMVPROC)wglGetProcAddress("glCreateShaderProgramv"))(GL_FRAGMENT_SHADER, 1, &post_frag);
#endif
#ifdef SU_LOAD_GMDLS
su_load_gmdls();
#endif // SU_LOAD_GMDLS
// initialize sound
#ifndef EDITOR_CONTROLS
#if USE_AUDIO
@ -81,6 +82,7 @@ int __cdecl main(int argc, char* argv[])
waveOutPrepareHeader(hWaveOut, &WaveHDR, sizeof(WaveHDR));
waveOutWrite(hWaveOut, &WaveHDR, sizeof(WaveHDR));
#endif
#else
Leviathan::Editor editor = Leviathan::Editor();
editor.updateShaders(&pidMain, &pidPost, true);
@ -92,10 +94,13 @@ int __cdecl main(int argc, char* argv[])
double position = 0.0;
#endif
// main loop
// main loop
do
{
#ifdef EDITOR_CONTROLS
float syncs[1 + SU_NUMSYNCS];
#ifdef EDITOR_CONTROLS
editor.beginFrame(timeGetTime());
#endif
@ -118,15 +123,32 @@ int __cdecl main(int argc, char* argv[])
glColor3ui(MMTime.u.sample, 0, 0);
#else
// remember to divide your shader time variable with the SAMPLE_RATE (44100 with 4klang)
((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"))(0, MMTime.u.sample);
//((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"))(0, MMTime.u.sample);
#endif
#endif
#else
position = track.getTime();
((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"))(0, (static_cast<int>(position*44100.0)));
#endif
syncs[0] = MMTime.u.sample / (2 * sizeof(SUsample));
for (int i = 0; i < SU_NUMSYNCS; ++i)
{
syncs[i + 1] = syncBuf[
(MMTime.u.sample >> 8) * SU_NUMSYNCS + i
];
}
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
glRects(-1, -1, 1, 1);
//syncs[0] = -syncs[0];
//glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
// render "post process" using the opengl backbuffer
#if POST_PASS
glBindTexture(GL_TEXTURE_2D, 1);