Graphics

Reply
Accepted Solution

program.SetAttributeValue complains about value array size

Just testing out the public SDK and trying to do something I know works in OpenGL ES 2.0:

I just need to draw a simple primitive by setting it's coordinates via attributes.

 

Creating the shader:

program = new ShaderProgram("/Application/shaders/basic.cgx");

program.SetAttributeBinding(0, "position");

 

Rendering (simplified):

float[] squareVertices = {
    x, y,           x+w, y,
    x, y+h,      x+w, y+h,
};

program.SetAttributeValue(0, squareVertices);

gl.DrawArrays(DrawMode.TriangleStrip, 0, 4);//"gl" is the GraphicsContext

 

When it reaches 'SetAttribute' it throws this exception:

System.InvalidOperationException: Value argument has wrong size

 

Why does it do this? Which size does it expect? Is it really nessecary to create a VBO just for this?

Please use plain text.

Re: program.SetAttributeValue complains about value array size

What type is the position attribute in your shader?

 

I have to admit I've never seen this usage before and I'd expect position to be a float3[] array of some sort?

 

Defining a VertexBuffer in PSS is almst identical to how you've done it here anyway (since the framework provides methods for easily contstructing and assigning them.

 

One thing to note is that the Shader Compiler does not appear to be a true OpenGL ES 2.0 compiler, it's 'similar' in many respects but seems bugged and missing certain features and semantics.

Martin Caine
Founder and Lead Programmer of Retroburn Game Studios

Twitter | LinkedIn | Facebook
Please use plain text.

Re: program.SetAttributeValue complains about value array size

Here is the shader

//Vertex
void main(	float2 in position  : POSITION,
		float2 in texCoord  : TEXCOORD0,
		float4 out vPosition : POSITION,
		float2 out texCoordinate : TEXCOORD0,
		uniform float4x4 projectionMatrix
)
{
	vPosition = mul(float4(position,1,1), projectionMatrix);
	texCoordinate = texCoord;
}
//Fragment:
void main( 
	float2 in texCoordinate   : TEXCOORD0,
	float4 out fragColor	  : COLOR,
	uniform sampler2D tex : TEXUNIT0
) { fragColor = tex2D(tex, texCoordinate); }

 

Oddly enough it looks like it converts it correctly to GLSL (lookin inside the .gfx file) (despite looking horrible):

attribute vec2 position;
attribute vec2 texCoord;
varying vec4 vPosition;
varying vec2 texCoordinate;
uniform mat4 projectionMatrix;
vec4 _r0003;
vec4 _v0003;

 // main procedure, the original name was main
void main()
{
    vec4 _vPosition;
    vec2 _texCoordinate;

    _v0003 = vec4(position.x, position.y, 1.00000000E+000, 1.00000000E+000);
    _r0003 = _v0003.x*projectionMatrix[0];
    _r0003 = _r0003 + _v0003.y*projectionMatrix[1];
    _r0003 = _r0003 + _v0003.z*projectionMatrix[2];
    _r0003 = _r0003 + _v0003.w*projectionMatrix[3];
    _vPosition = _r0003;
    _texCoordinate = texCoord.xy;
    gl_Position = _r0003;
    texCoordinate.xy = texCoord.xy;
} // main end
precision highp float;
precision highp int;
varying vec2 texCoordinate;
uniform sampler2D tex;

 // main procedure, the original name was main
void main()
{

    vec4 _fragColor;

    _fragColor = texture2D(tex, texCoordinate.xy);
    gl_FragColor = _fragColor;
} // main end

 

The method I'm using isn't very widespread but it works pretty well when you need to update the vertices manually very often. It also means that you only have to upload the vertices before drawing and not having to create an entirely new projectionMatrix before drawing.

 

Please use plain text.

Re: program.SetAttributeValue complains about value array size

You know.. I haven't even looked at the 'compiled' shader files. I had assumed they were compiled down to a lower level, not just to GLSL. I may aswell just code my shaders direct in GLSL if I can do that rather than using this intermediate step with non-standard semantics...

 

As for your problem, I've no idea if it's perhaps not supported on the devices or of it's something else causing it not to work.

Martin Caine
Founder and Lead Programmer of Retroburn Game Studios

Twitter | LinkedIn | Facebook
Please use plain text.

Re: program.SetAttributeValue complains about value array size

The .cgx files still contain the original CG shader and other information. I would keep programming them in CG (even though I prefer GLSL as well) as the PSS toolkit is designed for cross-platform compatibility. I'm quite sure there was a reason they chose CG. Probably because it is trivial to convert to HLSL on Microsoft platforms and because there are good tools for converting it to GLSL.

 

The original HLSL2GLSL converter by ATI: 

http://sourceforge.net/projects/hlsl2glsl/

 

An improved fork of ATI's tool:

https://github.com/aras-p/hlsl2glslfork

 

If you need to go the other way (GLSL to HLSL) I believe the ANGLE project from google has a library that does just that:

http://code.google.com/p/angleproject/

It translates OpenGL ES 2.0 calls to Direct3D calls and converts the shaders. Chrome and Firefox uses this on windows to get around bad OpenGL drivers as DirectX is much better supported on Windows on virtuall all windows computers.

Please use plain text.

Member

Member
jdpgxtbh
Posts: 4
Registered: ‎24-04-2012
Message 6 of 7 (244 Views)

Re: program.SetAttributeValue complains about value array size

Hi,

 

I *think* SetAttributeValue just sets the 'default' value to be used for an attribute if no vertex buffer is attached for that attribute. It can therefore only have '1' vertex value, so I'm guessing the method accepts 1...4 floats. This is sort of similar to how you could set glColor in GL, and it would affect all subsequent glVertex's.

 

If you want multiple attribute values, you'll need to use a vertex buffer. Fortunately, this is very easy with pss, eg:

 

VertexBuffer vb=new VertexBuffer( 4,VertexFormat.Float2 );

vb.SetVertices( 0,new float[]{ x,y, x+w,y, x,y+h, x+w, y+h } );

 

Please use plain text.

Re: program.SetAttributeValue complains about value array size

Looks like you are right about the vertex attributes if there is no vertex buffer attached. I wonder why this is enforced like this if my method is valid.

Please use plain text.
This widget could not be displayed.
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を一度ログアウトし、再度ログインしてください。






Recent News