Skip to content

Instantly share code, notes, and snippets.

@Cruel
Created July 5, 2015 03:33
Show Gist options
  • Save Cruel/542f70841d4109510abc to your computer and use it in GitHub Desktop.
Save Cruel/542f70841d4109510abc to your computer and use it in GitHub Desktop.
static int update_attrib_format(struct gl_vertex_array_object* vao)
{
int x, index = 0;
struct gl_vertex_attrib_array* attrib;
for (x = 0; x < VERT_ATTRIB_MAX; ++x) {
attrib = &vao->VertexAttrib[x];
if (attrib->Enabled) {
vao->AttributeFormats |= GPU_ATTRIBFMT(index, attrib->Size, attrib->Type);
// vao->AttributeFormats |= ((attrib->Size-1 << 2) | attrib->Type) << (index * 4);
vao->AttributePermutation |= index << (index * 4);
vao->BufferOffsets[index] = attrib->Ptr - __linear_heap;
vao->BufferPermutations[index] = index;// << (index * 4);
index++;
}
}
return index;
}
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
{
GET_CURRENT_CONTEXT(ctx);
update_context(ctx);
int i = 0;
u8 sizeTable[0xC];
// uint64_t attributeFormats = 0;
uint16_t attributeMask = 0xFF8; //0xFFF << 3;
// uint64_t attributePermutation = 0;
// uint32_t bufferOffsets[1];
// uint64_t bufferPermutations[1];
// uint8_t bufferNumAttributes[1];
struct gl_vertex_array_object* vao = ctx->Array.VAO;
unsigned char attrib_count = update_attrib_format(vao);
printf(" count:%d ", attrib_count);
int numBuffers = 3; // hardcode buffer count for testing
u32 param[28];
memset(param, 0x00, 28*4);
param[0x0]=(osConvertVirtToPhys(__linear_heap))>>3;
param[0x1]=vao->AttributeFormats&0xFFFFFFFF;
param[0x2]=((attrib_count-1)<<28)|((attributeMask&0xFFF)<<16)|((vao->AttributeFormats>>32)&0xFFFF);
int j;
u8 bufferNumAttributes[] = {1, 1, 1};
const u8 GPU_FORMATSIZE[4]={1,1,2,4};
for(i=0;i<attrib_count;i++)
{
u8 v=vao->AttributeFormats&0xF;
sizeTable[i]=GPU_FORMATSIZE[v&3]*((v>>2)+1);
vao->AttributeFormats>>=4;
}
for(i=0;i<numBuffers;i++)
{
u16 stride=20;
param[3*(i+1)+0]=vao->BufferOffsets[i];
param[3*(i+1)+1]=vao->BufferPermutations[i]&0xFFFFFFFF;
// for(j=0;j<bufferNumAttributes[i];j++)stride+=sizeTable[(vao->BufferPermutations[i]>>(4*j))&0xF];
printf("stride%d:%d", i, stride);
param[3*(i+1)+2]=(bufferNumAttributes[i]<<28)|((stride&0xFFF)<<16)|((vao->BufferPermutations[i]>>32)&0xFFFF);
}
GPUCMD_AddIncrementalWrites(GPUREG_ATTRIBBUFFERS_LOC, param, 28);
GPUCMD_AddMaskedWrite(GPUREG_VSH_INPUTBUFFER_CONFIG, 0xB, 0xA0000000|(attrib_count-1));
GPUCMD_AddWrite(GPUREG_0242, (attrib_count-1));
GPUCMD_AddIncrementalWrites(GPUREG_VSH_ATTRIBUTES_PERMUTATION_LOW, ((u32[]){vao->AttributePermutation&0xFFFFFFFF, (vao->AttributePermutation>>32)&0xFFFF}), 2);
GPU_DrawArray((GPU_Primitive_t)mode, count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment