Skip to content
Snippets Groups Projects
Commit e2392f5b authored by gyroninja's avatar gyroninja
Browse files

Added seconds per frame counter

parent 22838faf
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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) == "&gt;") {
......@@ -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++;
}
}
......@@ -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
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment