From e0dfa431e62a261decb4e3d29f1483c440db8278 Mon Sep 17 00:00:00 2001 From: Laurent Carlier Date: Fri, 21 Aug 2009 21:59:47 +0000 Subject: [PATCH] [GB.OPENGL] * BUG: Fix Gl.RenderMode() return values. It can return an Integer[][] (with Gl.GL_SELECT) or a Float[] (with Gl.GL_FEEDBACK) git-svn-id: svn://localhost/gambas/trunk@2257 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.opengl/src/GL.c | 2 +- gb.opengl/src/GLselectFeedback.c | 34 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gb.opengl/src/GL.c b/gb.opengl/src/GL.c index 8314ac289..a7833cdf0 100644 --- a/gb.opengl/src/GL.c +++ b/gb.opengl/src/GL.c @@ -253,7 +253,7 @@ GB_DESC Cgl[] = GB_STATIC_METHOD("PassThrough", NULL, GLPASSTHROUGH, "(Token)f"), GB_STATIC_METHOD("PopName", NULL, GLPOPNAME, NULL), GB_STATIC_METHOD("PushName", NULL, GLPUSHNAME, "(Name)i"), - GB_STATIC_METHOD("RenderMode", "v", GLRENDERMODE, "(Mode)i"), + GB_STATIC_METHOD("RenderMode", "Object[];", GLRENDERMODE, "(Mode)i"), GB_STATIC_METHOD("SelectBuffer", NULL, GLSELECTBUFFER, NULL), /* glGetxxxx calls - see GLinfo.h/c */ diff --git a/gb.opengl/src/GLselectFeedback.c b/gb.opengl/src/GLselectFeedback.c index 49c866820..48831ee26 100644 --- a/gb.opengl/src/GLselectFeedback.c +++ b/gb.opengl/src/GLselectFeedback.c @@ -76,7 +76,7 @@ END_METHOD BEGIN_METHOD(GLRENDERMODE, GB_INTEGER Mode) static GLuint oldrendermode = GL_RENDER; /* default render mode */ - GLint mode = VARG(Mode); + GLint result, mode = VARG(Mode); /* invalid mode or same render mode: return null object, and let propagate an opengl error */ @@ -87,16 +87,16 @@ BEGIN_METHOD(GLRENDERMODE, GB_INTEGER Mode) return; } - mode = glRenderMode(mode); - - if (!mode) + result = glRenderMode(mode); + + if (!result) { GB.ReturnNull(); oldrendermode = mode; return; } - if (mode < 0) + if (result < 0) { GB.Error ("Gl.RenderMode, buffer is too small !"); return; @@ -108,25 +108,27 @@ BEGIN_METHOD(GLRENDERMODE, GB_INTEGER Mode) GLuint *hitbuffer = selectbuffer; int idxhit, idxname; - GB.Array.New(&hitArray, GB_T_OBJECT, mode); + //GB.New(&hitArray, GB_T_OBJECT, result); + GB.New(POINTER(&hitArray), GB.FindClass("Integer[][]"), NULL, NULL); - for (idxhit=0; idxhit < mode; idxhit++) + for (idxhit=0; idxhit < result; idxhit++) { GB_ARRAY childhitArray; - int names = (*hitbuffer) + 3; - GB.Array.New(&childhitArray, GB_T_INTEGER, names); + int names = *hitbuffer; + GB.Array.New(&childhitArray, GB_T_INTEGER, names + 3); *((GLuint *)GB.Array.Get(childhitArray, 0)) = *hitbuffer++; // maxname *((GLuint *)GB.Array.Get(childhitArray, 1)) = *hitbuffer++; // zmin *((GLuint *)GB.Array.Get(childhitArray, 2)) = *hitbuffer++; // zmax - for (idxname=3; idxname < names; idxname++) - *((GLuint *)GB.Array.Get(childhitArray, 2)) = *hitbuffer++; // names + for (idxname=0; idxname < names; idxname++) + *((GLuint *)GB.Array.Get(childhitArray, 3 + idxname)) = *hitbuffer++; // names - *((GB_ARRAY *)GB.Array.Get(hitArray, idxhit)) = childhitArray; + GB.Ref(childhitArray); + *((GB_ARRAY *)GB.Array.Add(hitArray)) = childhitArray; } - GB.ReturnObject(&hitArray); + GB.ReturnObject(hitArray); return; } @@ -136,12 +138,12 @@ BEGIN_METHOD(GLRENDERMODE, GB_INTEGER Mode) GLfloat *resultbuffer = feedbuffer; int idxfeed; - GB.Array.New(&feedArray, GB_T_FLOAT, mode); + GB.Array.New(&feedArray, GB_T_FLOAT, result); - for (idxfeed=0; idxfeed < mode; idxfeed++) + for (idxfeed=0; idxfeed < result; idxfeed++) *((GLfloat *)GB.Array.Get(feedArray, idxfeed)) = *resultbuffer++; - GB.ReturnObject(&feedArray); + GB.ReturnObject(feedArray); return; }