From bda9ef9345786d48fd0d98b0855ce965e1028b2f Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 5 May 2016 23:48:06 +0800 Subject: Add support for batching vertices with custom indices. Fix compiler warnings. --- extensions/smbmfont.cpp | 4 +-- include/smelt.hpp | 3 +- include/smttfont.hpp | 2 +- smelt/sdl/gfx_sdl.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++-- smelt/sdl/makefile | 2 +- smelt/sdl/smelt_internal.hpp | 1 + smelt/sdl/sys_sdl.cpp | 14 ++++----- 7 files changed, 81 insertions(+), 15 deletions(-) diff --git a/extensions/smbmfont.cpp b/extensions/smbmfont.cpp index 97b7fdb..def8454 100644 --- a/extensions/smbmfont.cpp +++ b/extensions/smbmfont.cpp @@ -211,11 +211,11 @@ void smBMFontw::render(float x,float y,float z,int align,float *rw,const wchar_t } void smBMFontw::printf(float x,float y,float z,int align,float *rw,const wchar_t* format,...) { - wchar_t buf[1024]; + wchar_t buf[1025]; va_list vl; va_start(vl,format); vswprintf(buf,sizeof(buf)-1,format,vl); va_end(vl); - buf[sizeof(buf)-1]='\0'; + buf[1024]=L'\0'; render(x,y,z,align,rw,buf); } diff --git a/include/smelt.hpp b/include/smelt.hpp index 3894e34..40bc52f 100644 --- a/include/smelt.hpp +++ b/include/smelt.hpp @@ -22,7 +22,7 @@ * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with Foobar. If not, see . + * along with SMELT. If not, see . * */ @@ -362,6 +362,7 @@ public: virtual void smRenderQuad(smQuad *q)=0; virtual smVertex* smGetVertArray()=0; virtual void smDrawVertArray(int prim,SMTEX texture,int blend,int _primcnt)=0; + virtual void smDrawCustomIndexedVertices(smVertex* vb,WORD* ib,int vbc,int ibc,int blend,SMTEX texture)=0; virtual SMTRG smTargetCreate(int w,int h)=0; virtual SMTEX smTargetTexture(SMTRG targ)=0; diff --git a/include/smttfont.hpp b/include/smttfont.hpp index 777d8ed..0f87b1c 100644 --- a/include/smttfont.hpp +++ b/include/smttfont.hpp @@ -42,7 +42,7 @@ protected: FT_Library ftlib; FT_Face ttface; private: - wchar_t buf[1024]; + wchar_t buf[1025]; std::map chars; float w,h; public: diff --git a/smelt/sdl/gfx_sdl.cpp b/smelt/sdl/gfx_sdl.cpp index 4e80a38..f0dca92 100644 --- a/smelt/sdl/gfx_sdl.cpp +++ b/smelt/sdl/gfx_sdl.cpp @@ -217,6 +217,70 @@ void SMELT_IMPL::smDrawVertArray(int prim,SMTEX texture,int blend,int _primcnt) if(primBlend!=blend)setBlend(blend); primcnt=primcnt; } +void SMELT_IMPL::smDrawCustomIndexedVertices(smVertex* vb,WORD* ib,int vbc,int ibc,int blend,SMTEX texture) +{ + if(vertexArray) + { + batchOGL(); + pOpenGLDevice->glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER,0); + pOpenGLDevice->glVertexPointer(3,GL_FLOAT,sizeof(smVertex),&vb[0].x); + pOpenGLDevice->glColorPointer(4,GL_UNSIGNED_BYTE,sizeof(smVertex),&vb[0].col); + pOpenGLDevice->glTexCoordPointer(2,GL_FLOAT,sizeof(smVertex),&vb[0].tx); + + float twm=1.,thm=1.; + if(texture) + { + 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*)texture; + if(pOpenGLDevice->TextureTarget==GL_TEXTURE_RECTANGLE_ARB) + {twm=ptex->rw;thm=ptex->rh;} + else if(ptex->dw&&ptex->dh) + { + twm=(ptex->rw)/(float)(ptex->dw); + thm=(ptex->rh)/(float)(ptex->dh); + } + } + if(!tdmode) + { + float h=curTarget?curTarget->h:scrh; + for(int i=0;i>24)&0xFF); + BYTE r=((color>>16)&0xFF); + BYTE g=((color>> 8)&0xFF); + BYTE b=((color>> 0)&0xFF); + col[0]=r;col[1]=g; + col[2]=b;col[3]=a; + } + if(texture!=primTex)bindTexture((glTexture*)texture); + if(blend!=primBlend)setBlend(blend); + pOpenGLDevice->glDrawElements(GL_TRIANGLES,ibc,GL_UNSIGNED_SHORT,ib); + + pOpenGLDevice->glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER,IndexBufferObject); + pOpenGLDevice->glVertexPointer(3,GL_FLOAT,sizeof(smVertex),&vertexBuf[0].x); + pOpenGLDevice->glColorPointer(4,GL_UNSIGNED_BYTE,sizeof(smVertex),&vertexBuf[0].col); + pOpenGLDevice->glTexCoordPointer(2,GL_FLOAT,sizeof(smVertex),&vertexBuf[0].tx); + } +} SMTRG SMELT_IMPL::smTargetCreate(int w,int h) { bool ok=false; @@ -683,8 +747,8 @@ void SMELT_IMPL::batchOGL(bool endScene) pOpenGLDevice->glDrawArrays(GL_TRIANGLES,0,3*primcnt); break; case PRIM_QUADS: - pOpenGLDevice->glDrawElements(GL_TRIANGLES,6*primcnt,GL_UNSIGNED_SHORT,indexBuf); - if(false) + pOpenGLDevice->glDrawElements(GL_TRIANGLES,6*primcnt,GL_UNSIGNED_SHORT,pOpenGLDevice->have_GL_ARB_vertex_buffer_object?0:indexBuf); +#if 0 for (int i=0;iglGenBuffersARB(1,&IndexBufferObject); pOpenGLDevice->glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER,IndexBufferObject); pOpenGLDevice->glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER,sizeof(GLushort)*((VERTEX_BUFFER_SIZE*6)/4),indexBuf,GL_STATIC_DRAW); - delete[] indexBuf;indexBuf=NULL; } pOpenGLDevice->glVertexPointer(3,GL_FLOAT,sizeof(smVertex),&vertexBuf[0].x); pOpenGLDevice->glColorPointer(4,GL_UNSIGNED_BYTE,sizeof(smVertex),&vertexBuf[0].col); diff --git a/smelt/sdl/makefile b/smelt/sdl/makefile index 28a3629..fc513d5 100644 --- a/smelt/sdl/makefile +++ b/smelt/sdl/makefile @@ -1,5 +1,5 @@ CC= g++ -CXXFLAGS= -c -g -std=c++11 -Wall -I/usr/include/SDL/ -I../include -D_LINUX -fPIC +CXXFLAGS= -c -g -O2 -std=c++11 -Wall -I/usr/include/SDL/ -I../include -D_LINUX -fPIC all: objects-normal archive-normal diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp index b786ee6..7825f51 100644 --- a/smelt/sdl/smelt_internal.hpp +++ b/smelt/sdl/smelt_internal.hpp @@ -154,6 +154,7 @@ public: virtual void smRenderQuad(smQuad *q); virtual smVertex* smGetVertArray(); virtual void smDrawVertArray(int prim,SMTEX texture,int blend,int _primcnt); + virtual void smDrawCustomIndexedVertices(smVertex* vb,WORD* ib,int vbc,int ibc,int blend,SMTEX texture); virtual SMTRG smTargetCreate(int w,int h); virtual SMTEX smTargetTexture(SMTRG targ); diff --git a/smelt/sdl/sys_sdl.cpp b/smelt/sdl/sys_sdl.cpp index 427b1bf..b33d71b 100644 --- a/smelt/sdl/sys_sdl.cpp +++ b/smelt/sdl/sys_sdl.cpp @@ -53,7 +53,7 @@ bool SMELT_IMPL::smInit() unsigned int nExIds=CPUInfo[0]; char *cpuName,*loced;cpuName=calloc(0x40,sizeof(char));loced=cpuName; for(unsigned int i=0x80000000;i<=nExIds;++i) - { + { __cpuid(CPUInfo, i); if(i==0x80000002) memcpy(cpuName,CPUInfo,sizeof(CPUInfo)); @@ -69,17 +69,17 @@ bool SMELT_IMPL::smInit() GlobalMemoryStatus(&mem_st); smLog("%s:" SLINE ": Memory: %ldK total, %ldK free\n", SYS_SDL_SRCFN,mem_st.dwTotalPhys/1024L,mem_st.dwAvailPhys/1024L); #else - system("uname -svm > os.out"); - char osv[100];FILE* a=fopen("os.out","r");fgets(osv,100,a);fclose(a); + system("uname -svm > /tmp/os.out"); + char osv[100];FILE* a=fopen("/tmp/os.out","r");fgets(osv,100,a);fclose(a); osv[strlen(osv)-1]='\0'; smLog("%s:" SLINE ": OS: %s\n",SYS_SDL_SRCFN,osv); - system("rm os.out"); + system("rm /tmp/os.out"); - system("cat /proc/cpuinfo | grep name -m 1 > cpu.out"); - a=fopen("cpu.out","r");fgets(osv,100,a);fclose(a); + system("cat /proc/cpuinfo | grep name -m 1 > /tmp/cpu.out"); + a=fopen("/tmp/cpu.out","r");fgets(osv,100,a);fclose(a); osv[strlen(osv)-1]='\0';char *ptr=osv;while(*ptr!=':')++ptr;ptr+=2; smLog("%s:" SLINE ": CPU: %s\n",SYS_SDL_SRCFN,osv); - system("rm cpu.out"); + system("rm /tmp/cpu.out"); a=fopen("/proc/meminfo","r"); unsigned totalm,freem; -- cgit v1.2.3