diff --git a/README.md b/README.md index 3a41cb58fe04b126cb7fe05a32b518edba55bb24..095e68d309c7abfd5f1dfb65e0d6799f3077607e 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,9 @@ In the face of recent changes in Firefox, some anons were asking for a /g/'s per - Create components for defining how HTML elements are rendered. - Create components for defining how CSS rules affect elements. - Render the parsed data. - +- Calculate the height of every node to make positioning nodes easier. +- Create css parser. +- Make css rules trickle down. +- Make text components more efficient (no longer have seperate vao, vbo, and texture for every character) +- Handle more HTTP status codes +- Add address field diff --git a/src/graphics/opengl/components/TextComponent.cpp b/src/graphics/opengl/components/TextComponent.cpp index 22fb07b419b122ea68bcd5e54f0269b0e567c18b..7fe1e64d1a4307fbb4477764341fbe94046d2b15 100644 --- a/src/graphics/opengl/components/TextComponent.cpp +++ b/src/graphics/opengl/components/TextComponent.cpp @@ -7,26 +7,26 @@ TextComponent::TextComponent(const std::string &text, const int x, const int y, this->fontSize = fontSize; this->bold = bold; - htmlDecode(this->text); + sanitize(this->text); rasterize(this->text, x, y, fontSize, bold, windowWidth, windowHeight); + glGenBuffers(1, &elementBufferObject); + for (int i = 0; i < glyphVertices.size(); i++) { const Glyph &glyph = glyphs[i]; const std::unique_ptr<float[]> &glyphVertice = glyphVertices[i]; vertexArrayObjects.push_back(0); vertexBufferObjects.push_back(0); - elementBufferObjects.push_back(0); glGenVertexArrays(1, &vertexArrayObjects.back()); glGenBuffers(1, &vertexBufferObjects.back()); - glGenBuffers(1, &elementBufferObjects.back()); glBindVertexArray(vertexArrayObjects.back()); glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjects.back()); glBufferData(GL_ARRAY_BUFFER, ((3 + 2) * 4) * sizeof(float), glyphVertice.get(), GL_STATIC_DRAW); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObjects.back()); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*) (0 * sizeof(float))); @@ -45,10 +45,10 @@ TextComponent::TextComponent(const std::string &text, const int x, const int y, } TextComponent::~TextComponent() { + glDeleteBuffers(1, &elementBufferObject); for (int i = 0; i < vertexArrayObjects.size(); i++) { glDeleteVertexArrays(1, &vertexArrayObjects[i]); glDeleteBuffers(1, &vertexBufferObjects[i]); - glDeleteBuffers(1, &elementBufferObjects[i]); glDeleteTextures(1, &textures[i]); } } @@ -99,7 +99,7 @@ void TextComponent::rasterize(const std::string &text, const int x, const int y, void TextComponent::render() { if (verticesDirty) { - for (int i = 0; i < vertexArrayObjects.size(); i++) { + for (int i = 0; i < vertexBufferObjects.size(); i++) { glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjects[i]); glBufferData(GL_ARRAY_BUFFER, ((3 + 2) * 4) * sizeof(float), glyphVertices[i].get(), GL_STATIC_DRAW); } @@ -122,7 +122,7 @@ void TextComponent::pointToViewport(float &x, float &y, const int windowWidth, c y = ((y / windowHeight) * 2) - 1; } -void TextComponent::htmlDecode(std::string &str) { +void TextComponent::sanitize(std::string &str) { size_t found = 0; while ((found = str.find("&", found)) != std::string::npos) { if (str.substr(found, 4) == ">") { @@ -130,4 +130,9 @@ void TextComponent::htmlDecode(std::string &str) { } found++; } + found = 0; + while ((found = str.find("\n", found)) != std::string::npos) { + str.replace(found, 1, ""); + found++; + } } diff --git a/src/graphics/opengl/components/TextComponent.h b/src/graphics/opengl/components/TextComponent.h index b63d4e895d321587aa3e70f85e7d5cb566eca343..d2f7d6a7a1e4aa8a1fbbf78c191b6ef2871043a5 100644 --- a/src/graphics/opengl/components/TextComponent.h +++ b/src/graphics/opengl/components/TextComponent.h @@ -25,7 +25,7 @@ private: std::vector<std::unique_ptr<float[]>> glyphVertices; std::vector<GLuint> vertexArrayObjects; std::vector<GLuint> vertexBufferObjects; - std::vector<GLuint> elementBufferObjects; + GLuint elementBufferObject; std::vector<GLuint> textures; public: TextComponent(const std::string &text, const int x, const int y, const int fontSize, const bool bold,const int windowWidth, const int windowHeight); @@ -34,7 +34,7 @@ public: void render(); void resize(const int x, const int y, const int windowWidth, const int windowHeight); void pointToViewport(float &x, float &y, const int windowWidth, const int windowHeight) const; - void htmlDecode(std::string &str); + void sanitize(std::string &str); }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0901cdb4ec35fbb2f440ba566ec56d748c5a876d..922390332c8efcd070a5ce060b7347f5e2db9871 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,9 +39,9 @@ const std::string getHostFromURL(const std::string &url) { void handleRequest(const HTTPResponse &response) { if (response.statusCode == 200) { const std::unique_ptr<HTMLParser> parser = std::make_unique<HTMLParser>(); - std::clock_t begin = clock(); + const std::clock_t begin = clock(); std::shared_ptr<Node> rootNode = parser->parse(response.body); - std::clock_t end = clock(); + const std::clock_t end = clock(); std::cout << "Parsed document in: " << std::fixed << (((double) (end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl; window->setDOM(rootNode); } @@ -66,7 +66,10 @@ int main(int argc, char *argv[]) { request->sendRequest(handleRequest); window->init(); while (!glfwWindowShouldClose(window->window)) { + const std::clock_t begin = clock(); window->render(); + const std::clock_t end = clock(); + std::cout << '\r' << std::fixed << ((((double) (end - begin)) / CLOCKS_PER_SEC) * 1000) << std::scientific << " ms/f " << std::flush; } return 0; }