Graphics

Reply

DrawMode.Triangles not taking Indices

Hi all,

 

I'm trying to batch my draw calls for my 2D game into fewer, larger calls to optimise my code.

 

I'm running into an issue where the indices I pass in my call to SetIndices seem to be being ignored.  Has anyone else experienced this?  Is there a workaround?  If any further information is required please let me know.

 

Steve

Please use plain text.

Re: DrawMode.Triangles not taking Indices

Hi @MingooX

Are you able to post us a snippet of the code that you are using to give us some more context?

Thanks, James.
PlayStation®Mobile Dev Team
Please use plain text.

Re: DrawMode.Triangles not taking Indices

[ Edited ]
Hi James, Thanks for coming back to me. Below is my SpriteBatch class. I'm writing a drop-in replacement library that will allow me to almost instantly convert my existing games from xna to pss. The InternalTexture property of my Texture2D is just a normal pss texture. I get the top right half of each triangle, just not the bottom left half. I have had to post it to a notepadding site as the forum did not like my code: http://notepub.com/#fb=&note=355711 Let me know if any more information is required. Kind Regards, Steve
Please use plain text.

Re: DrawMode.Triangles not taking Indices

Hello, MingooX,

 

Have you tried using a constructor with indexCount param, such as:

 

_vertexBuffer = new VertexBuffer(_maxVertexCount,

_maxIndexCount, 
VertexFormat.Float2, // Position
VertexFormat.Float2, // Tex Coord
VertexFormat.Float4// Color
);
VertexBuffer's contstructed without indexCount seem to ignore SetIndices method.
(They should raise errors, I think...)
I didn't surveyed the rest of your code, but this may be one of the reasons that you cannot get the right result.
Please use plain text.

Re: DrawMode.Triangles not taking Indices

Hi Nagata, That worked great thanks. I used your change in conjunction with _vertexBuffer.SetIndices (_indices, 0, 0, _indexCount); and it started behaving as I expected. My next question while I have you is are there any built in methods for translating, scaling and rotating a vector by a matrix? I need to manipulate the four vertices of my rectangles on the cpu before passing them to the gpu. Thanks, Steve
Please use plain text.

Re: DrawMode.Triangles not taking Indices

As for now, I cannot find any methods that manipulate vectors stored in a float[] .

 

We can write such methods easily but that sort of methods should be standardized,

so that we can expect hardware acceleration.

 

As all ARM processors in PS Certified devices have SIMD vector processing instructions...

Please use plain text.

Re: DrawMode.Triangles not taking Indices

Hi Guys,

 

    Actually, you can declare the float arrays that used to pass in for vertexbuffer.SetVertices as Vector3s.

 

 static VertexBuffer CreateQuad()
    {
        VertexBuffer vertexbuffer = new VertexBuffer( 4,
                                                      6,
                                                      VertexFormat.Float3,
                                                      VertexFormat.Float2 );

        // vertexbuffer
		
		//Vector3 positions[4];
		Vector3[] positions;
		positions = new Vector3[4];
		
		positions[0].X = -1.0f;
		positions[0].Y = -1.0f;
		positions[0].Z = 0.0f;
			
		positions[1].X = 1.0f;
		positions[1].Y = -1.0f;
		positions[1].Z = 0.0f;
			
		positions[2].X = 2.0f;
		positions[2].Y = 1.0f;
		positions[2].Z = 0.0f;
			
		positions[3].X = -1.0f;
		positions[3].Y = 1.0f;
		positions[3].Z = 0.0f;
			
		/*	
		float[] positions = {
            // front
			-1.0f,  -1.0f, 0.0f, // 0
			 1.0f,  -1.0f, 0.0f, // 1
			 1.0f,   1.0f, 0.0f, // 2
			-1.0f,   1.0f, 0.0f, // 3
            
		};
		*/
		float[] texcoords = {
            // front
			0.0f, 1.0f, // 0
			1.0f, 1.0f, // 1
            1.0f, 0.0f, // 2
            0.0f, 0.0f, // 3
		};

        ushort[] indices = { 
            // front
            0, 1, 2,
            0, 2, 3
        };


		vertexbuffer.SetVertices( 0, positions );
		vertexbuffer.SetVertices( 1, texcoords );
        vertexbuffer.SetIndices( indices );
        return vertexbuffer;
    }

 

for math purpos, then you can use Matrix4 class to perform rotation and such on these vector3s.

 


nagata_kobo wrote:

As for now, I cannot find any methods that manipulate vectors stored in a float[] .

 

We can write such methods easily but that sort of methods should be standardized,

so that we can expect hardware acceleration.

 

As all ARM processors in PS Certified devices have SIMD vector processing instructions...


As it is in C#, I would assume that by using the built in Matrix4/Vector3/Vecotr4 math operations , it will try to translated into SIMD instructions if possible after compile to take HW advantage.

 

Thanks,

Jay

 

 

 

Please use plain text.

Re: DrawMode.Triangles not taking Indices

Hello, Jay,

 

Thank you for your suggestions.

Frankly, I could not have found that VertexBuffer's SetIndices methods accept Vector2/3/4 arrays till now...

 

The SDK Documents should refer to this.

Please use plain text.

Re: DrawMode.Triangles not taking Indices


nagata_kobo wrote:

Hello, Jay,

 

Thank you for your suggestions.

Frankly, I could not have found that VertexBuffer's SetIndices methods accept Vector2/3/4 arrays till now...

 

The SDK Documents should refer to this.



Agree, I will reflect this to the internal team.

 

Cheers,

Jay

Please use plain text.

Member

Member
jdpgxtbh
Posts: 4
Registered: ‎24-04-2012
Message 10 of 13 (274 Views)

Re: DrawMode.Triangles not taking Indices

Just thought I'd mention I had a similar issue to this on Vita HW.

 

I was initially using 2 vertex buffers - 1 with pos/color, and the other with uv/tri-index.

 

Setup was like this:

 

[code]

//pos/color buffer...

_vertBuf=new VertexBuffer( MAX_VERTS,VertexFormat.Float2,VertexFormat.UByte4N );

//uv/index buffer
_quadBuf=new VertexBuffer( MAX_QUADS*4,MAX_QUADS*6,VertexFormat.Float2 );
ushort[] idxs=new ushort[MAX_QUADS*6];
for( int i=0;i<MAX_QUADS;++i ){
idxs[i*6+0]=(ushort)(i*4);
idxs[i*6+1]=(ushort)(i*4+1);
idxs[i*6+2]=(ushort)(i*4+2);
idxs[i*6+3]=(ushort)(i*4);
idxs[i*6+4]=(ushort)(i*4+2);
idxs[i*6+5]=(ushort)(i*4+3);
}
_quadBuf.SetIndices( idxs );

 

_gc.SetVertexBuffer( 0,_vertBuf );

_gc.SetVertexBuffer( 1,_quadBuf );

[/code]

 

According to my reading of the docs, this should work - and it did on the emulator but not on the Vita. At a guess, it looked like the indices were being completely ignored on the Vita.

 

Moving to a single vertex/index buffer fixed it.

 

 

 

Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。