fishbowl/engine/include/fishbone/draw.h

95 lines
2.9 KiB
C
Raw Normal View History

2026-06-01 13:50:35 +09:00
#ifndef __FISHBOWL_DRAW_H__
#define __FISHBOWL_DRAW_H__
#include <fishbone/pre.h>
namespace fishbone {
class Texture;
class Mesh;
class Renderer;
2026-06-05 21:43:30 +09:00
}; // namespace fishbone
2026-06-01 13:50:35 +09:00
2026-06-05 21:43:30 +09:00
#include <fishbone/window.h>
#include <fishbone/meshldr.h>
2026-06-06 01:04:29 +09:00
#include <fishbone/textureldr.h>
2026-06-06 22:30:58 +09:00
#include <fishbone/math.h>
2026-06-01 13:50:35 +09:00
namespace fishbone {
class Texture {
2026-06-06 01:04:29 +09:00
void init(fishbone::Renderer* renderer, unsigned char* rgba, int width, int height);
2026-06-01 13:50:35 +09:00
struct Impl;
Impl* impl;
2026-06-05 21:43:30 +09:00
public:
2026-06-06 01:04:29 +09:00
Texture(fishbone::Renderer* renderer, unsigned char* rgba, int width, int height) {
this->init(renderer, rgba, width, height);
}
Texture(fishbone::Renderer* renderer, fishbone::TextureData* data) {
this->init(renderer, data->rgba, data->width, data->height);
}
2026-06-01 13:50:35 +09:00
~Texture();
2026-06-06 01:04:29 +09:00
2026-06-06 01:07:19 +09:00
void begin();
void end();
2026-06-01 13:50:35 +09:00
};
class Mesh {
2026-06-05 21:43:30 +09:00
void init(fishbone::Renderer* renderer, std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals);
2026-06-01 13:50:35 +09:00
struct Impl;
Impl* impl;
2026-06-05 21:43:30 +09:00
public:
Mesh(fishbone::Renderer* renderer, std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals) {
this->init(renderer, vertices, texcoords, normals);
}
Mesh(fishbone::Renderer* renderer, fishbone::MeshData* data) {
this->init(renderer, data->vertices, data->texcoords, data->normals);
}
2026-06-01 13:50:35 +09:00
~Mesh();
2026-06-01 14:23:48 +09:00
void draw();
2026-06-06 01:04:29 +09:00
void draw(struct fishbone::Vector3 pos);
void draw(struct fishbone::Vector3 pos, struct fishbone::Vector3 rot);
fishbone::Texture* texture;
2026-06-01 13:50:35 +09:00
};
class Renderer {
struct Impl;
Impl* impl;
2026-06-05 21:43:30 +09:00
public:
Renderer(fishbone::Window* window);
2026-06-01 13:50:35 +09:00
~Renderer();
2026-06-06 01:04:29 +09:00
void prepare();
2026-06-06 22:30:58 +09:00
void quad(std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals) {
std::vector<struct fishbone::Vector3> v;
std::vector<struct fishbone::Vector2> t;
std::vector<struct fishbone::Vector3> n;
v = fishbone::quadToTriangle<struct fishbone::Vector3>(vertices);
t = fishbone::quadToTriangle<struct fishbone::Vector2>(texcoords);
n = fishbone::quadToTriangle<struct fishbone::Vector3>(normals);
this->triangle(v, t, n);
}
void triangle(std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals);
2026-06-10 01:10:55 +09:00
void quad(std::vector<struct fishbone::Vector2> vertices, std::vector<struct fishbone::Vector2> texcoords) {
std::vector<struct fishbone::Vector2> v;
std::vector<struct fishbone::Vector2> t;
v = fishbone::quadToTriangle<struct fishbone::Vector2>(vertices);
t = fishbone::quadToTriangle<struct fishbone::Vector2>(texcoords);
this->triangle(v, t);
}
void triangle(std::vector<struct fishbone::Vector2> vertices, std::vector<struct fishbone::Vector2> texcoords);
2026-06-01 13:50:35 +09:00
};
2026-06-06 01:04:29 +09:00
static float maxDistance = 64;
2026-06-05 21:43:30 +09:00
}; // namespace fishbone
2026-06-01 13:50:35 +09:00
#endif