| 582 | } |
| 583 | |
| 584 | void GL46Engine::EnableTextures(Shader const* shader, GLuint program) |
| 585 | { |
| 586 | int32_t const index = TextureSingle::shaderDataLookup; |
| 587 | for (auto const& ts : shader->GetData(index)) |
| 588 | { |
| 589 | if (!ts.object) |
| 590 | { |
| 591 | LogError(ts.name + " is null texture."); |
| 592 | } |
| 593 | |
| 594 | auto texture = static_cast<GL46TextureSingle*>(Bind(ts.object)); |
| 595 | if (!texture) |
| 596 | { |
| 597 | LogError("Failed to bind texture."); |
| 598 | } |
| 599 | |
| 600 | // By convension, ts.isGpuWritable is true for "image*" and false |
| 601 | // for "sampler*". |
| 602 | GLuint handle = texture->GetGLHandle(); |
| 603 | if (ts.isGpuWritable) |
| 604 | { |
| 605 | // For "image*" objects in the shader, use "readonly" or |
| 606 | // "writeonly" attributes in the layout to control R/W/RW access |
| 607 | // using shader compiler and then connect as GL_READ_WRITE here. |
| 608 | // Always bind level 0 and all layers. |
| 609 | GLint unit = mTextureImageUnitMap.AcquireUnit(program, ts.bindPoint); |
| 610 | glUniform1i(ts.bindPoint, unit); |
| 611 | uint32_t format = texture->GetTexture()->GetFormat(); |
| 612 | GLuint internalFormat = texture->GetInternalFormat(format); |
| 613 | glBindImageTexture(unit, handle, 0, GL_TRUE, 0, GL_READ_WRITE, internalFormat); |
| 614 | } |
| 615 | else |
| 616 | { |
| 617 | GLint unit = mTextureSamplerUnitMap.AcquireUnit(program, ts.bindPoint); |
| 618 | glUniform1i(ts.bindPoint, unit); |
| 619 | glActiveTexture(GL_TEXTURE0 + unit); |
| 620 | glBindTexture(texture->GetTarget(), handle); |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | void GL46Engine::DisableTextures(Shader const* shader, GLuint program) |
| 626 | { |
nothing calls this directly
no test coverage detected