Skip to main content
Code Review

Return to Answer

added 86 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192

Disclaimer: This is the first time I have ever really looked into using OpenGL

Disclaimer: This is the first time I have ever really looked into using OpenGL

Bounty Awarded with 25 reputation awarded by Community Bot
added 17 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
 void
 run(GLFWwindow *window)
 {
 void *resources = setup();
 glfwSetWindowUserPointer(window, resources);
 
 #ifdef MEASURE
 glfwSwapInterval(0);
 #endif
 
 int viewport_width, viewport_height;
 
 // set for proper resizing of window and viewport
 glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
 
 while (!glfwWindowShouldClose(window))
 {
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 glfwGetFramebufferSize(window, &viewport_width, &viewport_height);
 glViewportframebuffer_size_callback(0, 0window, viewport_width, viewport_height);
 
 draw(resources);
 
 glfwSwapBuffers(window);
 glfwPollEvents();
 #ifdef MEASURE
 printfps();
 #endif
 }
 
 cleanup(resources);
 }
 void
 run(GLFWwindow *window)
 {
 void *resources = setup();
 glfwSetWindowUserPointer(window, resources);
 
 #ifdef MEASURE
 glfwSwapInterval(0);
 #endif
 
 int viewport_width, viewport_height;
 
 // set for proper resizing of window and viewport
 glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
 
 while (!glfwWindowShouldClose(window))
 {
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 glfwGetFramebufferSize(window, &viewport_width, &viewport_height);
 glViewport(0, 0, viewport_width, viewport_height);
 
 draw(resources);
 
 glfwSwapBuffers(window);
 glfwPollEvents();
 #ifdef MEASURE
 printfps();
 #endif
 }
 
 cleanup(resources);
 }
 void
 run(GLFWwindow *window)
 {
 void *resources = setup();
 glfwSetWindowUserPointer(window, resources);
 
 #ifdef MEASURE
 glfwSwapInterval(0);
 #endif
 
 int viewport_width, viewport_height;
 
 // set for proper resizing of window and viewport
 glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
 
 while (!glfwWindowShouldClose(window))
 {
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 glfwGetFramebufferSize(window, &viewport_width, &viewport_height);
 framebuffer_size_callback(window, viewport_width, viewport_height);
 
 draw(resources);
 
 glfwSwapBuffers(window);
 glfwPollEvents();
 #ifdef MEASURE
 printfps();
 #endif
 }
 
 cleanup(resources);
 }
added 675 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192

Bugs

Bugs

Optimization

Optimization

  • Running my own profiling tests for a longer duration, I came up with the following data.

enter image description here

As we can see, glDrawElementsInstanced() now only takes up 2% of the total run time. The big time hogs are CGLFlushDrawable and _glfwPlatformPollEvents.

  • There are two ways to process pending events. glfwPollEvents() processes only those events that have already been received and then returns immediately. This is the best choice when rendering continually, like most games do.

    If instead you only need to update your rendering once you have received new input, glfwWaitEvents() is a better choice. It waits until at least one event has been received, putting the thread to sleep in the meantime, and then processes all received events just like glfwPollEvents() does. This saves a great deal of CPU cycles and is useful for, for example, many kinds of editing tools.


I plan to further expand this answer as I work to optimize this code. This answer is only preliminary right now, and points out what I have found.

Bugs

Optimization

  • There are two ways to process pending events. glfwPollEvents() processes only those events that have already been received and then returns immediately. This is the best choice when rendering continually, like most games do.

    If instead you only need to update your rendering once you have received new input, glfwWaitEvents() is a better choice. It waits until at least one event has been received, putting the thread to sleep in the meantime, and then processes all received events just like glfwPollEvents() does. This saves a great deal of CPU cycles and is useful for, for example, many kinds of editing tools.


I plan to further expand this answer as I work to optimize this code. This answer is only preliminary right now, and points out what I have found.

Bugs

Optimization

  • Running my own profiling tests for a longer duration, I came up with the following data.

enter image description here

As we can see, glDrawElementsInstanced() now only takes up 2% of the total run time. The big time hogs are CGLFlushDrawable and _glfwPlatformPollEvents.

  • There are two ways to process pending events. glfwPollEvents() processes only those events that have already been received and then returns immediately. This is the best choice when rendering continually, like most games do.

    If instead you only need to update your rendering once you have received new input, glfwWaitEvents() is a better choice. It waits until at least one event has been received, putting the thread to sleep in the meantime, and then processes all received events just like glfwPollEvents() does. This saves a great deal of CPU cycles and is useful for, for example, many kinds of editing tools.

added 675 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
added 653 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
markdown update + indentation fixed in code + fixed is published
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
markdown update + indentation fixed in code + fixed is published
Source Link
Loading
added 161 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /