/
Team8
/
kittycad
Обзор
Документация
Войти
/
Team8
/
kittycad
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/graphics/rendering.h
144 строки
3 KB
levovix
add: prototype for Thread (резьба)
08 янв 2026, 21:35
08 янв 2026, 21:35
fcd7540
Код
Авторство
О чём код?
#pragma once #include <la.h> // #include <QtOpenGL/QOpenGLFunctions_3_3_Compatibility> #include "data/typedefs.h" typedef unsigned int GLenum; typedef unsigned int GLuint; typedef int GLsizei; typedef int GLint; #define GL_TRIANGLES 0x0004 #define GL_STATIC_DRAW 0x88E4 constexpr char const* glsl_version = "#version 130"; class QOpenGLFunctions_3_3_Compatibility; extern QOpenGLFunctions_3_3_Compatibility& gl; class MbSolid; void checkGlErrors(); void setUniform(GLint handle, V4f const& v); void setUniform(GLint handle, M4f const& v, bool transpose = false); using GlVertexArray = GLuint; using GlBuffer = GLuint; struct Mesh { ~Mesh(); GlVertexArray vao{}; GlBuffer vertices{}, indices{}, normals{}, surfaceIndices{}; GLenum kind{GL_TRIANGLES}; int elementCount{0}; using index_t = GLint; using normal_t = V3f; using vertex_t = V3f; using surfaceIndex_t = GLint; inline bool hasIndices() const { return indices != 0; } inline bool hasNormals() const { return normals != 0; } }; struct DrawContext { using GLint = int; struct Shaders { struct Flat { GLuint handle{}; GLint model{-2}; GLint view{-2}; GLint projection{-2}; GLint color{-2}; struct Uniforms { M4f model{1}; M4f view{1}; M4f projection{1}; V4f color{1, 1, 1, 1}; }; void use(Uniforms const& args); // todo: генерировать автоматически } flat; struct Shaded { GLuint handle{}; GLint model{-2}; GLint view{-2}; GLint projection{-2}; GLint color{-2}; GLint shadowColor{-2}; GLint lightDir{-2}; GLint backlight{-2}; struct Uniforms { M4f model{1}; M4f view{1}; M4f projection{1}; V4f color{1, 1, 1, 1}; V4f shadowColor{0.4, 0.4, 0.4, 1}; V3f lightDir = v3f_norm(V3f{-1, -1, -1}, 1e-6, {}); float backlight{0.6}; }; void use(Uniforms const& args); // todo: генерировать автоматически } shaded; } shaders; struct Shapes { owned<Mesh> rect; } shapes; }; void glfw_error_callback(int error, const char* description); char const* glErrorToString(int errcode); void raiseCompilationErrorsIfAny(GLuint handle, GLenum statusKind); GLuint newShader(char const* vert, char const* frag, char const* version); struct MeshData { Mesh::vertex_t const* vertices{}; GLsizei vertexCount{0}; Mesh::index_t const* indices{}; GLsizei indexCount{0}; Mesh::normal_t const* normals{}; GLsizei normalCount{0}; // per-vertex normals Mesh::surfaceIndex_t const* surfaceIndices{}; GLsizei surfaceIndexCount{0}; GLenum kind{GL_TRIANGLES}; GLenum usage{GL_STATIC_DRAW}; }; owned<Mesh> newMesh(MeshData data); void draw(Mesh const& mesh); void initShaders(DrawContext& ctx, char const* version); void initMeshes(DrawContext& ctx); owned<Mesh> toMesh(MbSolid* solid);