Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit e11da12

Browse files
committed
GLList; SpriteBatch use IMS
1 parent bf0fddd commit e11da12

File tree

13 files changed

+642
-100
lines changed

13 files changed

+642
-100
lines changed

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
exports org.overrun.swgl.core.asset;
1616
exports org.overrun.swgl.core.cfg;
1717
exports org.overrun.swgl.core.gl;
18+
exports org.overrun.swgl.core.gl.ims;
1819
exports org.overrun.swgl.core.io;
1920
exports org.overrun.swgl.core.level;
2021
exports org.overrun.swgl.core.model;

src/main/java/org/overrun/swgl/core/GlfwApplication.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public void boot() {
8989
prepare();
9090
if (!glfwInit())
9191
throw new IllegalStateException("Unable to initialize GLFW");
92-
preStart();
9392

9493
// Setup window
9594
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);//todo add to config
@@ -101,6 +100,7 @@ public void boot() {
101100
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
102101
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
103102
}
103+
preStart();
104104
window = new Window();
105105
window.createHandle(initialWidth, initialHeight, initialTitle);
106106
long hWnd = window.getHandle();
@@ -123,6 +123,7 @@ public void boot() {
123123
glfwSetWindowFocusCallback(hWnd, (handle, focused) -> {
124124
if (!focused) mouse.firstFocus = true;
125125
});
126+
glfwSetScrollCallback(hWnd, (handle, xoffset, yoffset) -> onScroll(xoffset, yoffset));
126127

127128
timer = new Timer();
128129
glfwMakeContextCurrent(hWnd);
@@ -230,6 +231,15 @@ public void onMouseBtnPress(int btn, int mods) {
230231
public void onMouseBtnRelease(int btn, int mods) {
231232
}
232233

234+
/**
235+
* Will be called when a scrolling device is used, such as a mouse wheel or scrolling area of a touchpad.
236+
*
237+
* @param xoffset the scroll offset along the x-axis
238+
* @param yoffset the scroll offset along the y-axis
239+
*/
240+
public void onScroll(double xoffset, double yoffset) {
241+
}
242+
233243
/**
234244
* Called on setting {@link #frames}.
235245
*/

src/main/java/org/overrun/swgl/core/gl/GLStateMgr.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public static void init() {
7070
maxTextureImageUnits = glGetInteger(GL_MAX_TEXTURE_IMAGE_UNITS);
7171
texture2dId = new int[maxCombinedTextureImageUnits];
7272
texture2DStates = new GLTextureState[maxCombinedTextureImageUnits];
73+
for (int i = 0; i < maxCombinedTextureImageUnits; i++) {
74+
texture2DStates[i] = new GLTextureState(GL_TEXTURE_2D);
75+
}
7376
}
7477
}
7578

@@ -91,6 +94,18 @@ public static int getMaxTexImgUnits() {
9194
return maxTextureImageUnits;
9295
}
9396

97+
public static void enableTexture2D() {
98+
texture2DStates[activeTexture].enable();
99+
}
100+
101+
public static void disableTexture2D() {
102+
texture2DStates[activeTexture].disable();
103+
}
104+
105+
public static boolean isTexture2dEnabled(int unit) {
106+
return texture2DStates[unit].isEnabled();
107+
}
108+
94109
/**
95110
* Binds a 2D texture to the active texture unit.
96111
*
@@ -286,11 +301,27 @@ public static void disableBlend() {
286301
* @param dfactor The blend dst factor both RGB and alpha
287302
*/
288303
public static void blendFunc(int sfactor, int dfactor) {
289-
if (blendSFactorRGB != sfactor && blendSFactorAlpha != sfactor
290-
&& blendDFactorRGB != dfactor && blendDFactorAlpha != dfactor) {
304+
if (blendSFactorRGB != sfactor || blendSFactorAlpha != sfactor
305+
|| blendDFactorRGB != dfactor || blendDFactorAlpha != dfactor) {
291306
blendSFactorRGB = blendSFactorAlpha = sfactor;
292307
blendDFactorRGB = blendDFactorAlpha = dfactor;
293308
glBlendFunc(sfactor, dfactor);
294309
}
295310
}
311+
312+
public static void blendFuncSeparate(
313+
int sfactorRGB,
314+
int dfactorRGB,
315+
int sfactorAlpha,
316+
int dfactorAlpha
317+
) {
318+
if (blendSFactorRGB != sfactorRGB || blendSFactorAlpha != sfactorAlpha
319+
|| blendDFactorRGB != dfactorRGB || blendDFactorAlpha != dfactorAlpha) {
320+
blendSFactorRGB = sfactorRGB;
321+
blendSFactorAlpha = sfactorAlpha;
322+
blendDFactorRGB = dfactorRGB;
323+
blendDFactorAlpha = dfactorAlpha;
324+
glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
325+
}
326+
}
296327
}

src/main/java/org/overrun/swgl/core/gl/GLTextureState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public int getType() {
4040
return type;
4141
}
4242

43-
public void enabled() {
43+
public void enable() {
4444
enabled = true;
4545
}
4646

47-
public void disabled() {
47+
public void disable() {
4848
enabled = false;
4949
}
5050

0 commit comments

Comments
 (0)