GLVis  v4.2
Accurate and flexible finite element visualization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
renderer_core.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-443271.
4 //
5 // This file is part of the GLVis visualization tool and library. For more
6 // information and source code availability see https://glvis.org.
7 //
8 // GLVis is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef GLVIS_RENDERER_CORE_HPP
13 #define GLVIS_RENDERER_CORE_HPP
14 #include "renderer.hpp"
15 #include "shader.hpp"
16 
17 namespace gl3
18 {
19 // Renderer for OpenGL versions with access to the programmable pipeline
20 class CoreGLDevice : public GLDevice
21 {
22 public:
24  {
31  };
32 
34  {
35  float pos[4];
36  float color[4];
37  float clipCoord;
38  };
39 
40 private:
41  ShaderProgram default_prgm;
42  ShaderProgram feedback_prgm;
43  VtxArrayHandle global_vao;
44 
45  BufObjHandle feedback_vbo;
46 
47  const static std::vector<std::string> unif_list;
48 
49  std::unordered_map<std::string, GLuint> uniforms;
50 
51  bool use_clip_plane;
52 
53  struct VBOData
54  {
55  BufObjHandle vert_buf;
56  BufObjHandle elem_buf;
57  GLenum shape;
58  size_t count;
59  array_layout layout;
60  };
61 
62  std::vector<VBOData> vbos;
63 
64  bool compileShaders();
65  void initializeShaderState(const ShaderProgram& prog);
66 
67  template<typename T>
68  void drawDeviceBufferImpl(GLenum shape, int count, bool indexed);
69 
70  void processTriangleXfbBuffer(CaptureBuffer& cbuf,
71  const vector<ShaderXfbVertex>& verts);
72  void processLineXfbBuffer(CaptureBuffer& cbuf,
73  const vector<ShaderXfbVertex>& verts);
74 
75 public:
77  : global_vao(0)
78  {
79  vbos.emplace_back(VBOData{}); // dummy for index 0
80  }
81 
82  DeviceType getType() override { return GLDevice::CORE_DEVICE; }
83 
84  void init() override;
85  void setTransformMatrices(glm::mat4 model_view, glm::mat4 projection) override;
86  void setNumLights(int i) override;
87  void setMaterial(Material mat) override;
88  void setPointLight(int i, Light lt) override;
89  void setAmbientLight(const std::array<float, 4>& amb) override;
90  void setClipPlaneUse(bool enable) override;
91  void setClipPlaneEqn(const std::array<double, 4>& eqn) override;
92 
93  void bufferToDevice(array_layout layout, IVertexBuffer& buf) override;
94  void bufferToDevice(array_layout layout, IIndexedBuffer& buf) override;
95  void bufferToDevice(TextBuffer& t_buf) override;
96  void drawDeviceBuffer(int hnd) override;
97  void drawDeviceBuffer(const TextBuffer& t_buf) override;
98 
99  void initXfbMode() override
100  {
101  glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, feedback_vbo);
102  initializeShaderState(feedback_prgm);
103  glEnable(GL_RASTERIZER_DISCARD);
104  }
105  void exitXfbMode() override
106  {
107  glDisable(GL_RASTERIZER_DISCARD);
108  initializeShaderState(default_prgm);
109  glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
110  }
112  {
113  glDisable(GL_RASTERIZER_DISCARD);
114  initializeShaderState(prog);
115  glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
116  }
117  void captureXfbBuffer(PaletteState& pal, CaptureBuffer& cbuf, int hnd) override;
118 };
119 
120 }
121 
122 #endif // GLVIS_RENDERER_CORE_HPP
void setClipPlaneEqn(const std::array< double, 4 > &eqn) override
void drawDeviceBuffer(int hnd) override
void setNumLights(int i) override
void setClipPlaneUse(bool enable) override
void init() override
void bindExternalProgram(const ShaderProgram &prog)
array_layout
Definition: types.hpp:170
void captureXfbBuffer(PaletteState &pal, CaptureBuffer &cbuf, int hnd) override
void bufferToDevice(array_layout layout, IVertexBuffer &buf) override
void setPointLight(int i, Light lt) override
DeviceType getType() override
void exitXfbMode() override
void setTransformMatrices(glm::mat4 model_view, glm::mat4 projection) override
void setAmbientLight(const std::array< float, 4 > &amb) override
void setMaterial(Material mat) override
void initXfbMode() override