Skip to content

Commit e891d18

Browse files
Merge pull request #60 from ArtifactForms/working2
Added java doc and constructor parameter validation
2 parents b334fda + b355088 commit e891d18

File tree

2 files changed

+111
-5
lines changed

2 files changed

+111
-5
lines changed
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,65 @@
11
package engine.resources;
22

3+
/**
4+
* Represents a generic texture in the engine. Provides methods for querying dimensions, managing
5+
* pixels, binding/unbinding the texture, and controlling texture sampling and filtering options.
6+
*/
37
public interface Texture {
48

9+
/**
10+
* Gets the width of the texture in pixels.
11+
*
12+
* @return the width of the texture.
13+
*/
514
int getWidth();
615

16+
/**
17+
* Gets the height of the texture in pixels.
18+
*
19+
* @return the height of the texture.
20+
*/
721
int getHeight();
822

9-
void bind(int unit); // Bind to a specific texture unit
23+
/**
24+
* Updates the texture's pixel data.
25+
*
26+
* @param pixels an array of pixel data, typically in ARGB or RGBA format, depending on the
27+
* engine's requirements.
28+
*/
29+
void setPixels(int[] pixels);
30+
31+
/**
32+
* Binds the texture to a specific texture unit for rendering.
33+
*
34+
* @param unit the texture unit to bind to (e.g., 0 for GL_TEXTURE0).
35+
*/
36+
void bind(int unit);
1037

38+
/** Unbinds the texture from the current texture unit. */
1139
void unbind();
1240

41+
/** Deletes the texture and releases any resources associated with it. */
1342
void delete();
1443

15-
void setPixels(int[] pixels);
16-
44+
/**
45+
* Gets the current filter mode of the texture.
46+
*
47+
* @return the {@link FilterMode} applied to the texture.
48+
*/
1749
FilterMode getFilterMode();
18-
50+
51+
/**
52+
* Sets the filter mode for the texture, determining how it is sampled.
53+
*
54+
* @param filterMode the new {@link FilterMode} to apply.
55+
*/
1956
void setFilterMode(FilterMode filterMode);
20-
57+
58+
/**
59+
* Gets the underlying backend texture implementation. This is useful for accessing
60+
* engine-specific or platform-specific features.
61+
*
62+
* @return the backend texture object.
63+
*/
2164
Texture getBackendTexture();
2265
}

src/main/java/engine/resources/Texture2D.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,116 @@
11
package engine.resources;
22

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+
*/
311
public class Texture2D implements Texture {
412

513
private Texture texture;
614

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+
*/
725
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+
}
832
texture = TextureManager.getInstance().createTexture(width, height);
933
}
1034

35+
/**
36+
* Gets the width of the texture in pixels.
37+
*
38+
* @return the width of the texture.
39+
*/
1140
@Override
1241
public int getWidth() {
1342
return texture.getWidth();
1443
}
1544

45+
/**
46+
* Gets the height of the texture in pixels.
47+
*
48+
* @return the height of the texture.
49+
*/
1650
@Override
1751
public int getHeight() {
1852
return texture.getHeight();
1953
}
2054

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+
*/
2160
@Override
2261
public void bind(int unit) {
2362
texture.bind(unit);
2463
}
2564

65+
/** Unbinds the texture from its currently bound texture unit. */
2666
@Override
2767
public void unbind() {
2868
texture.unbind();
2969
}
3070

71+
/** Deletes the texture and releases any associated resources. */
3172
@Override
3273
public void delete() {
3374
texture.delete();
3475
}
3576

77+
/**
78+
* Updates the pixel data of the texture.
79+
*
80+
* @param pixels an array of pixel data to set for this texture.
81+
*/
3682
@Override
3783
public void setPixels(int[] pixels) {
3884
texture.setPixels(pixels);
3985
}
4086

87+
/**
88+
* Gets the filter mode currently applied to the texture.
89+
*
90+
* @return the filter mode of the texture.
91+
* @see FilterMode
92+
*/
4193
@Override
4294
public FilterMode getFilterMode() {
4395
return texture.getFilterMode();
4496
}
4597

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+
*/
46104
@Override
47105
public void setFilterMode(FilterMode filterMode) {
48106
texture.setFilterMode(filterMode);
49107
}
50108

109+
/**
110+
* Retrieves the backend texture instance used by this facade.
111+
*
112+
* @return the underlying {@link Texture} instance.
113+
*/
51114
@Override
52115
public Texture getBackendTexture() {
53116
return texture;

0 commit comments

Comments
 (0)