diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-01-25 23:01:59 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-01-25 23:01:59 +0800 |
commit | 841465ea45e56bf2f294b5cb934e5ff955c72401 (patch) | |
tree | 6ea71790c1b1c8458cdf6b2b751788ecd32943bf /smelt | |
parent | 1d64816653b5d1835dd60762c2bc64f000d88fa5 (diff) | |
download | SMELT-841465ea45e56bf2f294b5cb934e5ff955c72401.tar.xz |
Texture options.
Add smHandler* version of event handlers.
Diffstat (limited to 'smelt')
-rw-r--r-- | smelt/sdl/gfx_sdl.cpp | 52 | ||||
-rw-r--r-- | smelt/sdl/smelt_internal.hpp | 8 | ||||
-rw-r--r-- | smelt/sdl/sys_sdl.cpp | 19 |
3 files changed, 70 insertions, 9 deletions
diff --git a/smelt/sdl/gfx_sdl.cpp b/smelt/sdl/gfx_sdl.cpp index 47b6999..4e80a38 100644 --- a/smelt/sdl/gfx_sdl.cpp +++ b/smelt/sdl/gfx_sdl.cpp @@ -343,6 +343,45 @@ void SMELT_IMPL::smTextureFree(SMTEX tex) delete ptex; } } +void SMELT_IMPL::smTextureOpt(int potopt,int filter) +{ + batchOGL(); + if(potopt==TPOT_NONPOT) + { + if(pOpenGLDevice->have_GL_ARB_texture_rectangle) + pOpenGLDevice->TextureTarget=GL_TEXTURE_RECTANGLE_ARB; + else if(pOpenGLDevice->have_GL_ARB_texture_non_power_of_two) + pOpenGLDevice->TextureTarget=GL_TEXTURE_2D; + else pOpenGLDevice->TextureTarget=GL_TEXTURE_2D; + pOpenGLDevice->glDisable(GL_TEXTURE_2D); + if(pOpenGLDevice->have_GL_ARB_texture_rectangle)pOpenGLDevice->glDisable(GL_TEXTURE_RECTANGLE_ARB); + pOpenGLDevice->glEnable(pOpenGLDevice->TextureTarget); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE); + } + if(potopt==TPOT_POT) + { + pOpenGLDevice->TextureTarget=GL_TEXTURE_2D; + pOpenGLDevice->glDisable(GL_TEXTURE_2D); + if(pOpenGLDevice->have_GL_ARB_texture_rectangle)pOpenGLDevice->glDisable(GL_TEXTURE_RECTANGLE_ARB); + pOpenGLDevice->glEnable(pOpenGLDevice->TextureTarget); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_WRAP_S,GL_REPEAT); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_WRAP_T,GL_REPEAT); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_WRAP_R,GL_REPEAT); + } + filtermode=filter; + if(filter==TFLT_NEAREST) + { + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + } + if(filter==TFLT_LINEAR) + { + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + } +} int SMELT_IMPL::smTextureGetWidth(SMTEX tex,bool original) { if(original) @@ -594,8 +633,16 @@ void SMELT_IMPL::batchOGL(bool endScene) float twm=1.,thm=1.; if(primTex) { - pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + if(filtermode==TFLT_NEAREST) + { + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + } + if(filtermode==TFLT_LINEAR) + { + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + } glTexture *ptex=(glTexture*)primTex; if(pOpenGLDevice->TextureTarget==GL_TEXTURE_RECTANGLE_ARB) {twm=ptex->rw;thm=ptex->rh;} @@ -881,6 +928,7 @@ bool SMELT_IMPL::confOGL() pOpenGLDevice->glEnable(GL_ALPHA_TEST); pOpenGLDevice->glAlphaFunc(GL_GEQUAL,1.0f/255.0f); pOpenGLDevice->glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); + filtermode=TFLT_LINEAR; pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR); pOpenGLDevice->glTexParameteri(pOpenGLDevice->TextureTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //GL_REPEAT doesn't work with non-pot textures... diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp index c3cfa89..6d9e04f 100644 --- a/smelt/sdl/smelt_internal.hpp +++ b/smelt/sdl/smelt_internal.hpp @@ -91,8 +91,11 @@ public: virtual void smUpdateFunc(smHook func); virtual void smUpdateFunc(smHandler* h); virtual void smUnFocFunc(smHook func); + virtual void smUnFocFunc(smHandler* h); virtual void smFocFunc(smHook func); + virtual void smFocFunc(smHandler* h); virtual void smQuitFunc(smHook func); + virtual void smQuitFunc(smHandler* h); virtual void smWinTitle(const char* title); virtual bool smIsActive(); virtual void smNoSuspend(bool para); @@ -159,6 +162,7 @@ public: virtual SMTEX smTextureLoad(const char *path); virtual SMTEX smTextureLoadFromMemory(const char *ptr,DWORD size); virtual void smTextureFree(SMTEX tex); + virtual void smTextureOpt(int potopt=TPOT_NONPOT,int filter=TFLT_LINEAR); virtual int smTextureGetWidth(SMTEX tex,bool original=false); virtual int smTextureGetHeight(SMTEX tex,bool original=false); virtual DWORD* smTextureLock(SMTEX tex,int l,int t,int w,int h,bool ro=true); @@ -175,7 +179,7 @@ public: bool (*pUnFocFunc)(); bool (*pFocFunc)(); bool (*pQuitFunc)(); - smHandler *updateHandler; + smHandler *updateHandler,*unFocHandler,*focHandler,*quitHandler; const char *Icon; char winTitle[256]; int scrw,scrh; @@ -195,7 +199,7 @@ public: TRenderTargetList *curTarget; TTextureList *textures; bool tdmode; - int primcnt,primType,primBlend; + int primcnt,primType,primBlend,filtermode; SMTEX primTex; bool zbufenabled; bool checkGLExtension(const char *extlist,const char *ext); diff --git a/smelt/sdl/sys_sdl.cpp b/smelt/sdl/sys_sdl.cpp index 675d88f..427b1bf 100644 --- a/smelt/sdl/sys_sdl.cpp +++ b/smelt/sdl/sys_sdl.cpp @@ -182,8 +182,11 @@ void SMELT_IMPL::smMainLoop() void SMELT_IMPL::smUpdateFunc(smHook func){pUpdateFunc=func;} void SMELT_IMPL::smUpdateFunc(smHandler* h){updateHandler=h;} void SMELT_IMPL::smUnFocFunc(smHook func){pUnFocFunc=func;} +void SMELT_IMPL::smUnFocFunc(smHandler* h){unFocHandler=h;} void SMELT_IMPL::smFocFunc(smHook func){pFocFunc=func;} +void SMELT_IMPL::smFocFunc(smHandler* h){focHandler=h;} void SMELT_IMPL::smQuitFunc(smHook func){pQuitFunc=func;} +void SMELT_IMPL::smQuitFunc(smHandler* h){quitHandler=h;} void SMELT_IMPL::smWinTitle(const char *title){strcpy(winTitle,title);} bool SMELT_IMPL::smIsActive(){return Active;} void SMELT_IMPL::smNoSuspend(bool para){noSuspend=para;} @@ -250,7 +253,8 @@ float SMELT_IMPL::smGetTime(){return timeS;} SMELT_IMPL::SMELT_IMPL() { hwnd=NULL;Active=false;memset(curError,0,sizeof(curError)); - pUpdateFunc=pUnFocFunc=pFocFunc=pQuitFunc=NULL;updateHandler=NULL; + pUpdateFunc=pUnFocFunc=pFocFunc=pQuitFunc=NULL; + updateHandler=unFocHandler=focHandler=quitHandler=NULL; Icon=NULL;strcpy(winTitle,"untitled");scrw=dispw=800;scrh=disph=600; windowed=vsync=false;memset(logFile,0,sizeof(logFile)); limfps=0;hideMouse=true;noSuspend=false; @@ -263,8 +267,8 @@ SMELT_IMPL::SMELT_IMPL() void SMELT_IMPL::focusChange(bool actif) { Active=actif; - if(actif)pFocFunc?pFocFunc():0; - else pUnFocFunc?pUnFocFunc():0; + if(actif){pFocFunc?pFocFunc():0;focHandler?focHandler->handlerFunc():0;} + else {pUnFocFunc?pUnFocFunc():0;unFocHandler?unFocHandler->handlerFunc():0;}; } bool SMELT_IMPL::procSDLEvent(const SDL_Event &e) { @@ -291,8 +295,13 @@ bool SMELT_IMPL::procSDLEvent(const SDL_Event &e) } break; case SDL_QUIT: - if(pSM->pQuitFunc&&!pSM->pQuitFunc())break; - return false; + { + bool accepted=true; + if(pSM->pQuitFunc&&pSM->pQuitFunc())accepted=false; + if(pSM->quitHandler&&quitHandler->handlerFunc())accepted=false; + if(accepted)return false; + } + break; case SDL_KEYDOWN: keymods=(SDL_Keymod)e.key.keysym.mod; if((keymods&KMOD_ALT)&&((e.key.keysym.sym==SDLK_RETURN)||(e.key.keysym.sym==SDLK_KP_ENTER))) |