如何从C函数参数转换为基础协议期望的参数?
我正在尝试在协议级别上实现glTexImage2D。
glxproto.pdf描述了这样的参数:
TexImage2D
2 56+n+p rendering command length
2 110 rendering command opcode
1 BOOL swapbytes
1 BOOL lsbfirst
2 unused
4 CARD32 rowlength
4 CARD32 skiprows
4 CARD32 skippixels
4 CARD32 alignment
4 ENUM target
4 INT32 level
4 INT32 components
4 INT32 width
4 INT32 height
4 INT32 border
4 ENUM format
4 ENUM type
n LISTofBYTE image
p unused,p=pad(n)
现在OpenGL官方文档http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml对此描述如下:
void glTexImage2D(GLenum target, GLint level,
GLint internalFormat, GLsizei width,
GLsizei height, GLint border, GLenum format,
GLenum type, const GLvoid * data);
Parameters:
target
Specifies the target texture.
Must be GL_TEXTURE_2D, GL_PROXY_TEXTURE_2D,
GL_TEXTURE_1D_ARRAY, GL_PROXY_TEXTURE_1D_ARRAY,
GL_TEXTURE_RECTANGLE, GL_PROXY_TEXTURE_RECTANGLE,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, or
GL_PROXY_TEXTURE_CUBE_MAP.
level
Specifies the level-of-detail number.
Level 0 is the base image level.
Level n is the nth mipmap reduction image.
If target is GL_TEXTURE_RECTANGLE or
GL_PROXY_TEXTURE_RECTANGLE, level must be 0.
internalFormat
Specifies the number of color components in the texture.
Must be one of base internal formats given in Table 1,
one of the sized internal formats given in Table 2, or one
of the compressed internal formats given in Table 3, below.
width
Specifies the width of the texture image.
All implementations support texture images that are at least 1024 texels
wide.
height
Specifies the height of the texture image, or the number of layers in a texture
array, in the case of the GL_TEXTURE_1D_ARRAY and
GL_PROXY_TEXTURE_1D_ARRAY targets.
All implementations support 2D texture images that are at least 1024 texels
high, and texture arrays that are at least 256 layers deep.
border
This value must be 0.
format
Specifies the format of the pixel data.
The following symbolic values are accepted:
GL_RED,
GL_RG,
GL_RGB,
GL_BGR,
GL_RGBA,
GL_BGRA,
GL_RED_INTEGER,
GL_RG_INTEGER,
GL_RGB_INTEGER,
GL_BGR_INTEGER,
GL_RGBA_INTEGER,
GL_BGRA_INTEGER,
GL_STENCIL_INDEX,
GL_DEPTH_COMPONENT,
GL_DEPTH_STENCIL.
type
Specifies the data type of the pixel data.
The following symbolic values are accepted:
GL_UNSIGNED_BYTE,
GL_BYTE,
GL_UNSIGNED_SHORT,
GL_SHORT,
GL_UNSIGNED_INT,
GL_INT,
GL_FLOAT,
GL_UNSIGNED_BYTE_3_3_2,
GL_UNSIGNED_BYTE_2_3_3_REV,
GL_UNSIGNED_SHORT_5_6_5,
GL_UNSIGNED_SHORT_5_6_5_REV,
GL_UNSIGNED_SHORT_4_4_4_4,
GL_UNSIGNED_SHORT_4_4_4_4_REV,
GL_UNSIGNED_SHORT_5_5_5_1,
GL_UNSIGNED_SHORT_1_5_5_5_REV,
GL_UNSIGNED_INT_8_8_8_8,
GL_UNSIGNED_INT_8_8_8_8_REV,
GL_UNSIGNED_INT_10_10_10_2, and
GL_UNSIGNED_INT_2_10_10_10_REV.
data
Specifies a pointer to the image data in memory.
问题在于它们是不同的!
数据,边框,宽度,高度,级别都可以,它们相同并说明。
swapbytes,lsbfirst,skirows,skippixels,alignment,rowlength,组件-它们是什么?
internalFormat去哪里?
我试图找到某人的实现,但是没有运气。我尝试了XCB源,Mesa源,Node.js-x11。我无法找到正确的路线。
您是否认真尝试直接通过GLX协议进行接口?这似乎荒唐复杂。您有这样做的理由吗?
当然,命令参数和协议参数是不同的-GLX包含有线协议,除了您实际传递给基础GL API命令的参数外,它还必须将客户端状态(例如像素存储)发送到服务器。要实现GL命令-> GLX协议,您确实需要至少为客户端状态实现一个状态机。
由于Node.js-x11的作者表示有兴趣不实现像素存储状态跟踪,因此我提供了一个表格,其中包含您自己实现此功能所需的所有参数的默认值。
pname Type Initial Value Valid Range
-------------------------------------------------------------------
GL_UNPACK_SWAP_BYTES boolean false true or false
GL_UNPACK_LSB_FIRST boolean false true or false
GL_UNPACK_ROW_LENGTH integer 0 [0,oo)
GL_UNPACK_SKIP_ROWS integer 0 [0,oo)
GL_UNPACK_SKIP_PIXELS integer 0 [0,oo)
GL_UNPACK_ALIGNMENT integer 4 1, 2, 4, or 8
您可以更改API绑定以将这些参数包括在内(非常混乱),也可以始终假定它们是默认参数。但是,如果glTexImage2D (...)
没有此状态信息,则无法通过GLX实施。
与基本应用程序的GLX服务器通信时,不需要跟踪很多客户端状态,但是如果需要纹理,像素存储绝对是其中之一。大多数其他状态是服务器端的状态,其中包括您可以使用glPushAttrib (...)
和进行保存/恢复的任何状态glPopAttrib (...)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句