// // Copyright 2014 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { Q_OBJECT QOpenGLContextWrapper _context; protected: void renderText(); public: QTestWindow() { setSurfaceType(QSurface::OpenGLSurface); QSurfaceFormat format = getDefaultOpenGLSurfaceFormat(); setFormat(format); _context.setFormat(format); _context.create(); show(); makeCurrent(); gl::initModuleGl(); gpu::Context::init(); makeCurrent(); resize(QSize(800, 600)); } virtual ~QTestWindow() { } void draw(); void makeCurrent() { _context.makeCurrent(this); } }; const std::string VERTEX_SHADER_DEFINES{ R"GLSL( #version 410 core #define GPU_VERTEX_SHADER #define GPU_TRANSFORM_IS_STEREO #define GPU_TRANSFORM_STEREO_CAMERA #define GPU_TRANSFORM_STEREO_CAMERA_INSTANCED #define GPU_TRANSFORM_STEREO_SPLIT_SCREEN )GLSL" }; const std::string PIXEL_SHADER_DEFINES{ R"GLSL( #version 410 core #define GPU_PIXEL_SHADER #define GPU_TRANSFORM_IS_STEREO #define GPU_TRANSFORM_STEREO_CAMERA #define GPU_TRANSFORM_STEREO_CAMERA_INSTANCED #define GPU_TRANSFORM_STEREO_SPLIT_SCREEN )GLSL" }; void testShaderBuild(const std::string& vs_src, const std::string& fs_src) { std::string error; std::vector binary; GLuint vs, fs; if (!gl::compileShader(GL_VERTEX_SHADER, vs_src, VERTEX_SHADER_DEFINES, vs, error) || !gl::compileShader(GL_FRAGMENT_SHADER, fs_src, PIXEL_SHADER_DEFINES, fs, error)) { throw std::runtime_error("Failed to compile shader"); } auto pr = gl::compileProgram({ vs, fs }, error, binary); if (!pr) { throw std::runtime_error("Failed to link shader"); } } void QTestWindow::draw() { if (!isVisible()) { return; } makeCurrent(); glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); static std::once_flag once; std::call_once(once, [&]{ testShaderBuild(sdf_text3D_vert::getSource(), sdf_text3D_frag::getSource()); testShaderBuild(DrawTransformUnitQuad_vert::getSource(), DrawTexture_frag::getSource()); testShaderBuild(DrawTexcoordRectTransformUnitQuad_vert::getSource(), DrawTexture_frag::getSource()); testShaderBuild(DrawViewportQuadTransformTexcoord_vert::getSource(), DrawTexture_frag::getSource()); testShaderBuild(DrawTransformUnitQuad_vert::getSource(), DrawTextureOpaque_frag::getSource()); testShaderBuild(DrawTransformUnitQuad_vert::getSource(), DrawColoredTexture_frag::getSource()); testShaderBuild(skybox_vert::getSource(), skybox_frag::getSource()); testShaderBuild(simple_vert::getSource(), simple_frag::getSource()); testShaderBuild(simple_vert::getSource(), simple_textured_frag::getSource()); testShaderBuild(simple_vert::getSource(), simple_textured_unlit_frag::getSource()); testShaderBuild(deferred_light_vert::getSource(), directional_ambient_light_frag::getSource()); testShaderBuild(deferred_light_vert::getSource(), directional_skybox_light_frag::getSource()); testShaderBuild(standardTransformPNTC_vert::getSource(), standardDrawTexture_frag::getSource()); testShaderBuild(standardTransformPNTC_vert::getSource(), DrawTextureOpaque_frag::getSource()); testShaderBuild(model_vert::getSource(), model_frag::getSource()); testShaderBuild(model_normal_map_vert::getSource(), model_normal_map_frag::getSource()); testShaderBuild(model_vert::getSource(), model_translucent_frag::getSource()); testShaderBuild(model_normal_map_vert::getSource(), model_translucent_frag::getSource()); testShaderBuild(model_lightmap_vert::getSource(), model_lightmap_frag::getSource()); testShaderBuild(model_lightmap_normal_map_vert::getSource(), model_lightmap_normal_map_frag::getSource()); testShaderBuild(skin_model_vert::getSource(), model_frag::getSource()); testShaderBuild(skin_model_normal_map_vert::getSource(), model_normal_map_frag::getSource()); testShaderBuild(skin_model_vert::getSource(), model_translucent_frag::getSource()); testShaderBuild(skin_model_normal_map_vert::getSource(), model_translucent_frag::getSource()); testShaderBuild(model_shadow_vert::getSource(), model_shadow_frag::getSource()); testShaderBuild(textured_particle_vert::getSource(), textured_particle_frag::getSource()); /* FIXME: Bring back the ssao shader tests testShaderBuild(gaussian_blur_vert::getSource()ical_vert::getSource(), gaussian_blur_frag::getSource()); testShaderBuild(gaussian_blur_horizontal_vert::getSource(), gaussian_blur_frag::getSource()); testShaderBuild(ambient_occlusion_vert::getSource(), ambient_occlusion_frag::getSource()); testShaderBuild(ambient_occlusion_vert::getSource(), occlusion_blend_frag::getSource()); */ testShaderBuild(overlay3D_vert::getSource(), overlay3D_frag::getSource()); testShaderBuild(paintStroke_vert::getSource(),paintStroke_frag::getSource()); testShaderBuild(polyvox_vert::getSource(), polyvox_frag::getSource()); }); _context.swapBuffers(this); } const char * LOG_FILTER_RULES = R"V0G0N( hifi.gpu=true )V0G0N"; int main(int argc, char** argv) { setupHifiApplication("Shaders Test"); QGuiApplication app(argc, argv); QLoggingCategory::setFilterRules(LOG_FILTER_RULES); QTestWindow window; QTimer timer; timer.setInterval(1); app.connect(&timer, &QTimer::timeout, &app, [&] { window.draw(); }); timer.start(); app.exec(); return 0; } #include "main.moc"