cache optimized rectangle drawing and made sure the methods could be inlined
This commit is contained in:
+47
-14
@@ -6,10 +6,10 @@
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "../shaders/shader.cpp"
|
||||
#include "../shaders/colorshader.cpp"
|
||||
// #include "../shaders/colorshader.cpp"
|
||||
// #include "../shaders/gradientshader.cpp"
|
||||
#include "../shaders/hgradientshader.cpp"
|
||||
#include "../shaders/vgradientshader.cpp"
|
||||
// #include "../shaders/hgradientshader.cpp"
|
||||
// #include "../shaders/vgradientshader.cpp"
|
||||
// #include "../mapper.cpp"
|
||||
|
||||
namespace UwU {
|
||||
@@ -29,19 +29,52 @@ namespace UwU {
|
||||
uint16_t y1;
|
||||
|
||||
// Draw a rectangle
|
||||
template<typename ShaderType>
|
||||
void draw (Buffer buffer, ShaderType& shader) {
|
||||
// printf("color: %u, %u, %u, %u", shader.color().r, shader.color().g, shader.color().b, shader.color().a);
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
// Coord2 uv = Coord2();
|
||||
for (uint16_t y = y0; y < y1; y++) {
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
// uv = mapper.map(Coord2(x, y));
|
||||
Color c = shader.color(x, y);
|
||||
buffer.drawPixel(Coord2(x, y), c);
|
||||
void draw (Buffer buffer, Shader shader) {
|
||||
if (shader.shaderType == COLOR) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
Color c = shader.c0;
|
||||
uint8_t r = c.r;
|
||||
uint8_t g = c.g;
|
||||
uint8_t b = c.b;
|
||||
size_t stride = buffer.stride;
|
||||
size_t i = (size_t)y0 * buffer.stride + (size_t)x0 * 4;
|
||||
for (uint16_t y = y0; y < y1; y++) {
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
// buffer.drawPixel(Coord2(x, y), shader.c0);
|
||||
buffer.pixels[i + 0] = b;
|
||||
buffer.pixels[i + 1] = g;
|
||||
buffer.pixels[i + 2] = r;
|
||||
buffer.pixels[i + 3] = 255;
|
||||
i += 4;
|
||||
}
|
||||
i += stride - ((x1 - x0) * 4);
|
||||
}
|
||||
return;
|
||||
|
||||
} else if (shader.shaderType == HGRADIENT) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
Color cols[x1 - x0];
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
cols[x - x0] = ShaderMethods::gradient(shader.u0, shader.scale, shader.c0, shader.c1, x);
|
||||
}
|
||||
for (uint16_t y = y0; y < y1; y++) {
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
buffer.drawPixel(Coord2(x, y), cols[x - x0]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
} else if (shader.shaderType == VGRADIENT) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
for (uint16_t y = y0; y < y1; y++) {
|
||||
Color c = ShaderMethods::gradient(shader.v0, shader.scale, shader.c0, shader.c1, y);
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
buffer.drawPixel(Coord2(x, y), c);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user