created buffer shader and added shader logic to rectangle
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "../shader.cpp"
|
||||
|
||||
namespace UwU {
|
||||
// line
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "../shader.cpp"
|
||||
|
||||
namespace UwU {
|
||||
// point
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace UwU {
|
||||
|
||||
// Draw a rectangle
|
||||
void draw (Buffer buffer, Shader shader) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
if (shader.shaderType == COLOR) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
for (uint16_t y = y0; y < y1; y++) {
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
buffer.drawPixel(x, y, shader.c0);
|
||||
@@ -35,14 +35,13 @@ namespace UwU {
|
||||
return;
|
||||
|
||||
} else if (shader.shaderType == HGRADIENT) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
|
||||
// Precompute gradient LUT
|
||||
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(x, y, cols[x - x0]);
|
||||
@@ -51,7 +50,6 @@ namespace UwU {
|
||||
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++) {
|
||||
@@ -59,8 +57,16 @@ namespace UwU {
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
} else if (shader.shaderType == BUFFER) {
|
||||
for (uint16_t y = y0; y < y1; y++) {
|
||||
for (uint16_t x = x0; x < x1; x++) {
|
||||
buffer.drawPixel(x, y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "../shader.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class Triangle {
|
||||
|
||||
Reference in New Issue
Block a user