Advertisement
Guest User

cpp

a guest
Jun 21st, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.23 KB | None | 0 0
  1. #include "glWrapper.hpp"
  2.  
  3. #define GW_DEBUG
  4.  
  5. #ifdef GW_DEBUG
  6.     #define DEV_LOG(x, y) std::cout << x << y << '\n'
  7. #else
  8.     #define DEV_LOG(x, y)
  9. #endif
  10.  
  11. //
  12. // *SHADER
  13. //
  14.  
  15. // *DEFAULT SHADER SOURCE
  16.  
  17. const char *defaultVertexShader = "#version 330 core\n"
  18. "layout (location = 0) in vec3 aPos;\n"
  19. "uniform mat4 model;\n"
  20. "uniform mat4 view;\n"
  21. "uniform mat4 projection;\n"
  22. "void main()\n"
  23. "{\n"
  24. "    gl_Position = projection * view * model * vec4(aPos, 1);\n"
  25. "}\n";
  26.  
  27. const char *defaultFragmentShader = "#version 330 core\n"
  28. "out vec4 FragColor;\n"
  29. "void main()\n"
  30. "{\n"
  31. "    FragColor = vec4(0.8, 0.8, 0.8, 1);\n"
  32. "}\n";
  33.  
  34. static std::string ExtractFile(std::string path) // Extracts the contents of a file to a string
  35. {
  36.     std::ifstream file;
  37.     std::string line;
  38.     std::string returnValue;
  39.     file.exceptions(/*std::ifstream::failbit |*/ std::ifstream::badbit); // Set fstream exceptions (failbit removed for unneccesary exceptions)
  40.  
  41.     try
  42.     {
  43.         file.open(path);
  44.  
  45.         while(std::getline(file, line)){ // Extract lines
  46.         returnValue += line + '\n';
  47.         }
  48.     }
  49.     catch(std::ifstream::failure e)
  50.     {
  51.         std::cout << e.what() << '\n';
  52.     }
  53.    
  54.     return returnValue; // Return string
  55. }
  56.  
  57. static void CreateShader(unsigned int &id, GLenum type, std::string code){
  58.     id = glCreateShader(type);
  59.     const char* source = code.c_str();
  60.  
  61.     glShaderSource(id, 1, &source, NULL);
  62.  
  63.     glCompileShader(id);
  64.  
  65.     int success; // Error handle type
  66.     char log[512]; // Error message
  67.     glGetShaderiv(id, GL_COMPILE_STATUS, &success);
  68.     if(!success)
  69.     {
  70.         glGetShaderInfoLog(id, 512, NULL, log);
  71.         DEV_LOG("Failed compile: ", log);
  72.     }
  73.  
  74.     return;
  75. }
  76.  
  77. std::vector<float> GetAttributeData(tinygltf::Model& model, tinygltf::Primitive& primitive, std::string target){
  78.  
  79.     tinygltf::BufferView view = model.bufferViews[model.accessors[primitive.attributes.at(target)].bufferView];
  80.     int byteOffset = view.byteOffset;
  81.     int byteLength = view.byteLength;
  82.  
  83.     tinygltf::Buffer buffer = model.buffers[view.buffer];
  84.  
  85.     std::vector<unsigned char> data;
  86.     data.resize(buffer.data.size());
  87.     data = buffer.data;
  88.  
  89.     std::vector<float> attributeData;
  90.     attributeData.resize(byteLength / sizeof(float));
  91.  
  92.     std::memcpy(attributeData.data(), data.data() + byteOffset, byteLength);
  93.  
  94.     return attributeData;
  95. }
  96.  
  97. std::vector<unsigned short> GetIndexData(tinygltf::Model& model, tinygltf::Primitive& primitive){
  98.  
  99.     tinygltf::BufferView view = model.bufferViews[model.accessors[primitive.indices].bufferView];
  100.     int byteOffset = view.byteOffset;
  101.     int byteLength = view.byteLength;
  102.  
  103.     tinygltf::Buffer buffer = model.buffers[view.buffer];
  104.  
  105.     std::vector<unsigned char> data;
  106.     data.resize(buffer.data.size());
  107.     data = buffer.data;
  108.  
  109.     std::vector<unsigned short> indices;
  110.     indices.resize(byteLength / sizeof(unsigned short));
  111.  
  112.     std::memcpy(indices.data(), data.data() + byteOffset, byteLength);
  113.  
  114.     return indices;
  115. }
  116.  
  117. void CreateGlObjects(glWrap::Primitive &primitive){
  118.  
  119.     // DEV_LOG("Starting", "");
  120.     glGenVertexArrays(1, &primitive.m_VAO);
  121.     // DEV_LOG("VAO", primitive.m_VAO);
  122.     glGenBuffers(1, &primitive.m_VBO);
  123.     // DEV_LOG("VBO", primitive.m_VBO);
  124.     glGenBuffers(1, &primitive.m_EBO);
  125.     // DEV_LOG("EBO", primitive.m_EBO);
  126.     // DEV_LOG("Cont", "");
  127.  
  128.     glBindVertexArray(primitive.m_VAO);
  129.     // DEV_LOG("Binding VAO", "");
  130.  
  131.     glBindBuffer(GL_ARRAY_BUFFER, primitive.m_VBO);
  132.     glBufferData(GL_ARRAY_BUFFER, primitive.m_vertices.size() * sizeof(glWrap::Vertex), primitive.m_vertices.data(), GL_STATIC_DRAW);
  133.     // DEV_LOG("Vertex size", primitive.m_vertices.size());
  134.  
  135.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, primitive.m_EBO);
  136.     glBufferData(GL_ELEMENT_ARRAY_BUFFER, primitive.m_indices.size() * sizeof(GL_UNSIGNED_SHORT), primitive.m_indices.data(), GL_STATIC_DRAW);
  137.     // DEV_LOG("Index size", primitive.m_indices.size());
  138.  
  139.     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
  140.     glEnableVertexAttribArray(0);
  141.  
  142.     glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
  143.     glEnableVertexAttribArray(1);
  144.  
  145.     glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
  146.     glEnableVertexAttribArray(2);
  147.     // DEV_LOG("Attrib arrays generated", "");
  148.  
  149.     glBindVertexArray(0);
  150.  
  151.     // DEV_LOG("DONE", "");
  152. }
  153.  
  154. glWrap::Shader::Shader(std::string vertexPath, std::string fragmentPath){
  155.    
  156.     unsigned int vertex, fragment; // Shader objects
  157.  
  158.     CreateShader(vertex, GL_VERTEX_SHADER, ExtractFile(vertexPath));
  159.     CreateShader(fragment, GL_FRAGMENT_SHADER, ExtractFile(fragmentPath));
  160.  
  161.  
  162.     m_ID = glCreateProgram();
  163.     glAttachShader(m_ID, vertex);
  164.     glAttachShader(m_ID, fragment);
  165.  
  166.     glLinkProgram(m_ID);
  167.  
  168.     int success; // Error handle type
  169.     char log[512]; // Error message
  170.     glGetProgramiv(m_ID, GL_LINK_STATUS, &success);
  171.     if(!success)
  172.     {
  173.         glGetProgramInfoLog(m_ID, 512, NULL, log);
  174.         DEV_LOG("Failed linking: ", log);
  175.     }
  176.  
  177.     glDeleteShader(vertex);
  178.     glDeleteShader(fragment);
  179.  
  180.     return;
  181. }
  182.  
  183. glWrap::Shader::Shader(const char* vertexShader, const char* fragmentShader, bool isText){
  184.     unsigned int vertex, fragment; // Shader objects
  185.  
  186.     CreateShader(vertex, GL_VERTEX_SHADER, vertexShader);
  187.     CreateShader(fragment, GL_FRAGMENT_SHADER, fragmentShader);
  188.  
  189.     m_ID = glCreateProgram();
  190.     glAttachShader(m_ID, vertex);
  191.     glAttachShader(m_ID, fragment);
  192.  
  193.     glLinkProgram(m_ID);
  194.  
  195.     int success; // Error handle type
  196.     char log[512]; // Error message
  197.     glGetProgramiv(m_ID, GL_LINK_STATUS, &success);
  198.     if(!success)
  199.     {
  200.         glGetProgramInfoLog(m_ID, 512, NULL, log);
  201.         DEV_LOG("Failed linking: ", log);
  202.     }
  203.  
  204.     glDeleteShader(vertex);
  205.     glDeleteShader(fragment);
  206.  
  207.     return;
  208. }
  209.  
  210. void glWrap::Shader::Use(){
  211.     glUseProgram(m_ID);
  212. }
  213.  
  214. void glWrap::Shader::SetBool(const std::string &name, bool value) const{
  215.     if (glGetUniformLocation(m_ID, name.c_str()) != -1)
  216.         glUniform1i(glGetUniformLocation(m_ID, name.c_str()), (int)value);
  217. }
  218.  
  219. void glWrap::Shader::SetInt(const std::string &name, int value) const{
  220.     if (glGetUniformLocation(m_ID, name.c_str()) != -1)
  221.         glUniform1i(glGetUniformLocation(m_ID, name.c_str()), value);
  222. }
  223.  
  224. void glWrap::Shader::SetFloat(const std::string &name, float value) const{
  225.     if (glGetUniformLocation(m_ID, name.c_str()) != -1)
  226.         glUniform1f(glGetUniformLocation(m_ID, name.c_str()), value);
  227. }
  228.  
  229. void glWrap::Shader::SetMatrix4(const std::string &name, glm::mat4 mat) const{
  230.     if (glGetUniformLocation(m_ID, name.c_str()) != -1)
  231.         glUniformMatrix4fv(glGetUniformLocation(m_ID, name.c_str()), 1, GL_FALSE, glm::value_ptr(mat));
  232. }
  233.  
  234. //
  235. // *TEXTURE
  236. //
  237.  
  238. static GLenum GetChannelType(unsigned int channels){
  239.     switch(channels)
  240.     {
  241.         case 1:
  242.         return GL_RED;
  243.  
  244.         case 2:
  245.         return GL_RG;
  246.  
  247.         case 3:
  248.         return GL_RGB;
  249.  
  250.         case 4:
  251.         return GL_RGBA;
  252.     }
  253.  
  254.     return GL_RGB;
  255. }
  256.  
  257. glWrap::Texture2D::Texture2D(std::string image, bool flip, GLenum filter, GLenum desiredChannels){
  258.     stbi_set_flip_vertically_on_load(flip);
  259.     int width, height, channels;
  260.     unsigned char *data = stbi_load(image.c_str(), &width, &height, &channels, 0);
  261.  
  262.     // std::cout << channels << " channels\n";
  263.  
  264.     glGenTextures(1, &m_ID);
  265.     glBindTexture(GL_TEXTURE_2D, m_ID);
  266.  
  267.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  268.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  269.  
  270.     if(data)
  271.     {
  272.         glTexImage2D(GL_TEXTURE_2D, 0, desiredChannels, width, height, 0, GetChannelType(channels), GL_UNSIGNED_BYTE, data);
  273.         glGenerateMipmap(GL_TEXTURE_2D);
  274.     }
  275.     else std::cout << "Texture not loaded correctly\n";
  276.  
  277.     stbi_image_free(data);
  278. }
  279.  
  280. void glWrap::Texture2D::SetActive(unsigned int unit){
  281.     glActiveTexture(GL_TEXTURE0 + unit);
  282.     glBindTexture(GL_TEXTURE_2D, m_ID);
  283. }
  284.  
  285. //
  286. // *WorldObject
  287. //
  288.  
  289. glWrap::Transform glWrap::WorldObject::GetTransform() { return m_transform; }
  290. glm::vec3 glWrap::WorldObject::GetPosition(){ return m_transform.pos; }
  291. glm::vec3 glWrap::WorldObject::GetRotation() { return m_transform.rot; }
  292. glm::vec3 glWrap::WorldObject::GetScale(){ return m_transform.scl; }
  293. glm::vec3 glWrap::WorldObject::GetDirection(){
  294.     return glm::vec3{
  295.         (cos(glm::radians(m_transform.rot.z)) * cos(glm::radians(m_transform.rot.y))),
  296.         sin(glm::radians(m_transform.rot.y)),
  297.         (sin(glm::radians(m_transform.rot.z)) * cos(glm::radians(m_transform.rot.y)))};
  298. }
  299.  
  300. void glWrap::WorldObject::SetTransform(Transform transform){ m_transform = transform; }
  301. void glWrap::WorldObject::SetPosition(glm::vec3 position){ m_transform.pos = position; }
  302. void glWrap::WorldObject::SetRotation(glm::vec3 rotation){ m_transform.rot = rotation; }
  303. void glWrap::WorldObject::SetScale(glm::vec3 scale){ m_transform.scl = scale; }
  304.  
  305. void glWrap::WorldObject::AddPosition(glm::vec3 position){ m_transform.pos += position; }
  306. void glWrap::WorldObject::AddRotation(glm::vec3 rotation){ m_transform.rot += rotation; }
  307. void glWrap::WorldObject::AddScale(glm::vec3 scale){ m_transform.scl += scale; }
  308.  
  309. //
  310. // *Camera
  311. //
  312.  
  313. float glWrap::Camera::GetFOV(){ return m_FOV; }
  314. // glm::mat4 glWrap::Camera::GetView(){ return glm::lookAt( m_transform.pos, m_transform.pos +  ); }
  315. glm::mat4 glWrap::Camera::GetProjection(){
  316.     if(m_perspective) return glm::perspective(glm::radians(m_FOV), (m_aspect.x / m_aspect.y ), m_clip.x, m_clip.y );
  317.     else return glm::ortho(0.0f, m_aspect.x, 0.0f, m_aspect.y, m_clip.x, m_clip.y);
  318. }
  319.  
  320. //
  321. // *Mesh / Primitive
  322. //
  323.  
  324. void glWrap::Primitive::Draw(){
  325.  
  326.     // DEV_LOG("Binding VAO: ", m_VAO);
  327.     glBindVertexArray(m_VAO);
  328.     // DEV_LOG("Binding EBO: ", m_EBO);
  329.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);
  330.  
  331.     // DEV_LOG("Drawing elements", "");
  332.     glDrawElements(GL_TRIANGLES, m_indices.size(), GL_UNSIGNED_SHORT, 0);
  333. }
  334.  
  335. //
  336. // *Instance
  337. //
  338.  
  339. void glWrap::Instance::SetMesh(Mesh* mesh){
  340.     m_mesh = mesh;
  341.     m_shaders.resize(mesh->m_primitives.size());
  342.     // DEV_LOG("Shaders required: ", m_shaders.size());
  343. }
  344.  
  345. void glWrap::Instance::SetShader(Shader* shader, int primitive){
  346.     if (primitive < m_shaders.size()){
  347.         m_shaders[primitive] = shader;
  348.     }
  349.     else {
  350.         DEV_LOG("Wrong primitive index, max is: ", m_shaders.size() - 1);
  351.     }
  352. }
  353.  
  354. void glWrap::Instance::SetVisibility(bool visibility){ m_visible = visibility; }
  355.  
  356. glWrap::Mesh* glWrap::Instance::GetMesh(){ return m_mesh; }
  357.  
  358. glWrap::Shader* glWrap::Instance::GetShader(int primitive){
  359.     if (primitive < m_shaders.size()){
  360.         return m_shaders[primitive];
  361.     }
  362.     else {
  363.         // DEV_LOG("Wrong primitive index, max is: ", m_shaders.size() - 1);
  364.         return nullptr;
  365.     }
  366. }
  367.  
  368. bool glWrap::Instance::GetVisibility(){ return m_visible; }
  369.  
  370. //
  371. // *Window
  372. //
  373.  
  374. glWrap::Window::Window(std::string name, glm::ivec2 size, glm::vec4 color, Camera* camera, GLFWwindow* context) : m_name{name}, m_color{color}{
  375.  
  376.     m_ActiveCamera = camera;
  377.  
  378.     m_window = glfwCreateWindow(size.x, size.y, name.c_str(), NULL, context);
  379.  
  380.     glfwMakeContextCurrent(m_window);
  381.  
  382.    
  383.     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
  384.     {
  385.         DEV_LOG("Failed to initialize GLAD for window ", name);
  386.         glfwTerminate();
  387.     }
  388.    
  389.  
  390.     // glfwSetKeyCallback(m_window, keyCall);
  391. }
  392.  
  393. void glWrap::Window::Swap(){
  394.     glfwSwapBuffers(m_window);
  395.     if (glfwGetCurrentContext() != m_window) glfwMakeContextCurrent(m_window);
  396.     glClearColor(m_color.r, m_color.b, m_color.g, m_color.a);
  397.     glClear(GL_COLOR_BUFFER_BIT);
  398. }
  399.  
  400. void glWrap::Window::Draw(Instance& instance){
  401.     if (instance.GetMesh() && instance.GetVisibility() && m_ActiveCamera){
  402.  
  403.         for (int i{}; i < instance.GetMesh()->m_primitives.size(); ++i){
  404.            
  405.             if (!instance.GetShader(i)) continue;
  406.  
  407.             if (glfwGetCurrentContext() != m_window) glfwMakeContextCurrent(m_window);
  408.  
  409.             Shader* currentShader = instance.GetShader(i);
  410.  
  411.             currentShader->Use();
  412.  
  413.             glm::mat4 model = glm::mat4(1.0f);
  414.  
  415.             // model = glm::rotate(model, glm::radians(-55.0f), glm::vec3(1.0f, 0.0f, 0.0f));
  416.  
  417.             // model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.0f, 1.0f, 0.0f));
  418.  
  419.             // model = glm::rotate(model, glm::radians(m_transform.rot.x), glm::vec3(1.0f, 0.0f, 0.0f));
  420.  
  421.             // model = glm::rotate(model, glm::radians(m_transform.rot.y), glm::vec3(0.0f, 1.0f, 0.0f));
  422.             // model = glm::rotate(model, glm::radians(m_transform.rot.z), glm::vec3(0.0f, 0.0f, 1.0f));
  423.  
  424.             glm::mat4 view = glm::mat4(1.0f);
  425.  
  426.             // view = glm::translate(view, glm::vec3(0.0f, 0.0f, 3.0f));
  427.  
  428.             // view = glm::translate(view, m_transform.pos);
  429.  
  430.             glm::mat4 projection = glm::mat4(1.0f);
  431.  
  432.             // projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
  433.  
  434.             currentShader->SetMatrix4("model", model);
  435.             currentShader->SetMatrix4("view", view);
  436.             currentShader->SetMatrix4("projection", projection);
  437.  
  438.             instance.GetMesh()->m_primitives[i].Draw();
  439.         }
  440.     }
  441. }
  442.  
  443. bool glWrap::Window::isKeyHeld(unsigned int key) { return glfwGetKey(m_window, key) == GLFW_PRESS; }
  444. bool glWrap::Window::WindowRequestedClose() { return glfwWindowShouldClose(m_window); }
  445.  
  446. glWrap::Window::~Window(){
  447.     glfwDestroyWindow(m_window);
  448. }
  449.  
  450. /*
  451. void glWrap::Window::keyCall(GLFWwindow* window, int key, int scancode, int action, int mods){
  452.     switch (action){
  453.         case GLFW_PRESS:
  454.             m_heldKeys.push_back(key);
  455.             break;
  456.  
  457.         case GLFW_RELEASE:
  458.             for (int i{}; i < m_heldKeys.size(); ++i){
  459.                 if(m_heldKeys[i] == key){
  460.                     m_heldKeys.erase(m_heldKeys.begin() + i);
  461.                     break;
  462.                 }
  463.             }
  464.             break;
  465.  
  466.         case GLFW_REPEAT:
  467.             break;
  468.     }
  469. }
  470. */
  471.  
  472. //
  473. // *Engine
  474. //
  475.  
  476. glWrap::Engine::Engine(){
  477.    
  478.     if(!glfwInit()){
  479.         DEV_LOG("Failed to initialize OPENGL", "");
  480.         return;
  481.     }
  482.    
  483.     // glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
  484.  
  485.     m_context = glfwCreateWindow(10, 10, ".", NULL, NULL);
  486.  
  487.     glfwMakeContextCurrent(m_context);
  488.  
  489.     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
  490.     {
  491.         DEV_LOG("Failed to initialize GLAD for default context", "");
  492.         glfwTerminate();
  493.     }
  494.  
  495.     m_defaultShader = std::make_unique<Shader>(defaultVertexShader, defaultFragmentShader, true);
  496.  
  497.     // glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
  498. }
  499.  
  500. void glWrap::Engine::Update(){
  501.     if (m_firstFrame){
  502.         m_deltaTime = 0.0f;
  503.         m_lastFrameTime = glfwGetTime();
  504.         m_firstFrame = false;
  505.         glfwPollEvents();
  506.         return;
  507.     }
  508.  
  509.     glfwPollEvents();
  510.     m_deltaTime = glfwGetTime() - m_lastFrameTime;
  511.     m_lastFrameTime = glfwGetTime();
  512. }
  513.  
  514. float glWrap::Engine::GetDeltaTime(){ return m_deltaTime; }
  515.  
  516. glWrap::Shader* glWrap::Engine::GetDefaultShader(){ return m_defaultShader.get(); }
  517.  
  518. GLFWwindow* glWrap::Engine::GetContext(){ return m_context; }
  519.  
  520. glWrap::Engine::~Engine(){
  521.     glfwTerminate();
  522. }
  523.  
  524. void glWrap::LoadMesh(std::map<std::string, Mesh>& container, std::string file){
  525.  
  526.     tinygltf::TinyGLTF loader;
  527.     tinygltf::Model model;
  528.     std::string error{};
  529.     std::string warning{};
  530.  
  531.     if (!loader.LoadASCIIFromFile(&model, &error, &warning, file)){
  532.         DEV_LOG("ASCII Error", error);
  533.         DEV_LOG("ASCII Warning", warning);
  534.     }
  535.  
  536.     /*
  537.     else if (!Engine.LoadBinaryFromFile(&model, &error, &warning, path)){
  538.         DEV_LOG("BINARY Error", error);
  539.         DEV_LOG("BINARY Warning", warning);
  540.  
  541.         return;
  542.     }
  543.     */
  544.  
  545.     // DEV_LOG("Meshes found: ", model.meshes.size());
  546.  
  547.     for(int i{}; i < model.meshes.size(); ++i){
  548.         Mesh temp_mesh;
  549.  
  550.         int postfix{0};
  551.         while (container.count(model.meshes[i].name + "." + std::to_string(postfix))){
  552.             // DEV_LOG("Name exists already: ", (model.meshes[i].name + "." + std::to_string(postfix)));
  553.             ++postfix;
  554.         }
  555.  
  556.         // DEV_LOG("Created mesh: ", (model.meshes[i].name + "." + std::to_string(postfix)));
  557.  
  558.         for(int j{}; j < model.meshes[i].primitives.size(); ++j){
  559.  
  560.             temp_mesh.m_primitives.push_back(Primitive());
  561.             // DEV_LOG("Pushed primitive: ", j);
  562.  
  563.             Primitive& prim = temp_mesh.m_primitives.back();
  564.  
  565.             std::vector<float> position = GetAttributeData(model, model.meshes[i].primitives[j], "POSITION");
  566.             std::vector<float> normal = GetAttributeData(model, model.meshes[i].primitives[j], "NORMAL");
  567.             std::vector<float> texCoord = GetAttributeData(model, model.meshes[i].primitives[j], "TEXCOORD_0");
  568.  
  569.             int floats = position.size() + normal.size() + texCoord.size();
  570.  
  571.             std::vector<Vertex>& vertices = prim.m_vertices;
  572.  
  573.             vertices.resize(floats / 8);
  574.  
  575.             for (int x{}; x < vertices.size(); ++x){
  576.                 int posLoc = x * 3;
  577.                 int texLoc = x * 2;
  578.  
  579.                 vertices[x].pos.x = position[0 + posLoc];
  580.                 vertices[x].pos.y = position[1 + posLoc];
  581.                 vertices[x].pos.z = position[2 + posLoc];
  582.                 vertices[x].nor.x = normal[0 + posLoc];
  583.                 vertices[x].nor.y = normal[1 + posLoc];
  584.                 vertices[x].nor.z = normal[2 + posLoc];
  585.                 vertices[x].tex.x = texCoord[0 + posLoc];
  586.                 vertices[x].tex.y = texCoord[1 + posLoc];
  587.             }
  588.  
  589.             prim.m_indices = GetIndexData(model, model.meshes[i].primitives[j]);
  590.  
  591.             // DEV_LOG("Generating GL objects", "");
  592.  
  593.             CreateGlObjects(prim);
  594.  
  595.             // DEV_LOG("GL objects generated", "");
  596.             }
  597.         container.insert({(model.meshes[i].name + "." + std::to_string(postfix)), temp_mesh});
  598.  
  599.         // DEV_LOG("Inserted mesh: ", (model.meshes[i].name + std::to_string(postfix)));
  600.     }
  601.     // DEV_LOG("Meshes created", "");
  602.  
  603.     return;
  604. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement