added gradient shaders to all primatives
This commit is contained in:
+12
-9
@@ -34,6 +34,8 @@ int main(void) {
|
|||||||
uint16_t w = 800, h = 480;
|
uint16_t w = 800, h = 480;
|
||||||
UwU::Shader fuchsia = UwU::Shader(UwU::Direction::V, 100, 300, UwU::Color(0xb00b69ff), UwU::Color(0x00000000));
|
UwU::Shader fuchsia = UwU::Shader(UwU::Direction::V, 100, 300, UwU::Color(0xb00b69ff), UwU::Color(0x00000000));
|
||||||
UwU::Shader red = UwU::Shader(UwU::Direction::V, 69, 420, UwU::Color(0xff0000ff), UwU::Color(0x00000000));
|
UwU::Shader red = UwU::Shader(UwU::Direction::V, 69, 420, UwU::Color(0xff0000ff), UwU::Color(0x00000000));
|
||||||
|
UwU::Shader bisexual = UwU::Shader(UwU::Direction::H, 100, 469, UwU::Color(0xff0000ff), UwU::Color(0x0000ffff));
|
||||||
|
UwU::Shader aqua = UwU::Shader(UwU::Direction::V, 4, 475, UwU::Color(0x00ff00ff), UwU::Color(0x0000ffff));
|
||||||
UwU::Shader warmup = UwU::Shader(UwU::Color(0xb00b69ff));
|
UwU::Shader warmup = UwU::Shader(UwU::Color(0xb00b69ff));
|
||||||
UwU::Color green = UwU::Color(0x00ff00ff);
|
UwU::Color green = UwU::Color(0x00ff00ff);
|
||||||
UwU::Color blue = UwU::Color(0x0000ff80);
|
UwU::Color blue = UwU::Color(0x0000ff80);
|
||||||
@@ -41,31 +43,30 @@ int main(void) {
|
|||||||
|
|
||||||
UwU::Surface surface = UwU::Surface(w, h, onKey);
|
UwU::Surface surface = UwU::Surface(w, h, onKey);
|
||||||
UwU::Buffer buffer = UwU::Buffer(800, 480);
|
UwU::Buffer buffer = UwU::Buffer(800, 480);
|
||||||
UwU::Shader triangleBuffer = UwU::Shader(69, 69, buffer);
|
UwU::Shader gradientBuffer = UwU::Shader(69, 69, buffer);
|
||||||
|
|
||||||
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
|
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
|
||||||
|
UwU::Rectangle bgRectangle = UwU::Rectangle(2, 2, 797, 477);
|
||||||
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
|
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
|
||||||
UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300);
|
UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300);
|
||||||
UwU::Point point = UwU::Point(387, 43);
|
UwU::Point point = UwU::Point(387, 43);
|
||||||
|
|
||||||
|
bgRectangle.draw(buffer, aqua);
|
||||||
triangle.draw(buffer, fuchsia);
|
|
||||||
rectangle.draw(surface.buffer, triangleBuffer);
|
|
||||||
|
|
||||||
// Benchmarking
|
// Benchmarking
|
||||||
struct timespec start, end;
|
struct timespec start, end;
|
||||||
const int WARMUP = 100;
|
const int WARMUP = 100;
|
||||||
const int BATCH = 1000;
|
const int BATCH = 1000;
|
||||||
const int SAMPLES = 10;
|
const int SAMPLES = 10;
|
||||||
|
|
||||||
for (int i = 0; i < WARMUP; i++) {
|
for (int i = 0; i < WARMUP; i++) {
|
||||||
trapezoid.draw(surface.buffer, fuchsia);
|
rectangle.draw(surface.buffer, gradientBuffer);
|
||||||
}
|
}
|
||||||
long times[SAMPLES];
|
long times[SAMPLES];
|
||||||
for (int s = 0; s < SAMPLES; s++) {
|
for (int s = 0; s < SAMPLES; s++) {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
for (int i = 0; i < BATCH; i++) {
|
for (int i = 0; i < BATCH; i++) {
|
||||||
trapezoid.draw(surface.buffer, fuchsia);
|
rectangle.draw(surface.buffer, gradientBuffer);
|
||||||
}
|
}
|
||||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
times[s] = (end.tv_sec - start.tv_sec) * 1000000000L + (end.tv_nsec - start.tv_nsec);
|
times[s] = (end.tv_sec - start.tv_sec) * 1000000000L + (end.tv_nsec - start.tv_nsec);
|
||||||
@@ -79,6 +80,8 @@ int main(void) {
|
|||||||
printf("Elapsed: %ld ns\n", timeAvg);
|
printf("Elapsed: %ld ns\n", timeAvg);
|
||||||
|
|
||||||
|
|
||||||
|
triangle.draw(surface.buffer, fuchsia);
|
||||||
|
trapezoid.draw(surface.buffer, red);
|
||||||
point.draw(surface.buffer, green);
|
point.draw(surface.buffer, green);
|
||||||
|
|
||||||
UwU::Line lines[8] {
|
UwU::Line lines[8] {
|
||||||
@@ -93,7 +96,7 @@ int main(void) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (uint16_t i = 0; i < 8; i++) {
|
for (uint16_t i = 0; i < 8; i++) {
|
||||||
lines[i].draw(surface.buffer, green);
|
lines[i].draw(surface.buffer, bisexual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,18 @@ namespace UwU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
} else if (shader.shaderType == BUFFER) {
|
||||||
|
for (int16_t x = ix0; x < ix1; x++) {
|
||||||
|
buffer.drawPixel((uint16_t)x, (uint16_t)y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y));
|
||||||
|
if (d > 0) {
|
||||||
|
y += yi;
|
||||||
|
d += (2 * (dy - dx));
|
||||||
|
} else {
|
||||||
|
d += (2 * dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -110,6 +122,17 @@ namespace UwU {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
} else if (shader.shaderType == BUFFER) {
|
||||||
|
for (int16_t y = iy0; y < iy1; y++) {
|
||||||
|
buffer.drawPixel((uint16_t)x, (uint16_t)y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y));
|
||||||
|
if (d > 0) {
|
||||||
|
x += xi;
|
||||||
|
d += (2 * (dx - dy));
|
||||||
|
} else {
|
||||||
|
d += (2 * dx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ namespace UwU {
|
|||||||
} else if (shader.shaderType == VGRADIENT) {
|
} else if (shader.shaderType == VGRADIENT) {
|
||||||
buffer.drawPixel(x, y, ShaderMethods::gradient(shader.v0, shader.scale, shader.c0, shader.c1, y));
|
buffer.drawPixel(x, y, ShaderMethods::gradient(shader.v0, shader.scale, shader.c0, shader.c1, y));
|
||||||
return;
|
return;
|
||||||
|
} else if (shader.shaderType == BUFFER) {
|
||||||
|
buffer.drawPixel(x, y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,13 @@ namespace UwU {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
} else if (shader.shaderType == BUFFER) {
|
||||||
|
for (uint16_t i = 0; i < height; i++) {
|
||||||
|
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
|
||||||
|
buffer.drawPixel(x, i + y0, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, i + y0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,6 +157,24 @@ namespace UwU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
} else if (shader.shaderType == BUFFER) {
|
||||||
|
// Left-handed triangle case (midpoint is left of triangle)
|
||||||
|
if ((int16_t)midX < longBound[midY - topY]) {
|
||||||
|
for (uint16_t i = 0; i < height; i++) {
|
||||||
|
for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) {
|
||||||
|
buffer.drawPixel(x, i + (uint16_t)topY, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, i + topY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Right-handed triangle case (midpoint is right of triangle)
|
||||||
|
} else {
|
||||||
|
for (uint16_t i = 0; i < height; i++) {
|
||||||
|
for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) {
|
||||||
|
buffer.drawPixel(x, i + (uint16_t)topY, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, i + topY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user