Per vertex colors

FossilOrigin-Name: 3632a7239a1926291c9162ba892d2315038a178a31652618df991c0ee549b5b5
This commit is contained in:
Jonathan Schleifer 2023-01-10 02:43:32 +00:00
parent e0e41e991a
commit cdf559f8e3
3 changed files with 18 additions and 30 deletions

View file

@ -199,23 +199,8 @@ grGlideShutdownCdecl(void)
grBufferClear(0, 0, 0);
}
- (void)setColor: (OFColor *)color
{
float values[4];
[color getRed: &values[0]
green: &values[1]
blue: &values[2]
alpha: &values[3]];
for (uint_fast8_t i = 0; i < 4; i++)
values[i] *= 255;
grColorCombine(GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
GR_COMBINE_LOCAL_CONSTANT, GR_COMBINE_OTHER_NONE, FXFALSE);
grConstantColorValue((((GrColor_t)values[0]) << 24) |
(((GrColor_t)values[1]) << 16) | (((GrColor_t)values[2]) << 8) |
(GrColor_t)values[2]);
}
- (void)drawPolygonVertices: (const O3DVertex *)vertices count: (size_t)count
- (void)drawPolygonWithVertices: (const O3DVertex *)vertices
count: (size_t)count
{
/*
* Range is -1 to 1, we add 1, so we get 0 to 2 - so we need to
@ -224,11 +209,15 @@ grGlideShutdownCdecl(void)
float halfWidth = grSstScreenWidth() / 2;
float halfHeight = grSstScreenHeight() / 2;
GrVertex *glideVertices = OFAllocMemory(count, sizeof(GrVertex));
GrVertex *glideVertices = OFAllocZeroedMemory(count, sizeof(GrVertex));
@try {
for (size_t i = 0; i < count; i++) {
glideVertices[i].x = (vertices[i].x + 1) * halfWidth;
glideVertices[i].y = (vertices[i].y + 1) * halfHeight;
glideVertices[i].r = vertices[i].r * 255;
glideVertices[i].g = vertices[i].g * 255;
glideVertices[i].b = vertices[i].b * 255;
glideVertices[i].a = vertices[i].a * 255;
}
grDrawPolygonVertexList((int)count, glideVertices);

View file

@ -19,6 +19,7 @@ OF_ASSUME_NONNULL_BEGIN
typedef struct OF_BOXABLE {
float x, y;
float r, g, b, a;
} O3DVertex;
@protocol O3DRenderer <OFObject>
@ -31,8 +32,8 @@ typedef struct OF_BOXABLE {
refreshRate: (float)refreshRate
options: (nullable OFDictionary *)options;
- (void)beginFrame;
- (void)setColor: (OFColor *)color;
- (void)drawPolygonVertices: (const O3DVertex *)vertices count: (size_t)count;
- (void)drawPolygonWithVertices: (const O3DVertex *)vertices
count: (size_t)count;
- (void)endFrame;
@end

View file

@ -32,23 +32,21 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate)
options: nil] autorelease];
const O3DVertex outerTriangle[] = {
{ -1, -1 },
{ 0, 1 },
{ 1, -1 }
{ -1, -1, 1, 0, 0 },
{ 0, 1, 0, 1, 0 },
{ 1, -1, 0, 0, 1 }
};
const O3DVertex innerTriangle[] = {
{ -0.5, 0.5 },
{ 0, -0.5 },
{ 0.5, 0.5 }
{ -0.5, 0.5, 1, 1, 0 },
{ 0, -0.5, 0, 1, 1 },
{ 0.5, 0.5, 1, 0, 1 }
};
OFDate *startDate = [OFDate date];
while (-startDate.timeIntervalSinceNow < 5) {
[renderer beginFrame];
[renderer setColor: [OFColor yellow]];
[renderer drawPolygonVertices: outerTriangle count: 3];
[renderer setColor: [OFColor red]];
[renderer drawPolygonVertices: innerTriangle count: 3];
[renderer drawPolygonWithVertices: outerTriangle count: 3];
[renderer drawPolygonWithVertices: innerTriangle count: 3];
[renderer endFrame];
}