|
1 | 1 | package engine.resources; |
2 | 2 |
|
| 3 | +/** |
| 4 | + * A facade class representing a 2D texture, providing a simplified interface for creating and |
| 5 | + * manipulating textures in the rendering engine. |
| 6 | + * |
| 7 | + * <p>This class delegates functionality to an underlying {@link Texture} instance managed by the |
| 8 | + * {@link TextureManager}. It provides an abstraction to easily work with 2D textures without |
| 9 | + * directly handling the backend implementation. |
| 10 | + */ |
3 | 11 | public class Texture2D implements Texture { |
4 | 12 |
|
5 | 13 | private Texture texture; |
6 | 14 |
|
| 15 | + /** |
| 16 | + * Constructs a 2D texture with the specified width and height. |
| 17 | + * |
| 18 | + * <p>The texture is created using the {@link TextureManager} singleton instance. The width and |
| 19 | + * height must be positive integers; otherwise, an exception is thrown. |
| 20 | + * |
| 21 | + * @param width the width of the texture in pixels. Must be greater than 0. |
| 22 | + * @param height the height of the texture in pixels. Must be greater than 0. |
| 23 | + * @throws IllegalArgumentException if the width or height is less than or equal to zero. |
| 24 | + */ |
7 | 25 | public Texture2D(int width, int height) { |
| 26 | + if (width <= 0) { |
| 27 | + throw new IllegalArgumentException("Width cannot be negative or zero."); |
| 28 | + } |
| 29 | + if (height <= 0) { |
| 30 | + throw new IllegalArgumentException("Height cannot be negative or zero."); |
| 31 | + } |
8 | 32 | texture = TextureManager.getInstance().createTexture(width, height); |
9 | 33 | } |
10 | 34 |
|
| 35 | + /** |
| 36 | + * Gets the width of the texture in pixels. |
| 37 | + * |
| 38 | + * @return the width of the texture. |
| 39 | + */ |
11 | 40 | @Override |
12 | 41 | public int getWidth() { |
13 | 42 | return texture.getWidth(); |
14 | 43 | } |
15 | 44 |
|
| 45 | + /** |
| 46 | + * Gets the height of the texture in pixels. |
| 47 | + * |
| 48 | + * @return the height of the texture. |
| 49 | + */ |
16 | 50 | @Override |
17 | 51 | public int getHeight() { |
18 | 52 | return texture.getHeight(); |
19 | 53 | } |
20 | 54 |
|
| 55 | + /** |
| 56 | + * Binds the texture to the specified texture unit for rendering. |
| 57 | + * |
| 58 | + * @param unit the texture unit to bind this texture to. |
| 59 | + */ |
21 | 60 | @Override |
22 | 61 | public void bind(int unit) { |
23 | 62 | texture.bind(unit); |
24 | 63 | } |
25 | 64 |
|
| 65 | + /** Unbinds the texture from its currently bound texture unit. */ |
26 | 66 | @Override |
27 | 67 | public void unbind() { |
28 | 68 | texture.unbind(); |
29 | 69 | } |
30 | 70 |
|
| 71 | + /** Deletes the texture and releases any associated resources. */ |
31 | 72 | @Override |
32 | 73 | public void delete() { |
33 | 74 | texture.delete(); |
34 | 75 | } |
35 | 76 |
|
| 77 | + /** |
| 78 | + * Updates the pixel data of the texture. |
| 79 | + * |
| 80 | + * @param pixels an array of pixel data to set for this texture. |
| 81 | + */ |
36 | 82 | @Override |
37 | 83 | public void setPixels(int[] pixels) { |
38 | 84 | texture.setPixels(pixels); |
39 | 85 | } |
40 | 86 |
|
| 87 | + /** |
| 88 | + * Gets the filter mode currently applied to the texture. |
| 89 | + * |
| 90 | + * @return the filter mode of the texture. |
| 91 | + * @see FilterMode |
| 92 | + */ |
41 | 93 | @Override |
42 | 94 | public FilterMode getFilterMode() { |
43 | 95 | return texture.getFilterMode(); |
44 | 96 | } |
45 | 97 |
|
| 98 | + /** |
| 99 | + * Sets the filter mode for the texture. |
| 100 | + * |
| 101 | + * @param filterMode the desired filter mode to apply to the texture. |
| 102 | + * @see FilterMode |
| 103 | + */ |
46 | 104 | @Override |
47 | 105 | public void setFilterMode(FilterMode filterMode) { |
48 | 106 | texture.setFilterMode(filterMode); |
49 | 107 | } |
50 | 108 |
|
| 109 | + /** |
| 110 | + * Retrieves the backend texture instance used by this facade. |
| 111 | + * |
| 112 | + * @return the underlying {@link Texture} instance. |
| 113 | + */ |
51 | 114 | @Override |
52 | 115 | public Texture getBackendTexture() { |
53 | 116 | return texture; |
|
0 commit comments