| 510 | } |
| 511 | |
| 512 | void OpenGLImage::drawAt(const GraphicsContext& context, const Point<int>& pos) |
| 513 | { |
| 514 | if (textureId == 0 || isInvalid()) |
| 515 | return; |
| 516 | |
| 517 | const OpenGL3GraphicsContext& gl3context = static_cast<const OpenGL3GraphicsContext&>(context); |
| 518 | |
| 519 | if (gl3context.program == 0) |
| 520 | return; |
| 521 | |
| 522 | if (! setupCalled) |
| 523 | { |
| 524 | setupOpenGLImage(*this, textureId); |
| 525 | setupCalled = true; |
| 526 | } |
| 527 | |
| 528 | const GLfloat x = (static_cast<double>(pos.getX()) / gl3context.width) * 2 - 1; |
| 529 | const GLfloat y = (static_cast<double>(pos.getY()) / gl3context.height) * -2 + 1; |
| 530 | const GLfloat w = (static_cast<double>(getWidth()) / gl3context.width) * 2; |
| 531 | const GLfloat h = (static_cast<double>(getHeight()) / gl3context.height) * -2; |
| 532 | |
| 533 | const GLfloat color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; |
| 534 | glUniform4fv(gl3context.color, 1, color); |
| 535 | |
| 536 | glActiveTexture(GL_TEXTURE0); |
| 537 | glBindTexture(GL_TEXTURE_2D, textureId); |
| 538 | glUniform1i(gl3context.usingTexture, 1); |
| 539 | |
| 540 | const GLfloat vertices[] = { |
| 541 | x, y, x, y + h, x + w, y + h, x + w, y, |
| 542 | 0.f, 0.f, 0.f, 1.f, 1.f, 1.f, 1.f, 0.f, |
| 543 | }; |
| 544 | glBindBuffer(GL_ARRAY_BUFFER, gl3context.buffers[0]); |
| 545 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); |
| 546 | glEnableVertexAttribArray(gl3context.bounds); |
| 547 | glEnableVertexAttribArray(gl3context.textureMap); |
| 548 | glVertexAttribPointer(gl3context.bounds, 2, GL_FLOAT, GL_FALSE, 0, nullptr); |
| 549 | glVertexAttribPointer(gl3context.textureMap, 2, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<void*>(sizeof(GLfloat) * 8)); |
| 550 | |
| 551 | static constexpr const GLubyte order[] = { 0, 1, 2, 0, 2, 3 }; |
| 552 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl3context.buffers[1]); |
| 553 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(order), order, GL_STATIC_DRAW); |
| 554 | |
| 555 | glDrawElements(GL_TRIANGLES, ARRAY_SIZE(order), GL_UNSIGNED_BYTE, nullptr); |
| 556 | |
| 557 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 558 | glDisableVertexAttribArray(gl3context.textureMap); |
| 559 | glDisableVertexAttribArray(gl3context.bounds); |
| 560 | glUniform1i(gl3context.usingTexture, 0); |
| 561 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 562 | glBindTexture(GL_TEXTURE_2D, 0); |
| 563 | } |
| 564 | |
| 565 | #ifdef DGL_USE_GLES |
| 566 | ImageFormat OpenGLImage::getFormat() const noexcept |
nothing calls this directly
no test coverage detected