1 module d2d.rendering.irendertarget; 2 3 import d2d; 4 5 /// Interface for containers being able to draw elements. 6 interface IRenderTarget 7 { 8 /// Set active container. 9 void bind(); 10 /// Resize the container texture to the new width and height. 11 void resize(int width, int height); 12 /// Create a container texture in the given resolution. 13 void create(int width, int height); 14 15 /// Clears the container texture by calling `bind()` -> `glClearColor(r, g, b, 1)` -> `glClear(GL_COLOR_BUFFER_BIT)`. 16 final void clear(float r, float g, float b) 17 { 18 bind(); 19 glClearColor(r, g, b, 1); 20 glClear(GL_COLOR_BUFFER_BIT); 21 } 22 23 /// Draws drawable using optional shader onto this. This will call `drawable.draw(this, shader);` 24 /// If shader is `null`, `ShaderProgram.default` is gonna be used. 25 final void draw(IDrawable drawable, ShaderProgram shader = null) 26 { 27 bind(); 28 drawable.draw(this, shader); 29 } 30 31 /// Draws raw geometry to the container texture using an optional shader. 32 /// If shader is null, ShaderProgram.default is gonna be used. 33 final void draw(Mesh mesh, ShaderProgram shader = null) 34 { 35 bind(); 36 if (shader is null) 37 shader = ShaderProgram.defaultShader; 38 39 shader.bind(); 40 shader.set("transform", matrixStack.top); 41 shader.set("projection", projectionStack.top); 42 glBindVertexArray(mesh.renderable.bufferID); 43 glDrawElements(GL_TRIANGLES, mesh.renderable.indexLength, GL_UNSIGNED_INT, null); 44 } 45 46 /// Returns the result of the container texture. 47 @property Texture texture(); 48 }