|  | @@ -57,8 +57,7 @@ laColumn *DEBUG_C;
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #ifdef __linux__
 | 
	
		
			
				|  |  | -typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
 | 
	
		
			
				|  |  | -typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
 | 
	
		
			
				|  |  | +typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
 | 
	
		
			
				|  |  |  typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
 | 
	
		
			
				|  |  |  glXCreateContextAttribsARBProc glXCreateContextAttribsF;
 | 
	
		
			
				|  |  |  glXSwapIntervalEXTProc glXSwapIntervalEXTF;
 | 
	
	
		
			
				|  | @@ -191,7 +190,7 @@ SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncTo
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      XStoreName(MAIN.dpy, win, title);
 | 
	
		
			
				|  |  |      //XMapWindow(MAIN.dpy, win);
 | 
	
		
			
				|  |  | -    glXMakeCurrent(MAIN.dpy, win, MAIN.glc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent((*r_glc),win);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -222,8 +221,8 @@ SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncTo
 | 
	
		
			
				|  |  |      return win;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  void la_DestroySystemWindowX11(laWindow* w) {
 | 
	
		
			
				|  |  | -    glXMakeCurrent(MAIN.dpy, None, NULL);
 | 
	
		
			
				|  |  | -    glXDestroyContext(MAIN.dpy, w->glc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(0,0);
 | 
	
		
			
				|  |  | +    tnsDeleteContext(w->glc);
 | 
	
		
			
				|  |  |      XDestroyWindow(MAIN.dpy, w->win);
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  #endif //linux
 | 
	
	
		
			
				|  | @@ -350,13 +349,11 @@ void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
 | 
	
		
			
				|  |  |      hdc = GetDC(hwnd);
 | 
	
		
			
				|  |  |      la_SetupPxlFormat(hdc, &a, &b);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    wglMakeCurrent(0, 0);
 | 
	
		
			
				|  |  |      hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    //wglShareLists(hglrc, MAIN.glc);
 | 
	
		
			
				|  |  | -    wglMakeCurrent(hdc, hglrc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(hglrc, hdc);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
 | 
	
		
			
				|  |  |      wglSwapIntervalEXT(-1);
 | 
	
	
		
			
				|  | @@ -373,7 +370,8 @@ SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int Sync
 | 
	
		
			
				|  |  |      return hwnd;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  void la_DestroySystemWindowWin32(laWindow* w) {
 | 
	
		
			
				|  |  | -    wglDeleteContext(w->glc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(0,0);
 | 
	
		
			
				|  |  | +    tnsDeleteContext(w->glc);
 | 
	
		
			
				|  |  |      ReleaseDC(w->win, w->hdc);
 | 
	
		
			
				|  |  |      DestroyWindow(w->win);
 | 
	
		
			
				|  |  |  };
 | 
	
	
		
			
				|  | @@ -421,6 +419,17 @@ void glDebugOutput(GLenum source, GLenum type, unsigned int id,
 | 
	
		
			
				|  |  |      }printf("%s\n\n", strsource);
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +void la_SetCurrentGLContextDebug(){
 | 
	
		
			
				|  |  | +    glEnable(GL_DEBUG_OUTPUT);
 | 
	
		
			
				|  |  | +    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
 | 
	
		
			
				|  |  | +    glDebugMessageCallback(glDebugOutput, 0);
 | 
	
		
			
				|  |  | +    glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH|GL_DEBUG_SEVERITY_MEDIUM, 0, 0, GL_TRUE);
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +void la_SetupWindowGLStates(laWindow* w){
 | 
	
		
			
				|  |  | +    tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
 | 
	
		
			
				|  |  |      SYSGLCONTEXT glc;
 | 
	
		
			
				|  |  |  #ifdef __linux__
 | 
	
	
		
			
				|  | @@ -430,6 +439,7 @@ int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
 | 
	
		
			
				|  |  |      SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  |      window->win = hwnd;
 | 
	
		
			
				|  |  | +    window->glc = glc;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #ifdef _WIN32
 | 
	
		
			
				|  |  |      la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
 | 
	
	
		
			
				|  | @@ -443,14 +453,10 @@ int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
 | 
	
		
			
				|  |  |      XGetWindowAttributes(MAIN.dpy, window->win, &attr);
 | 
	
		
			
				|  |  |      window->CW =attr.width;
 | 
	
		
			
				|  |  |      window->CH = attr.height;
 | 
	
		
			
				|  |  | -    window->glc = glc;
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    glEnable(GL_DEBUG_OUTPUT);
 | 
	
		
			
				|  |  | -    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
 | 
	
		
			
				|  |  | -    glDebugMessageCallback(glDebugOutput, 0);
 | 
	
		
			
				|  |  | -    glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    la_SetCurrentGLContextDebug();
 | 
	
		
			
				|  |  | +    glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
 | 
	
		
			
				|  |  | +    la_SetupWindowGLStates(window);
 | 
	
		
			
				|  |  |      return 1;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -464,10 +470,12 @@ int la_DestroySystemWindow(laWindow* wnd){
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void la_DestroyWindow(laWindow *wnd){
 | 
	
		
			
				|  |  | -    laLayout *l; laPanel *p;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    if (!wnd) return;
 | 
	
		
			
				|  |  | +    laLayout *l; laPanel *p; if (!wnd) return;
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  | +    tnsSwitchToCurrentWindowContext(wnd);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      la_StopAllOperators();
 | 
	
		
			
				|  |  |      strSafeDestroy(&wnd->Title);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -733,6 +741,8 @@ int laGetReadyWith(laInitArguments* ia){
 | 
	
		
			
				|  |  |      if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
 | 
	
		
			
				|  |  |      if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    tnsInit();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  #ifdef __linux__
 | 
	
		
			
				|  |  |      SYSWINDOW root, win;
 | 
	
		
			
				|  |  |      GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
 | 
	
	
		
			
				|  | @@ -809,7 +819,7 @@ int laGetReadyWith(laInitArguments* ia){
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    glXMakeCurrent(MAIN.dpy, win, MAIN.glc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(MAIN.glc,win);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
 | 
	
		
			
				|  |  |      logPrint("    OpenGL Version: %d.%d\n",major,minor);
 | 
	
	
		
			
				|  | @@ -820,6 +830,10 @@ int laGetReadyWith(laInitArguments* ia){
 | 
	
		
			
				|  |  |          printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    la_SetCurrentGLContextDebug();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
 | 
	
		
			
				|  |  |      MAIN.bufid =  XInternAtom(MAIN.dpy, "CLIPBOARD", False),
 | 
	
		
			
				|  |  |      MAIN.fmtid =  XInternAtom(MAIN.dpy, "UTF8_STRING", False),
 | 
	
	
		
			
				|  | @@ -875,7 +889,7 @@ int laGetReadyWith(laInitArguments* ia){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      SetPixelFormat(hdc, 1, &cpfd);
 | 
	
		
			
				|  |  |      hglrc = wglCreateContext(hdc);
 | 
	
		
			
				|  |  | -    wglMakeCurrent(hdc, hglrc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(hglrc, hdc);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //MAIN.hdc = hdc;
 | 
	
		
			
				|  |  |     // MAIN.tWND = hwnd;
 | 
	
	
		
			
				|  | @@ -1044,6 +1058,18 @@ void laShutoff(int SavePrefereces){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      logClear();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#ifdef __linux__
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(0,0);
 | 
	
		
			
				|  |  | +    tnsDeleteContext(MAIN.glc);
 | 
	
		
			
				|  |  | +#endif
 | 
	
		
			
				|  |  | +#ifdef _WIN32
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(0,0);
 | 
	
		
			
				|  |  | +    tnsDeleteContext(MAIN.glc);
 | 
	
		
			
				|  |  | +    UnloadWintab();
 | 
	
		
			
				|  |  | +#endif
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      tnsQuit();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
 | 
	
	
		
			
				|  | @@ -1053,14 +1079,6 @@ void laShutoff(int SavePrefereces){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      hshFree(&MAIN.DBInstMemLeft);
 | 
	
		
			
				|  |  |      memNoLonger();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -#ifdef __linux__
 | 
	
		
			
				|  |  | -    glXDestroyContext(MAIN.dpy,MAIN.glc);
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  | -#ifdef _WIN32
 | 
	
		
			
				|  |  | -    wglDeleteContext(MAIN.glc);
 | 
	
		
			
				|  |  | -    UnloadWintab();
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void laSaveUserPreferences(){
 | 
	
	
		
			
				|  | @@ -1703,11 +1721,7 @@ void laEnsurePanelInBound(laPanel *p, laUiList *uil){
 | 
	
		
			
				|  |  |      p->TX = p->X; p->TY = p->Y;
 | 
	
		
			
				|  |  |      p->TW = p->W; p->TH = p->H;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    if (p->OffScr &&
 | 
	
		
			
				|  |  | -        (p->W != p->OffScr->pColor[0]->Width ||
 | 
	
		
			
				|  |  | -         p->H != p->OffScr->pColor[0]->Height)){
 | 
	
		
			
				|  |  | -        tnsConfigureOffscreen(p->OffScr, p->W,p->H);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +    if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
 | 
	
		
			
				|  |  |      tnsDrawToOffscreen(p->OffScr, 1, 0);
 | 
	
	
		
			
				|  | @@ -2349,7 +2363,7 @@ void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
 | 
	
		
			
				|  |  |  int laStartWindow(laWindow *w){
 | 
	
		
			
				|  |  |  #ifdef __linux__
 | 
	
		
			
				|  |  |      XMapWindow(MAIN.dpy,w->win);
 | 
	
		
			
				|  |  | -    glXMakeContextCurrent(MAIN.dpy, w->win,w->win, w->glc);
 | 
	
		
			
				|  |  | +    tnsContextMakeCurrent(w->glc,w->win);
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  |  #ifdef _WIN32
 | 
	
		
			
				|  |  |      ShowWindow(w->win, SW_SHOWNORMAL);
 | 
	
	
		
			
				|  | @@ -7283,7 +7297,7 @@ void laMainLoop(){
 | 
	
		
			
				|  |  |          if(MAIN.PreDraw){ MAIN.PreDraw(); }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
 | 
	
		
			
				|  |  | -            tnsSwitchToCurrentWindowContext(w);
 | 
	
		
			
				|  |  | +            tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
 | 
	
		
			
				|  |  |              la_DrawWindow(w);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
 |