我不知道如何为 sizeof() 和 void 指针取消引用该指针
我不知道如何取消引用这个指针...
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, 1, 2, 3,
4, 5, 7, 5, 6, 7,
8, 9, 11, 9, 10, 11,
12, 13, 15, 13, 14, 15,
16, 17, 19, 17, 18, 19,
20, 21, 23, 21, 22, 23,
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
};
//-------------------------
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, 0, sizeof(test1Data), test1Data);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(test1Data), 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, NULL, GL_STATIC_DRAW);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData3D), (void*)0);
glNormalPointer(GL_FLOAT, sizeof(VertexData3D), (void*)12);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(theInsert->insertName->tripsName), theInsert->insertName->tripsName);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(test1Trips), test1Trips);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test1Trips), sizeof(test2Trips), shapetest2->tripsName);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 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)
如果我注释掉有问题的行,并取消注释上面的行,它正在工作,但我需要这种间接,(实际上我需要另一个级别的间接,你可以在另一个注释掉的行中看到)但是如果我能弄清楚如何取消引用该行,我应该能够为另一个级别做到这一点间接?)
I could not figure out how to dereference this pointer...
sizeof(shapetest2->tripsName) in this line below, it is obviously not going to work because it is a pointer, i could not figure out how to dereference it? (is it easy? or is it a couple steps?, i've tried several things, but could not get close) I am not an experience enough coder to figure this particular circumstance out.
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(shapetest2->tripsName), shapetest2->tripsName);
here is the setup code. (i am experimenting with a VOB in openGL ES 1.5, so if it looks odd, that is why) if i forgot some important setup or definitions, or code, let me know and i'll include it.
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, 1, 2, 3,
4, 5, 7, 5, 6, 7,
8, 9, 11, 9, 10, 11,
12, 13, 15, 13, 14, 15,
16, 17, 19, 17, 18, 19,
20, 21, 23, 21, 22, 23,
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
};
//-------------------------
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, 0, sizeof(test1Data), test1Data);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(test1Data), 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, NULL, GL_STATIC_DRAW);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData3D), (void*)0);
glNormalPointer(GL_FLOAT, sizeof(VertexData3D), (void*)12);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(theInsert->insertName->tripsName), theInsert->insertName->tripsName);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(test1Trips), test1Trips);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test1Trips), sizeof(test2Trips), shapetest2->tripsName);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 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 is a handle (pointer to pointer) of the shapetest2, so you can substitute shapetest2 if you see "theInsert->insertName")
if i comment out the offending line, and uncomment the line above, it is working, but i need this indirection, (and actually i need another level of indirection that you can see in another commented out line) but if i can figure out how to dereference this line, i should be able to do it for another level of indirection?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sizeof
是编译时常量,适用于您提供的确切类型。void*
的sizeof
只是您机器上指针的大小(可能是 4/8 字节)。只需将大小与其他数据一起存储即可。sizeof
is compile-time constant that works on exact type you provide.sizeof
ofvoid*
is just a size of pointer on your machine (likely 4/8 bytes). Just store size along with other data.