Przeglądaj źródła

Add an occlusion query to count shaded fragments

master
Brian Ho 5 lat temu
rodzic
commit
664cb38c7c
2 zmienionych plików z 25 dodań i 9 usunięć
  1. 1
    1
      README.md
  2. 24
    8
      occlusion.cc

+ 1
- 1
README.md Wyświetl plik

@@ -5,6 +5,6 @@ This repo contains the source for an applicaiton that renders triangles using Op

## Instructions
- Enter the CrOS chroot and set up the boards you want to test against (`setup_board --board=${BOARD}`).
- Emerge mesa, and libpng to the device under test (`emerge media-libs/mesa libpng && cros deploy ${IP_ADDR} ${PACKAGES}`).
- Emerge mesa, and libpng to the device under test (`emerge x11-drivers/opengles-headers media-libs/mesa libpng && cros deploy ${IP_ADDR} ${PACKAGES}`).
- `make shaders`
- `target={local, atlas (i915), cheza (adreno)} make`

+ 24
- 8
occlusion.cc Wyświetl plik

@@ -1,7 +1,9 @@
#include <png.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>

#include <fstream>
#include <iostream>
@@ -22,15 +24,17 @@ void InitializeEGL() {
eglInitialize(display, nullptr, nullptr);
eglBindAPI(EGL_OPENGL_ES_API);

const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
const EGLint config_attribs[] = { EGL_SURFACE_TYPE, EGL_DONT_CARE, EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT, EGL_NONE };
const EGLint config_attribs[] = {
EGL_SURFACE_TYPE, EGL_DONT_CARE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE };
EGLConfig egl_config;
EGLint num_configs;
if (!eglChooseConfig(display, config_attribs, &egl_config, 1, &num_configs)) {
ERROR("Unable to choose EGL config");
}

const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
EGLContext context = eglCreateContext(display, egl_config, EGL_NO_CONTEXT, context_attribs);
if (context == EGL_NO_CONTEXT) {
ERROR("Failed to create GLES context");
@@ -45,7 +49,7 @@ void SetUpFramebuffer() {
GLuint color_buffer;
glGenRenderbuffers(1, &color_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, color_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, kWidth, kHeight);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kWidth, kHeight);

GLuint depth_buffer;
glGenRenderbuffers(1, &depth_buffer);
@@ -115,16 +119,27 @@ GLuint CreateProgram() {
return program;
}

void Draw(GLuint program) {
uint32_t Draw(GLuint program) {
glViewport(0, 0, kWidth, kHeight);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);

glUseProgram(program);
GLuint query_object;
glGenQueries(1, &query_object);
glBeginQuery(GL_SAMPLES_PASSED, query_object);
if (glGetError()) {
ERROR("GLES version does not support GL_SAMPLES_PASSED");
}
glDrawArrays(GL_TRIANGLES, 0, 6);
glEndQuery(GL_SAMPLES_PASSED);

uint32_t shaded_fragments = 0;
glGetQueryObjectuiv(query_object, GL_QUERY_RESULT, &shaded_fragments);

glFinish();
return shaded_fragments;
}

GLubyte* ReadFramebuffer() {
@@ -154,7 +169,8 @@ int main() {
SetUpFramebuffer();
GLuint program = CreateProgram();
Draw(program);
uint32_t shaded_fragments = Draw(program);
std::cout << "[Occlusion query] shaded fragments: " << shaded_fragments << std::endl;

GLubyte* pixels = ReadFramebuffer();
WriteImage(pixels);

Ładowanie…
Anuluj
Zapisz