D3D Vertex buffers as in OpenGL ?

Started by
2 comments, last by Ysaneya 22 years, 5 months ago
Please, bear with me as i''m fluent in OpenGL but a newbie to D3D. In OpenGL, it would be possible to reuse the same texture coordinate array for 2 different TMUs. Like, say you have an array of UV coordinates defined by float *uv; then you could set up a texture matrix on TMU1 and use uv, and set up a different texture matrix on TMU2, and use the same pointer to uv. That way, you do not provide data twice. I simply would like to know if it''s possible to do that in D3D and if so, how (hints to a doc would be fine). I can still duplicate the uv once per TMU, but it doesn''t seem very efficient to me. Another thing, more or less related, is about the way vertices are stored in a vertex buffer. In OpenGL, you are not forced to using an interleaved format (that is: xyz0,uv0,xyz1,uv1,xyz2,uv2 etc.. ); you can also use a linear array of components (xyz0,xyz1,xyz2,uv0,uv1,uv2). I would also like to know if it could be done in D3D or not. In a real situation, say i have 2 pass, for example a first one to draw a diffuse texture, and a second one to blend some lightmap over it (i''m assuming i do not have access to multitexturing, but that''s just for the example). Since the vertices positions (xyz) are the same in the 2 pass, i would like to avoid duplicating them in the 2 vertex buffers... that could easily be done in OpenGL by setting up a pointer to the same array. Any help is appreciated. Y.
Advertisement
You can set multiple streams sources if you are using vertex shaders, but you cannot if you are using the fixed function pipeline. Take a look at the SetStreamSource and vertex shader declaration portions of the docs.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
You certainly can reuse a texture coordinate in multiple texture stages:

- Take a look at IDirect3DDevice8::SetTextureStageState() [set the per-stage (TMU) render states], in particular look at the SDK docs for the D3DTSS_TEXCOORDINDEX state.

- For the texture matrices, the IDirect3DDevice8::SetTransform() call is what you''re after. The D3DTS_TEXTURE0 through to D3DTS_TEXTURE7 matrices are those applied to texture coordinates.

- Finally look at the D3DTSS_TEXTURETRANSFORMFLAGS TextureStageState which define how the matrix is to be used in processing of texture coordinates for that stage (is it homogeneous, how many coordinates are passed etc).

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Oops - sorry, I read the post too quickly. To sum up...

Yes, you can reuse coordinates a la Simon''s comments, but if you are using shaders you can also mix and match streams that have different data. Say you have position data and several possible uv coordinates. You can set things up to draw data from two different streams and trade the different uv streams out as needed.

I think you might be able to use linear arrays as you''ve described if you played around enough with start indices and strides, but I''ve never tried.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

This topic is closed to new replies.

Advertisement