之前一直不理解为什么osg::impostor里面的impostorSprite可以直接设置impostorSprite->getCoords()来设置geometry的四个边角,其实是因为这个函数
void ImpostorSprite::drawImplementation(osg::RenderInfo& renderInfo) const,它重写了geometry的这个函数,里面直接设置了
void ImpostorSprite::drawImplementation(osg::RenderInfo& renderInfo) const { osg::GLBeginEndAdapter& gl = (renderInfo.getState()->getGLBeginEndAdapter()); // when the tex env is set to REPLACE, and the // texture is set up correctly the color has no effect. gl.Color4fv(_color.ptr()); gl.Begin(GL_QUADS); gl.TexCoord2fv((GLfloat *)&_texcoords[0]); gl.Vertex3fv((GLfloat *)&_coords[0]); gl.TexCoord2fv((GLfloat *)&_texcoords[1]); gl.Vertex3fv((GLfloat *)&_coords[1]); gl.TexCoord2fv((GLfloat *)&_texcoords[2]); gl.Vertex3fv((GLfloat *)&_coords[2]); gl.TexCoord2fv((GLfloat *)&_texcoords[3]); gl.Vertex3fv((GLfloat *)&_coords[3]); gl.End(); }
所以可以impostorSprite->getCoords()直接设置,作用到了其成员变量,而不是通过addDrawArrays(new .....)这样来设置geometry的四个边角