Skip to content

Commit a30839d

Browse files
committed
Various opengl related comments
1 parent 081b677 commit a30839d

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

common/src/main/kotlin/com/lambda/graphics/buffer/Buffer.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ abstract class Buffer(
179179
}
180180

181181
/**
182-
* Grows the backing buffers
182+
* Allocates memory for each backing buffer using the specified size
183183
* This function handles the buffer binding
184184
*
185185
* @param size The size of the new buffer
186+
* @return An [IllegalArgumentException] if validation fails; null if the allocation succeeds
186187
*/
187188
open fun allocate(size: Long): Throwable? {
188189
if (!bufferValid(target, access))
@@ -203,9 +204,11 @@ abstract class Buffer(
203204
}
204205

205206
/**
206-
* Create a new buffer storage
207+
* Allocates new storage for the OpenGL buffer using the provided data
207208
* This function cannot be called twice for the same buffer
208209
* This function handles the buffer binding
210+
*
211+
* @return [IllegalArgumentException] for an invalid target or usage; null if storage allocation is successful
209212
*/
210213
open fun storage(data: ByteBuffer): Throwable? {
211214
if (!bufferValid(target, access))
@@ -226,11 +229,12 @@ abstract class Buffer(
226229
}
227230

228231
/**
229-
* Create a new buffer storage
232+
* Allocates storage for the buffer object
230233
* This function cannot be called twice for the same buffer
231234
* This function handles the buffer binding
232235
*
233236
* @param size The size of the storage buffer
237+
* @return [IllegalArgumentException] if the target or usage is invalid; null if storage allocation succeeds
234238
*/
235239
open fun storage(size: Long): Throwable? {
236240
if (!bufferValid(target, access))
@@ -251,12 +255,12 @@ abstract class Buffer(
251255
}
252256

253257
/**
254-
* Maps all or part of a buffer object's data store into the client's address space
258+
* Maps a specified region of the buffer's data store into client memory, processes it using the provided lambda, and then unmaps the buffer
255259
*
256260
* @param size Specifies the length of the range to be mapped.
257261
* @param offset Specifies the starting offset within the buffer of the range to be mapped.
258262
* @param block Lambda scope with the mapped buffer passed in
259-
* @return Error encountered during the mapping process
263+
* @return [IllegalArgumentException] if there were errors during the validation, mapping or unmapping, null otherwise
260264
*/
261265
open fun map(
262266
size: Long,
@@ -311,7 +315,9 @@ abstract class Buffer(
311315
}
312316

313317
/**
314-
* Sets the given data into the client mapped memory and executes the provided processing function to manage data transfer.
318+
* Uploads the specified data to the buffer starting at the given offset
319+
*
320+
* This abstract function should be implemented to perform the actual data transfer into the buffer
315321
*
316322
* @param data Data to set in memory
317323
* @param offset The starting offset within the buffer of the range to be mapped

common/src/main/kotlin/com/lambda/graphics/gl/Matrices.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object Matrices {
7878
}
7979

8080
/**
81-
* Translates the current matrix by the given x, y, and z values.
81+
* Applies a translation to the top matrix on the transformation stack
8282
*
8383
* @param x The translation amount along the X axis.
8484
* @param y The translation amount along the Y axis.
@@ -89,7 +89,7 @@ object Matrices {
8989
}
9090

9191
/**
92-
* Translates the current matrix by the given x, y, and z values.
92+
* Applies a translation to the top matrix on the transformation stack
9393
*
9494
* @param x The translation amount along the X axis.
9595
* @param y The translation amount along the Y axis.
@@ -152,12 +152,10 @@ object Matrices {
152152
}
153153

154154
/**
155-
* Temporarily sets a vertex offset vector for the duration of a block.
155+
* Applies a temporary vertex offset to mitigate precision issues in matrix operations on large coordinates
156156
*
157-
* Use this to avoid precision loss when using matrices while being on huge coordinates.
158-
*
159-
* @param offset The transformation offset to apply to vertices.
160-
* @param block The block of code to execute with the transformation applied.
157+
* @param offset the offset to apply to vertices for reducing precision loss
158+
* @param block the block of code within which the vertex offset is active
161159
*/
162160
fun withVertexOffset(offset: Vec3d, block: () -> Unit) {
163161
vertexOffset = offset

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
4646
private val gap get() = RenderSettings.gap * 0.5f - 0.8f
4747

4848
/**
49-
* Builds the vertex array for rendering the provided text string at a specified position.
49+
* Renders a text string at a specified position with configurable color, scale, shadow, and emoji parsing
5050
*
5151
* @param text The text to render.
5252
* @param position The position to render the text.
@@ -75,6 +75,14 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
7575
}
7676
}
7777

78+
/**
79+
* Renders a single glyph at the specified position with the given scale and color
80+
*
81+
* @param glyph The glyph information
82+
* @param position The rendering position where the glyph will be drawn
83+
* @param color The color of the glyph
84+
* @param scale The scale factor of the glyph
85+
*/
7886
fun drawGlyph(
7987
glyph: GlyphInfo,
8088
position: Vec2d,
@@ -150,15 +158,18 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
150158
}
151159

152160
/**
153-
* Calculates the height of the text based on the specified scale.
161+
* Computes the effective height of the rendered text
162+
*
163+
* The height is derived from the current font's base height, adjusted by a scaling factor
164+
* that ensures consistent visual proportions
154165
*
155166
* @param scale The scale factor for the height calculation.
156167
* @return The height of the text at the specified scale.
157168
*/
158169
fun getHeight(scale: Double = 1.0) = chars.height * getScaleFactor(scale) * 0.7
159170

160171
/**
161-
* Iterates over each character and emoji in the text and applies a block operation.
172+
* Processes a text string by iterating over its characters and emojis, computing rendering positions, and invoking a block for each glyph
162173
*
163174
* @param text The text to iterate over.
164175
* @param color The color of the text.

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/core/LambdaEmoji.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ enum class LambdaEmoji(val url: String) {
2525
private val emojiRegex = Regex(":[a-zA-Z0-9_]+:")
2626

2727
/**
28-
* Parses the emojis in the given text.
28+
* Extracts emoji names from the provided text
2929
*
30-
* @param text The text to parse.
30+
* The function scans the input text for patterns matching emojis in the `:name:` format and
31+
* returns a mutable list of the emoji names
3132
*
32-
* @return A list of parsed strings that does not contain the colons
33+
* @param text The text to parse.
34+
* @return A list of extract emoji names
3335
*/
3436
fun parse(text: String): MutableList<String> =
3537
emojiRegex.findAll(text).map { it.value }.toMutableList()

common/src/main/kotlin/com/lambda/graphics/texture/Texture.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,23 @@ open class Texture {
7575
var height = -1; protected set
7676

7777
/**
78-
* Binds the texture to a specific slot in the graphics pipeline.
78+
* Binds this texture to the specified slot in the graphics pipeline
7979
*/
8080
open fun bind(slot: Int = 0) {
8181
bindTexture(id, slot)
8282
}
8383

8484
/**
85-
* Unbinds the currently bound texture
85+
* Unbinds any texture from the specified slot
8686
*/
8787
open fun unbind(slot: Int = 0) {
8888
bindTexture(0, slot)
8989
}
9090

9191
/**
9292
* Uploads an image to the texture and generates mipmaps for the texture if applicable
93-
* This function does not bind the texture
93+
*
94+
* Note that the texture must be bound before calling this function
9495
*
9596
* @param image The image to upload to the texture
9697
* @param offset The mipmap level to upload the image to
@@ -112,7 +113,8 @@ open class Texture {
112113

113114
/**
114115
* Uploads an image to the texture and generates mipmaps for the texture if applicable
115-
* This function does not bind the texture
116+
*
117+
* Note that the texture must be bound before calling this function
116118
*
117119
* @param buffer The image buffer to upload to the texture
118120
* @param width The width of the texture
@@ -136,7 +138,8 @@ open class Texture {
136138

137139
/**
138140
* Updates the data of a texture
139-
* This function does not bind the texture
141+
*
142+
* Note that the texture must be bound before calling this function
140143
*
141144
* @param image The image to upload to the texture
142145
* @param offset The mipmap level to upload the image to

common/src/main/kotlin/com/lambda/graphics/texture/TextureOwner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object TextureOwner {
3434
get() = textureMap.getValue(this@texture)[0]
3535

3636
/**
37-
* Retrieves a specific texture owned by the object by its index
37+
* Retrieves the texture associated with the receiver object at the specified index
3838
*
3939
* @param index The index of the texture to retrieve
4040
* @return The texture [T] at the given index

0 commit comments

Comments
 (0)