I am trying to debug why texture fill is not working in starling graphics extension.
I made sure the texture is supplied and that TextureVertexColorFragmentShader is used.
Shader looks like this:
var agal:String =
"tex ft1, v1, fs0 <2d, repeat, linear> \n" +
"mul ft2, v0, fc0 \n" +
"mul oc, ft1, ft2"
compileAGAL( Context3DProgramType.FRAGMENT, agal );
This is how render method looks like:
override public function render(renderSupport:Painter):void
{
validateNow();
if(indices == null || indices.length < 3)
{
return;
}
context = Starling.context;
renderSupport.excludeFromCache(this);
if(isInvalid || uvsInvalid)
{
// Upload vertex/index buffers.
numVertices = vertices.length / VERTEX_STRIDE;
vertexBuffer = context.createVertexBuffer(numVertices, VERTEX_STRIDE);
vertexBuffer.uploadFromVector(vertices, 0, numVertices)
indexBuffer = context.createIndexBuffer(indices.length);
indexBuffer.uploadFromVector(indices, 0, indices.length);
isInvalid = uvsInvalid = false;
}
// always call this method when you write custom rendering code!
// it causes all previously batched quads/images to render.
renderSupport.finishMeshBatch();
if (context == null) throw new MissingContextError();
blendFactors = MyBlendMode.getBlendFactors(
blendMode == BlendMode.AUTO ? renderSupport.state.blendMode : this.blendMode,
true
);
context.setBlendFactors(blendFactors[0], blendFactors[1]);
_material.drawTriangles(
context,
renderSupport.state.mvpMatrix3D,
vertexBuffer,
indexBuffer,
_parent.alpha
);
context.setTextureAt(0, null);
context.setTextureAt(1, null);
context.setVertexBufferAt(0, null);
context.setVertexBufferAt(1, null);
context.setVertexBufferAt(2, null);
context.setBlendFactors(
Context3DBlendFactor.ONE,
Context3DBlendFactor.ZERO
);
context.setBlendFactors(
Context3DBlendFactor.ONE,
Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA
);
}
This is how material drawTriangles method looks like:
public function drawTriangles(context:Context3D,
matrix:Matrix3D,
vertexBuffer:VertexBuffer3D,
indexBuffer:IndexBuffer3D,
alpha:Number = 1,
numTriangles:int = -1):void
{
context.setVertexBufferAt(0, vertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
context.setVertexBufferAt(1, vertexBuffer, 3, Context3DVertexBufferFormat.FLOAT_4);
context.setVertexBufferAt(2, vertexBuffer, 7, Context3DVertexBufferFormat.FLOAT_2);
if(program == null && _vertexShader && _fragmentShader)
{
program = Program3DCache.getProgram3D(context, _vertexShader, _fragmentShader);
}
context.setProgram(program);
/**
*
* FOR TEXTURE FILLS
*/
textureLen = _textures.length;
if(textureLen > 0)
{
for(i = 0; i < textureLen; i++)
{
context.setTextureAt(i, _textures[i].base);
}
}
/***/
context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, matrix, true);
_vertexShader.setConstants(context, 4);
// Multiply display obect's alpha by material alpha.
finalAlpha = _alpha * alpha;
colorVector[0] = ((_color >> 16) / 255) * finalAlpha;
colorVector[1] = (((_color & 0x00FF00) >> 8) / 255) * finalAlpha;
colorVector[2] = ((_color & 0x0000FF) / 255) * finalAlpha;
colorVector[3] = finalAlpha;
context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, colorVector);
_fragmentShader.setConstants(context, 1);
context.drawTriangles(indexBuffer, 0, numTriangles);
}
}
It looks like this is implemented but maybe it is not. I have no idea how process of uploading vertices and uv vertices should look like. Does it look like in this method above if uv vertices are uploaded. I don't know where to start to look and what to look.
What checks can I do to make sure if all processes are used to enable using texture while drawing?