citro3d/source/attribs.c

66 lines
1.7 KiB
C
Raw Permalink Normal View History

2017-02-09 04:30:25 +01:00
#include "internal.h"
2014-12-20 21:34:19 +01:00
#include <c3d/attribs.h>
void AttrInfo_Init(C3D_AttrInfo* info)
{
memset(info, 0, sizeof(*info));
info->flags[1] = 0xFFF << 16;
2014-12-20 21:34:19 +01:00
}
int AttrInfo_AddLoader(C3D_AttrInfo* info, int regId, GPU_FORMATS format, int count)
2014-12-20 21:34:19 +01:00
{
if (info->attrCount == 12) return -1;
2014-12-20 21:34:19 +01:00
int id = info->attrCount++;
if (regId < 0) regId = id;
2014-12-20 21:34:19 +01:00
if (id < 8)
info->flags[0] |= GPU_ATTRIBFMT(id, count, format);
2014-12-20 21:34:19 +01:00
else
info->flags[1] |= GPU_ATTRIBFMT(id-8, count, format);
info->flags[1] = (info->flags[1] &~ (0xF0000000 | BIT(id+16))) | (id << 28);
info->permutation |= regId << (id*4);
return id;
2014-12-20 21:34:19 +01:00
}
int AttrInfo_AddFixed(C3D_AttrInfo* info, int regId)
2014-12-20 21:34:19 +01:00
{
if (info->attrCount == 12) return -1;
int id = info->attrCount++;
if (regId < 0) regId = id;
info->flags[1] = (info->flags[1] &~ 0xF0000000) | (id << 28);
info->permutation |= regId << (id*4);
return id;
2014-12-20 21:34:19 +01:00
}
C3D_AttrInfo* C3D_GetAttrInfo(void)
{
C3D_Context* ctx = C3Di_GetContext();
if (!(ctx->flags & C3DiF_Active))
return NULL;
ctx->flags |= C3DiF_AttrInfo;
2014-12-20 21:34:19 +01:00
return &ctx->attrInfo;
}
void C3D_SetAttrInfo(C3D_AttrInfo* info)
{
C3D_Context* ctx = C3Di_GetContext();
if (!(ctx->flags & C3DiF_Active))
return;
if (info != &ctx->attrInfo)
memcpy(&ctx->attrInfo, info, sizeof(*info));
ctx->flags |= C3DiF_AttrInfo;
2014-12-20 21:34:19 +01:00
}
void C3Di_AttrInfoBind(C3D_AttrInfo* info)
{
GPUCMD_AddIncrementalWrites(GPUREG_ATTRIBBUFFERS_FORMAT_LOW, (u32*)info->flags, sizeof(info->flags)/sizeof(u32));
2015-03-05 17:56:33 +01:00
GPUCMD_AddMaskedWrite(GPUREG_VSH_INPUTBUFFER_CONFIG, 0xB, 0xA0000000 | (info->attrCount - 1));
GPUCMD_AddWrite(GPUREG_VSH_NUM_ATTR, info->attrCount - 1);
2015-03-05 17:56:33 +01:00
GPUCMD_AddIncrementalWrites(GPUREG_VSH_ATTRIBUTES_PERMUTATION_LOW, (u32*)&info->permutation, 2);
2014-12-20 21:34:19 +01:00
}