30 const std::string versionString
31 =
reinterpret_cast<const char*
>(glGetString(GL_VERSION));
32 if (versionString.find(
"OpenGL ES 3.0") != std::string::npos)
41 return !GLEW_VERSION_3_0;
47 if (msaa_enable != aa_status)
49 msaa_enable = aa_status;
52 if (!feat_use_fbo_antialias)
54 glEnable(GL_MULTISAMPLE);
55 glEnable(GL_LINE_SMOOTH);
56 device->enableBlend();
58 device->setLineWidth(line_w_aa);
62 if (!feat_use_fbo_antialias)
64 glDisable(GL_MULTISAMPLE);
65 glDisable(GL_LINE_SMOOTH);
66 device->disableBlend();
68 device->setLineWidth(line_w);
76 if (device && !msaa_enable)
78 device->setLineWidth(line_w);
85 if (device && msaa_enable)
87 device->setLineWidth(line_w_aa);
91 void MeshRenderer::init()
94 const std::string versionString
95 =
reinterpret_cast<const char*
>(glGetString(GL_VERSION));
96 bool is_webgl2 = (versionString.find(
"OpenGL ES 3.0") != std::string::npos);
97 feat_use_fbo_antialias = is_webgl2;
98 if (feat_use_fbo_antialias)
100 glGetIntegerv(GL_MAX_SAMPLES, &msaa_samples);
104 feat_use_fbo_antialias = GLEW_VERSION_3_0;
105 glGetIntegerv(GL_MAX_SAMPLES, &msaa_samples);
113 std::stable_partition(sorted_queue.begin(), sorted_queue.end(),
114 [](RenderQueue::value_type& renderPair)
116 return !renderPair.first.contains_translucent;
120 if (feat_use_fbo_antialias && msaa_enable)
122 GLuint colorBuf, depthBuf;
123 glGenRenderbuffers(1, &colorBuf);
124 glGenRenderbuffers(1, &depthBuf);
129 glGenFramebuffers(1, &fbo);
132 device->getViewport(vp);
135 glBindRenderbuffer(GL_RENDERBUFFER, colorBuf);
136 glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa_samples,
137 GL_RGBA8, width, height);
138 glBindRenderbuffer(GL_RENDERBUFFER, depthBuf);
139 glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa_samples,
140 GL_DEPTH_COMPONENT24, width, height);
141 glBindRenderbuffer(GL_RENDERBUFFER, 0);
143 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
144 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
145 GL_RENDERBUFFER, colorBuf);
146 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
147 GL_RENDERBUFFER, depthBuf);
149 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
151 cerr <<
"Unable to create multisampled renderbuffer." << flush;
152 glDeleteFramebuffers(1, &fbo);
153 glBindFramebuffer(GL_FRAMEBUFFER, 0);
159 #ifndef __EMSCRIPTEN__
160 glEnable(GL_MULTISAMPLE);
163 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
164 for (
auto& q_elem : sorted_queue)
172 device->setPointLight(i, params.
lights[i]);
179 std::vector<int> tex_bufs, no_tex_bufs;
180 std::vector<TextBuffer*> text_bufs;
184 for (
size_t j = 0; j < GlDrawable::NUM_SHAPES; j++)
186 if (curr_drawable->buffers[i][j])
190 tex_bufs.emplace_back(curr_drawable->buffers[i][j].get()->getHandle());
194 no_tex_bufs.emplace_back(curr_drawable->buffers[i][j].get()->getHandle());
197 if (curr_drawable->indexed_buffers[i][j])
201 tex_bufs.emplace_back(curr_drawable->indexed_buffers[i][j].get()->getHandle());
205 no_tex_bufs.emplace_back(
206 curr_drawable->indexed_buffers[i][j].get()->getHandle());
211 text_bufs.emplace_back(&curr_drawable->text_buffer);
214 device->enableBlend();
218 device->enableDepthWrite();
222 for (
auto buf : tex_bufs)
224 device->drawDeviceBuffer(buf);
228 for (
auto buf : no_tex_bufs)
230 device->drawDeviceBuffer(buf);
234 device->enableBlend();
235 device->disableDepthWrite();
237 device->attachTexture(1, font_tex);
238 device->setNumLights(0);
241 device->drawDeviceBuffer(*buf);
243 device->enableDepthWrite();
244 if (feat_use_fbo_antialias || !msaa_enable) { device->disableBlend(); }
246 if (feat_use_fbo_antialias && msaa_enable && msaaFb)
248 device->enableBlend();
250 device->getViewport(vp);
254 glGenRenderbuffers(1, &colorBufId);
258 glGenFramebuffers(1, &fboId);
261 glBindRenderbuffer(GL_RENDERBUFFER, colorBuf);
262 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
263 glBindRenderbuffer(GL_RENDERBUFFER, 0);
265 glBindFramebuffer(GL_FRAMEBUFFER, resolveFb);
266 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
267 GL_RENDERBUFFER, colorBuf);
269 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
271 cerr <<
"Unable to create resolve renderbuffer." << endl;
272 glBindFramebuffer(GL_FRAMEBUFFER, 0);
276 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolveFb);
277 glBindFramebuffer(GL_READ_FRAMEBUFFER, msaaFb);
278 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
279 glBlitFramebuffer(0, 0, width, height,
283 #ifndef __EMSCRIPTEN__
284 glDisable(GL_MULTISAMPLE);
286 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
287 glBindFramebuffer(GL_READ_FRAMEBUFFER, resolveFb);
288 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
289 glBlitFramebuffer(0, 0, width, height,
293 device->disableBlend();
300 device->initXfbMode();
301 for (
auto& q_elem : queue)
309 device->setPointLight(i, params.
lights[i]);
316 std::vector<int> tex_bufs, no_tex_bufs;
317 std::vector<TextBuffer*> text_bufs;
321 for (
size_t j = 0; j < GlDrawable::NUM_SHAPES; j++)
323 if (curr_drawable->buffers[i][j])
327 tex_bufs.emplace_back(curr_drawable->buffers[i][j].get()->getHandle());
331 no_tex_bufs.emplace_back(curr_drawable->buffers[i][j].get()->getHandle());
334 if (curr_drawable->indexed_buffers[i][j])
338 tex_bufs.emplace_back(curr_drawable->indexed_buffers[i][j].get()->getHandle());
342 no_tex_bufs.emplace_back(
343 curr_drawable->indexed_buffers[i][j].get()->getHandle());
348 text_bufs.emplace_back(&curr_drawable->text_buffer);
352 for (
auto buf : tex_bufs)
354 device->captureXfbBuffer(*palette, cbuf, buf);
358 for (
auto buf : no_tex_bufs)
360 device->captureXfbBuffer(*palette, cbuf, buf);
364 device->enableBlend();
365 device->disableDepthWrite();
367 device->attachTexture(1, font_tex);
368 device->setNumLights(0);
371 device->captureXfbBuffer(cbuf, *buf);
374 device->exitXfbMode();
382 for (
size_t j = 0; j < GlDrawable::NUM_SHAPES; j++)
384 if (buf->buffers[i][j])
386 device->bufferToDevice((
array_layout) i, *(buf->buffers[i][j].get()));
388 if (buf->indexed_buffers[i][j])
390 device->bufferToDevice((
array_layout) i, *(buf->indexed_buffers[i][j].get()));
394 device->bufferToDevice(buf->text_buffer);
400 glDepthFunc(GL_LEQUAL);
401 glEnable(GL_DEPTH_TEST);
403 glPolygonOffset(1,1);
404 glEnable(GL_POLYGON_OFFSET_FILL);
406 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
407 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
410 GLuint default_texture;
411 glGenTextures(1, &default_texture);
412 glBindTexture(GL_TEXTURE_2D, default_texture);
413 int black_color = 0xFFFFFFFF;
414 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
417 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
418 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
419 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
428 glViewport(0, 0, w, h);
446 for (
const auto& entry : t_buf)
448 glm::vec3 raster = glm::project(
449 glm::vec3(entry.rx, entry.ry, entry.rz),
virtual void setTransformMatrices(glm::mat4 model_view, glm::mat4 projection)
Handle< rboCleanup > RenderBufHandle
TextureHandle passthrough_texture
void render(const RenderQueue &queued)
void setLineWidth(float w)
std::array< float, 4 > light_amb_scene
vector< FeedbackText > text
std::array< Light, LIGHTS_MAX > lights
CaptureBuffer capture(const RenderQueue &queued)
std::array< float, 4 > static_color
static bool useLegacyTextureFmts()
Handle< texCleanup > TextureHandle
void buffer(GlDrawable *buf)
void getViewport(GLint(&vp)[4])
static const int SAMPLER_ALPHA
static const int SAMPLER_COLOR
virtual void captureXfbBuffer(PaletteState &pal, CaptureBuffer &capture, int hnd)=0
vector< pair< RenderParams, GlDrawable * > > RenderQueue
bool contains_translucent
void setLineWidthMS(float w)
std::array< float, 4 > static_color
void setAntialiasing(bool aa_status)
std::array< double, 4 > clip_plane_eqn
void setViewport(GLsizei w, GLsizei h)
Handle< fboCleanup > FBOHandle