问题描述
|
我不知道如何取消引用此指针...
在下面这行中的sizeof(shapetest2-> tripsName),显然是行不通的,因为它是一个指针,我不知道如何取消引用它? (这很容易吗?还是只是几个步骤?,我已经尝试了好几件事,但是无法接近)我不是一个经验丰富的编码人员,无法弄清这种特殊情况。
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,sizeof(shapetest2-> tripsName),shapetest2-> tripsName);
这是设置代码。 (我正在openGL ES 1.5中试用VOB,因此,如果看起来很奇怪,这就是原因)如果我忘记了一些重要的设置或定义或代码,请告诉我并包括在内。
GLsizeiptr dataSize;
GLsizeiptr indexSize;
typedef struct shapeBase {
void *stripsName[maxStrips];
void *tripsName;
void *fansName;
int totStrips;
int stripsNum[maxStrips];
int tripsNum;
int totFans;
int fansBgn[maxStrips];
int fansNum[maxStrips];
void *dataname;
void *listofInserts;
Vertex3D center;
Vertex3D radius;
int damageMax;
float weight;
gluint bufferName;
gluint indexName;
} shapeBase;
static const glushort test2Trips[] =
{
0,1,3,2,4,5,7,6,8,9,11,10,12,13,15,14,16,17,19,18,20,21,23,22,24,25,27,26,28,29,31,30,32,33,35,34,36,37,39,38,40,41,43,42,44,45,47,46,};
//-------------------------
static inline void shapetest2Setup(void)
{
shapetest2 = malloc(sizeof(shapeBase));
shapetest2->stripsName[1] = NULL;
shapetest2->tripsName = &test2Trips;
shapetest2->fansName = NULL;
shapetest2->dataname = &test2Data;
shapetest2->totStrips = 0;
shapetest2->stripsNum[1] = 0;
shapetest2->tripsNum = 72;
shapetest2->totFans = 0;
shapetest2->listofInserts = NULL;
shapetest2->center = Vertex3DMake( 0.000000,-0.000000,2.000000 );
shapetest2->radius = Vertex3DMake( 1.000000,1.000000,2.000000 );
dataSize = sizeof(test1Data) + sizeof(test2Data);
glGenBuffers(1,&mainBuffer);
glBindBuffer(GL_ARRAY_BUFFER,mainBuffer);
glBufferData(GL_ARRAY_BUFFER,dataSize,NULL,GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,sizeof(test1Data),test1Data);
glBufferSubData(GL_ARRAY_BUFFER,sizeof(test2Data),test2Data);
// glGenBuffers(1,&shapetest2->indexName);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,shapetest2->indexName);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(test2Trips),test2Trips,GL_STATIC_DRAW);
indexSize = sizeof(test1Trips) + sizeof(test2Trips);
glGenBuffers(1,&mainIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mainIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,indexSize,GL_STATIC_DRAW);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBindBuffer(GL_ARRAY_BUFFER,mainBuffer);
glVertexPointer(3,GL_FLOAT,sizeof(VertexData3D),(void*)0);
glnormalPointer(GL_FLOAT,(void*)12);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mainIndex);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,sizeof(theInsert->insertName->tripsName),theInsert->insertName->tripsName);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,sizeof(test1Trips),test1Trips);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,shapetest2->tripsName);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,sizeof(shapetest2->tripsName),shapetest2->tripsName);
glDrawElements(GL_TRIANGLES,theInsert->insertName->tripsNum,GL_UNSIGNED_SHORT,(void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
polys += theInsert->insertName->tripsNum;
}
(theInsert是shapetest2的句柄(指向指针的指针,因此,如果看到\“ theInsert-> insertName \”,则可以替换shapetest2))
如果我注释掉有问题的行,并取消注释上面的行,它正在工作,但是我需要这种间接访问(实际上,我需要另一种级别的间接访问,可以在另一条注释掉的行中看到),但是如果我能弄清楚取消引用此行,我应该能够将它用于另一个间接级别?)
解决方法
sizeof
是编译时常量,可在您提供的确切类型上使用。 void*
中的sizeof
只是计算机上指针的大小(可能是4/8字节)。只需存储大小以及其他数据即可。