aboutsummaryrefslogtreecommitdiff
path: root/smelt
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-05 23:48:06 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-05 23:48:06 +0800
commitbda9ef9345786d48fd0d98b0855ce965e1028b2f (patch)
treecdcc7adc9f496c37cbcc75d8cccd2066d02c277b /smelt
parentc2b99f6321965b2c5b30a1b72b29119281c2d7e1 (diff)
downloadSMELT-bda9ef9345786d48fd0d98b0855ce965e1028b2f.tar.xz
Add support for batching vertices with custom indices.
Fix compiler warnings.
Diffstat (limited to 'smelt')
-rw-r--r--smelt/sdl/gfx_sdl.cpp70
-rw-r--r--smelt/sdl/makefile2
-rw-r--r--smelt/sdl/smelt_internal.hpp1
-rw-r--r--smelt/sdl/sys_sdl.cpp14
4 files changed, 76 insertions, 11 deletions
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<vbc;++i)
+ {
+ vertexArray[i].y=h-vertexArray[i].y;
+ vertexArray[i].z=-vertexArray[i].z;
+ }
+ }
+ for(int i=0;i<vbc;++i)
+ {
+ vb[i].tx*=twm;
+ vb[i].ty=(1.-vb[i].ty)*thm;
+ DWORD color=vb[i].col;
+ BYTE *col=(BYTE*)&vb[i].col;
+ BYTE a=((color>>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;i<primcnt*6;i+=3)
{
printf("idxbuf:%d\n",indexBuf[i]);
@@ -695,6 +759,7 @@ void SMELT_IMPL::batchOGL(bool endScene)
printf("#%d: ",indexBuf[i+2]);printVertex(vertexBuf[indexBuf[i+2]]);
#undef printVertex
}
+#endif
break;
}
primcnt=0;
@@ -905,7 +970,6 @@ bool SMELT_IMPL::confOGL()
pOpenGLDevice->glGenBuffersARB(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;