MCPcopy Create free account
hub / github.com/DISTRHO/DPF / drawRectangle

Function drawRectangle

dgl/src/OpenGL3.cpp:372–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370
371template<typename T>
372static void drawRectangle(const GraphicsContext& context, const Rectangle<T>& rect, const bool outline)
373{
374 DISTRHO_SAFE_ASSERT_RETURN(rect.isValid(),);
375
376 const OpenGL3GraphicsContext& gl3context = static_cast<const OpenGL3GraphicsContext&>(context);
377
378 if (gl3context.program == 0)
379 return;
380
381 const GLfloat x = (static_cast<double>(rect.getX()) / gl3context.width) * 2 - 1;
382 const GLfloat y = (static_cast<double>(rect.getY()) / gl3context.height) * -2 + 1;
383 const GLfloat w = (static_cast<double>(rect.getWidth()) / gl3context.width) * 2;
384 const GLfloat h = (static_cast<double>(rect.getHeight()) / gl3context.height) * -2;
385
386 const GLfloat vertices[] = { x, y, x, y + h, x + w, y + h, x + w, y };
387
388 glBindBuffer(GL_ARRAY_BUFFER, gl3context.buffers[0]);
389 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
390 glEnableVertexAttribArray(gl3context.bounds);
391 glVertexAttribPointer(gl3context.bounds, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
392 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl3context.buffers[1]);
393
394 if (outline)
395 {
396 static constexpr const GLubyte order[] = { 0, 1, 1, 2, 2, 3, 3, 0 };
397 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(order), order, GL_STATIC_DRAW);
398 glDrawElements(GL_LINES, ARRAY_SIZE(order), GL_UNSIGNED_BYTE, nullptr);
399 }
400 else
401 {
402 static constexpr const GLubyte order[] = { 0, 1, 2, 0, 2, 3 };
403 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(order), order, GL_STATIC_DRAW);
404 glDrawElements(GL_TRIANGLES, ARRAY_SIZE(order), GL_UNSIGNED_BYTE, nullptr);
405 }
406
407 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
408 glDisableVertexAttribArray(gl3context.bounds);
409 glBindBuffer(GL_ARRAY_BUFFER, 0);
410}
411
412template<typename T>
413void Rectangle<T>::draw(const GraphicsContext& context)

Callers

nothing calls this directly

Calls 3

isValidMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected