Hello, my name's rosario Corsini, i've recently decided to make my own D3D9/10/11/OPENGL graphics engine, I'm trying to make it shader based
basically use shaders to render everything so it can be nice and work with all 3 APIS (9/10/11) I'm running into a problem, see, I'm using hlsl rather then FX files and i tried to create a declaration and then set the decl and set the register/data and when i run it, i get this D3DDEBUG error:
[size="1"]Direct3D9: (ERROR) :Vertex stride in stream 0 is less than in the declaration
First-chance exception at 0x75d8b727 in IApp.exe: Microsoft C++ exception: long at memory location 0x005bf980..
Direct3D9: (ERROR) :DrawPrimitive failed.
now here is my code for setting/drawing the quad
ScreenQuad::ScreenQuad()
{
pGPU9 = new IHighLevelGpu9();
pGPU9->createProgram("Screen","main",VSP_VS_2_0,"Screen_Pixel",PSP_2_0);
pGPU9->loadProgram("Screen_Quad.hlsl");
}
Your vertex declaration doesn't seem to match the layout of your [color="#660066"][font="CourierNew, monospace"]VertexPCT[/font] structure.
Your vertex declaration is describing each property as being made of float types, whereas your [color="#660066"][font="CourierNew, monospace"]VertexPCT[/font] structure seems to use bytes (not floats) for it's colour values. Furthermore, your Texcoord and Colour properties are overlapping, like so (i.e. with everything made of floats, the texcoords should have an offset of 28, not 24):struct
{
float x, y, z;
float r, g, b;
union { float a; float u; };
float v;
}I can't be sure without seeing your [color="#660066"][font="CourierNew, monospace"]VertexPCT[/font] structure , but I'm guessing your declaration should look like D3DVERTEXELEMENT9 mVertexElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END(),
};
Your vertex declaration doesn't seem to match the layout of your [color="#660066"][font="CourierNew, monospace"]VertexPCT[/font] structure.
Your vertex declaration is describing each property as being made of float types, whereas your [color="#660066"][font="CourierNew, monospace"]VertexPCT[/font] structure seems to use bytes (not floats) for it's colour values. Furthermore, your Texcoord and Colour properties are overlapping, like so (i.e. with everything made of floats, the texcoords should have an offset of 28, not 24):struct
{
float x, y, z;
float r, g, b;
union { float a; float u; };
float v;
}I can't be sure without seeing your [color="#660066"][font="CourierNew, monospace"]VertexPCT[/font] structure , but I'm guessing your declaration should look like D3DVERTEXELEMENT9 mVertexElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END(),
};
class VertexPCT : public VertexPosColor
{
public:
VertexPCT(float X, float Y, float Z,
DWORD color, float U, float V)
: VertexPosColor(X,Y,Z,color),fU(U),
fV(V)
{
I actually got it to work, thanks, you got any advice so that this will never happen again? like how can i tell how much to offset when declaring the vertex elements? I want to learn as much as possible so it be easy to set this up in the future, thank you
That doesn't help because it doesn't show the entire data definition (it only shows [font="Lucida Console"]u[/font] and [font="Lucida Console"]v[/font]). There could still be anything in [font="Lucida Console"]VertexPosColor[/font] for all we know.
any advice so that this will never happen again? like how can i tell how much to offset when declaring the vertex elements?
If you want to use structs to represent your vertices (and be able to map vertex buffers to arrays of those structs), you should first be familliar with your compiler's packing rules.
You're basically guessing at the byte-offset of each member variable inside the structure.struct VertexPCT
{
float x;//first member, offset = 0
float y;
float z;
DWORD color; // sizeof(float) == 4. There's 3 floats before this. So the offset is 3x4 == 12
float u;//size of DWORD is also 4. There's 3 floats and a DWORD before this, so the offset is 12+4 == 16
float v;
};You can check if you're right by checking your guess against the compiler's answer:VertexPCT test;
char* base = (char*)&test;
assert( &test.x == (float*)(base + 0) );
assert( &test.y == (float*)(base + 4) );
assert( &test.z == (float*)(base + 8) );
assert( &test.color == (DWORD*)(base + 12) );
assert( &test.u == (float*)(base + 16) );
assert( &test.v == (float*)(base + 20) );
[quote name='Enerjak' timestamp='1303878939' post='4803395']
do you see anything wrong with this? because the compiler is giving me errors.
looks ok to me....let me know what you think
Your error messages are cut off mid-sentence...
[/quote]
Usage: fxc <options> <files>[/quote]I dunno if this is your problem, but you're supposed to put your usage switches before the filename.
i.e.
[font="Courier New"]fxc /T ps_3_0 blah.fx[/font]
instead of:
[font="Courier New"]fxc blah.fx /T ps_3_0[/font]
Also, if you're trying to compile that shader you posted earlier, you'll want the vs_3_0 profile, as it's a vertex shader.
I dunno if this is your problem, but you're supposed to put your usage switches before the filename.
i.e.
[font="Courier New"]fxc /T ps_3_0 blah.fx[/font]
instead of:
[font="Courier New"]fxc blah.fx /T ps_3_0[/font]
Also, if you're trying to compile that shader you posted earlier, you'll want the vs_3_0 profile, as it's a vertex shader.
[/quote]
Ok, that compiled but this was my original intention:
to have both in one hlsl file now when i compile to vs_3_0 how do i know that the PS also went to 3_0? i assume it got both, but it only shows one profile.