Skip to content

Commit 07926f5

Browse files
committed
Merge upstream 'v147' into be
2 parents 9d15e7f + fc46b1c commit 07926f5

File tree

21 files changed

+89
-97
lines changed

21 files changed

+89
-97
lines changed

arc-core/src/arc/graphics/Cubemap.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public enum CubemapSide{
119119
/** The negative Z and sixth side of the cubemap */
120120
negativeZ(5, GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, -1, 0, 0, 0, -1);
121121

122+
/** Cached {@link CubemapSide#values()} for performance and ergonomics. */
123+
public static final CubemapSide[] all = values();
124+
122125
/** The zero based index of the side in the cubemap */
123126
public final int index;
124127
/** The OpenGL target (used for glTexImage2D) of the side. */

arc-core/src/arc/graphics/Gl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ public class Gl{
323323
//STATE - optimizes GL calls
324324

325325
private static IntBuffer ibuf = Buffers.newIntBuffer(1);
326+
private static FloatBuffer fbuf = Buffers.newFloatBuffer(1);
326327
//last active texture unit
327328
private static int lastActiveTexture = -1;
328329
//last bound texture2ds, mapping from texture unit to texture handle
@@ -498,6 +499,12 @@ public static int getInt(int name){
498499
return ibuf.get(0);
499500
}
500501

502+
public static float getFloat(int name){
503+
fbuf.position(0);
504+
getFloatv(name, fbuf);
505+
return fbuf.get(0);
506+
}
507+
501508
public static String getString(int name){
502509
return Core.gl.glGetString(name);
503510
}

arc-core/src/arc/graphics/Pixmap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,10 +898,10 @@ public void update(){
898898
//RGB images are generally uncommon and the memory savings don't really matter; formats have to be converted to RGBA for drawing anyway
899899
const unsigned char* pixels = stbi_load_from_memory(p_buffer + offset, len, &width, &height, &format, STBI_rgb_alpha);
900900
901-
if(pixels == NULL) return NULL;
902-
903901
env->ReleasePrimitiveArrayCritical(buffer, (char*)p_buffer, 0);
904902
903+
if(pixels == NULL) return NULL;
904+
905905
jobject pixel_buffer = env->NewDirectByteBuffer((void*)pixels, width * height * 4);
906906
jlong* p_native_data = (jlong*)env->GetPrimitiveArrayCritical(nativeData, 0);
907907
p_native_data[0] = (jlong)pixels;

arc-core/src/arc/graphics/g2d/DrawRequest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

arc-core/src/arc/graphics/g2d/Fill.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,25 @@ public static void light(float x, float y, int sides, float radius, float rotati
190190
}
191191
}
192192

193+
public static void lightInner(float x, float y, int sides, float innerRadius, float radius, float rotation, Color center, Color edge){
194+
float centerf = center.toFloatBits(), edgef = edge.toFloatBits();
195+
196+
float space = 360f / sides;
197+
198+
for(int i = 0; i < sides; i ++){
199+
float px = Angles.trnsx(space * i + rotation, radius);
200+
float py = Angles.trnsy(space * i + rotation, radius);
201+
float px2 = Angles.trnsx(space * (i + 1) + rotation, radius);
202+
float py2 = Angles.trnsy(space * (i + 1) + rotation, radius);
203+
quad(
204+
x + Angles.trnsx(space * i + rotation, innerRadius), y + Angles.trnsy(space * i + rotation, innerRadius), centerf,
205+
x + px, y + py, edgef,
206+
x + px2, y + py2, edgef,
207+
x + Angles.trnsx(space * (i+1) + rotation, innerRadius), y + Angles.trnsy(space * (i+1) + rotation, innerRadius), centerf
208+
);
209+
}
210+
}
211+
193212
public static void polyBegin(){
194213
polyFloats.clear();
195214
}
@@ -263,7 +282,7 @@ public static void poly(float x, float y, int sides, float radius, float rotatio
263282
tri(x, y, x + px, y + py, x + px2, y + py2);
264283
}
265284
}
266-
285+
267286
public static void arc(float x, float y, float radius, float fraction){
268287
arc(x, y, radius, fraction, 0f);
269288
}
@@ -276,7 +295,7 @@ public static void arc(float x, float y, float radius, float fraction, float rot
276295
int max = Mathf.ceil(sides * fraction);
277296
polyBegin();
278297
polyPoint(x, y);
279-
298+
280299
for(int i = 0; i <= max; i++){
281300
float a = (float)i / max * fraction * 360f + rotation;
282301
float x1 = Angles.trnsx(a, radius);
@@ -285,7 +304,7 @@ public static void arc(float x, float y, float radius, float fraction, float rot
285304
polyPoint(x + x1, y + y1);
286305
}
287306
polyPoint(x, y);
288-
307+
289308
polyEnd();
290309
}
291310

arc-core/src/arc/graphics/gl/FrameBuffer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ protected Texture createTexture(FrameBufferTextureAttachmentSpec attachmentSpec)
139139
}
140140

141141
@Override
142-
protected void disposeColorTexture(Texture colorTexture){
142+
protected void disposeTexture(Texture colorTexture){
143143
colorTexture.dispose();
144144
}
145145

146146
@Override
147-
protected void attachFrameBufferColorTexture(Texture texture){
148-
Gl.framebufferTexture2D(Gl.framebuffer, GL20.GL_COLOR_ATTACHMENT0, GL20.GL_TEXTURE_2D, texture.getTextureObjectHandle(), 0);
147+
protected void attachTexture(int attachment, Texture texture){
148+
Gl.framebufferTexture2D(Gl.framebuffer, attachment, Gl.texture2d, texture.getTextureObjectHandle(), 0);
149149
}
150150
}

arc-core/src/arc/graphics/gl/FrameBufferCubemap.java

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package arc.graphics.gl;
22

3+
import arc.func.*;
34
import arc.graphics.*;
45
import arc.graphics.Cubemap.*;
56
import arc.graphics.Texture.*;
@@ -40,14 +41,6 @@
4041
* @author realitix
4142
*/
4243
public class FrameBufferCubemap extends GLFrameBuffer<Cubemap>{
43-
/** cubemap sides cache */
44-
private static final Cubemap.CubemapSide[] cubemapSides = Cubemap.CubemapSide.values();
45-
/** the zero-based index of the active side **/
46-
private int currentSide;
47-
48-
FrameBufferCubemap(){
49-
}
50-
5144
/**
5245
* Creates a GLFrameBuffer from the specifications provided by bufferBuilder
5346
**/
@@ -93,55 +86,30 @@ protected Cubemap createTexture(FrameBufferTextureAttachmentSpec attachmentSpec)
9386
}
9487

9588
@Override
96-
protected void disposeColorTexture(Cubemap colorTexture){
89+
protected void disposeTexture(Cubemap colorTexture){
9790
colorTexture.dispose();
9891
}
9992

10093
@Override
101-
protected void attachFrameBufferColorTexture(Cubemap texture){
94+
protected void attachTexture(int attachment, Cubemap texture){
10295
int glHandle = texture.getTextureObjectHandle();
103-
CubemapSide[] sides = CubemapSide.values();
104-
for(CubemapSide side : sides){
105-
Gl.framebufferTexture2D(Gl.framebuffer, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, glHandle, 0);
96+
for(CubemapSide side : CubemapSide.all){
97+
Gl.framebufferTexture2D(Gl.framebuffer, attachment, side.glEnum, glHandle, 0);
10698
}
10799
}
108100

109-
/**
110-
* Makes the frame buffer current so everything gets drawn to it, must be followed by call to either {@link #nextSide()} or
111-
* {@link #bindSide(arc.graphics.Cubemap.CubemapSide)} to activate the side to render onto.
112-
*/
113-
@Override
114-
public void bind(){
115-
currentSide = -1;
116-
super.bind();
117-
}
118-
119-
/**
120-
* Bind the next side of cubemap and return false if no more side. Should be called in between a call to {@link #begin()} and
121-
* #end to cycle to each side of the cubemap to render on.
122-
*/
123-
public boolean nextSide(){
124-
if(currentSide > 5){
125-
throw new ArcRuntimeException("No remaining sides.");
126-
}else if(currentSide == 5){
127-
return false;
101+
/** Should be called in between a call to {@link #begin()} and {@link #end()}. */
102+
public void eachSide(Cons<CubemapSide> cons){
103+
for(CubemapSide side : CubemapSide.all){
104+
cons.get(side);
128105
}
129-
130-
currentSide++;
131-
bindSide(getSide());
132-
return true;
133106
}
134107

135108
/**
136109
* Bind the side, making it active to render on. Should be called in between a call to {@link #begin()} and {@link #end()}.
137110
* @param side The side to bind
138111
*/
139-
protected void bindSide(final Cubemap.CubemapSide side){
140-
Gl.framebufferTexture2D(Gl.framebuffer, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, getTexture().getTextureObjectHandle(), 0);
141-
}
142-
143-
/** Get the currently bound side. */
144-
public Cubemap.CubemapSide getSide(){
145-
return currentSide < 0 ? null : cubemapSides[currentSide];
112+
public void bindSide(CubemapSide side){
113+
Gl.framebufferTexture2D(Gl.framebuffer, Gl.colorAttachment0, side.glEnum, getTexture().getTextureObjectHandle(), 0);
146114
}
147115
}

arc-core/src/arc/graphics/gl/GLFrameBuffer.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public abstract class GLFrameBuffer<T extends GLTexture> implements Disposable{
2929
protected final static int GL_DEPTH24_STENCIL8_OES = 0x88F0;
3030
/** the currently bound framebuffer; null for the default one. */
31-
protected static GLFrameBuffer currentBoundFramebuffer;
31+
protected static GLFrameBuffer<?> currentBoundFramebuffer;
3232
/** the default framebuffer handle, a.k.a screen. */
3333
protected static int defaultFramebufferHandle;
3434
/** # of nested buffers right now */
@@ -38,7 +38,7 @@ public abstract class GLFrameBuffer<T extends GLTexture> implements Disposable{
3838
/** the color buffer texture **/
3939
protected Seq<T> textureAttachments = new Seq<>();
4040
/** the framebuffer that was bound before this one began (null to indicate that nothing was bound) **/
41-
protected GLFrameBuffer lastBoundFramebuffer = null;
41+
protected GLFrameBuffer<?> lastBoundFramebuffer = null;
4242
/** the framebuffer handle **/
4343
protected int framebufferHandle;
4444
/** the depthbuffer render object handle **/
@@ -87,13 +87,12 @@ public Seq<T> getTextureAttachments(){
8787
protected abstract T createTexture(FrameBufferTextureAttachmentSpec attachmentSpec);
8888

8989
/** Override this method in a derived class to dispose the backing texture as you like. */
90-
protected abstract void disposeColorTexture(T colorTexture);
90+
protected abstract void disposeTexture(T colorTexture);
9191

9292
/** Override this method in a derived class to attach the backing texture to the GL framebuffer object. */
93-
protected abstract void attachFrameBufferColorTexture(T texture);
93+
protected abstract void attachTexture(int attachment, T texture);
9494

9595
protected void build(){
96-
9796
checkValidBuilder();
9897

9998
// iOS uses a different framebuffer handle! (not necessarily 0)
@@ -143,21 +142,18 @@ protected void build(){
143142
T texture = createTexture(attachmentSpec);
144143
textureAttachments.add(texture);
145144
if(attachmentSpec.isColorTexture()){
146-
Gl.framebufferTexture2D(Gl.framebuffer, GL30.GL_COLOR_ATTACHMENT0 + colorTextureCounter, GL30.GL_TEXTURE_2D,
147-
texture.getTextureObjectHandle(), 0);
145+
attachTexture(Gl.colorAttachment0 + colorTextureCounter, texture);
148146
colorTextureCounter++;
149147
}else if(attachmentSpec.isDepth){
150-
Gl.framebufferTexture2D(Gl.framebuffer, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_TEXTURE_2D,
151-
texture.getTextureObjectHandle(), 0);
148+
attachTexture(Gl.depthAttachment, texture);
152149
}else if(attachmentSpec.isStencil){
153-
Gl.framebufferTexture2D(Gl.framebuffer, GL20.GL_STENCIL_ATTACHMENT, GL20.GL_TEXTURE_2D,
154-
texture.getTextureObjectHandle(), 0);
150+
attachTexture(Gl.stencilAttachment, texture);
155151
}
156152
}
157153
}else{
158154
T texture = createTexture(bufferBuilder.textureAttachmentSpecs.first());
159155
textureAttachments.add(texture);
160-
Gl.bindTexture(texture.glTarget, texture.getTextureObjectHandle());
156+
attachTexture(Gl.colorAttachment0, texture);
161157
}
162158

163159
if(isMRT){
@@ -167,8 +163,6 @@ protected void build(){
167163
}
168164
buffer.position(0);
169165
Core.gl30.glDrawBuffers(colorTextureCounter, buffer);
170-
}else{
171-
attachFrameBufferColorTexture(textureAttachments.first());
172166
}
173167

174168
if(bufferBuilder.hasDepthRenderBuffer){
@@ -225,7 +219,7 @@ protected void build(){
225219

226220
if(result != Gl.framebufferComplete){
227221
for(T texture : textureAttachments){
228-
disposeColorTexture(texture);
222+
disposeTexture(texture);
229223
}
230224

231225
if(hasDepthStencilPackedBuffer){
@@ -277,7 +271,7 @@ private void checkValidBuilder(){
277271
@Override
278272
public void dispose(){
279273
for(T texture : textureAttachments){
280-
disposeColorTexture(texture);
274+
disposeTexture(texture);
281275
}
282276

283277
if(hasDepthStencilPackedBuffer){

arc-core/src/arc/math/geom/Geometry.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ public static void circle(int x, int y, int radius, Intc2 cons){
7171
}
7272

7373
public static void circle(int x, int y, int width, int height, int radius, Intc2 cons){
74-
for(int dx = -radius; dx <= radius; dx++){
75-
for(int dy = -radius; dy <= radius; dy++){
76-
int wx = dx + x, wy = dy + y;
77-
if(wx >= 0 && wy >= 0 && wx < width && wy < height && Mathf.within(dx, dy, radius)){
78-
cons.get(wx, wy);
74+
for(int dx = Math.max(x - radius, 0); dx <= Math.min(x + radius, width - 1); dx++){
75+
for(int dy = Math.max(y - radius, 0); dy <= Math.min(y + radius, height - 1); dy++){
76+
if(Mathf.within(dx, dy, x, y, radius)){
77+
cons.get(dx, dy);
7978
}
8079
}
8180
}

arc-core/src/arc/scene/Group.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ public Element hit(float x, float y, boolean touchable){
194194
Element[] childrenArray = children.items;
195195
for(int i = children.size - 1; i >= 0; i--){
196196
Element child = childrenArray[i];
197-
if(!child.visible) continue;
197+
//TODO: this optimization may be incorrect, needs further testing.
198+
if(!child.visible || (child.cullable && cullingArea != null && !cullingArea.overlaps(child.x + child.translation.x, child.y + child.translation.y, child.width, child.height))) continue;
198199
child.parentToLocalCoordinates(point.set(x, y));
199200
Element hit = child.hit(point.x, point.y, touchable);
200201
if(hit != null) return hit;

0 commit comments

Comments
 (0)