Skip to content

Commit cab576e

Browse files
TextureQuad base implementation
1 parent 9520a4b commit cab576e

File tree

5 files changed

+885
-11
lines changed

5 files changed

+885
-11
lines changed

worldwind-tutorials/src/commonMain/kotlin/earth.worldwind.tutorials/SurfaceImageTutorial.kt

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,45 @@ import earth.worldwind.geom.Sector
88
import earth.worldwind.layer.RenderableLayer
99
import earth.worldwind.render.image.ImageSource
1010
import earth.worldwind.shape.SurfaceImage
11+
import earth.worldwind.geom.Position
12+
import earth.worldwind.shape.TextureQuad
13+
import earth.worldwind.shape.ShapeAttributes
1114

1215
class SurfaceImageTutorial(private val engine: WorldWind) : AbstractTutorial() {
1316

1417
private val layer = RenderableLayer("Surface image").apply {
1518
// Configure a Surface Image to display an Android resource showing the WorldWindEarth logo.
19+
val sector1 = Sector.fromDegrees(37.46, 15.5, 0.5, 0.6)
20+
val sector2 = Sector.fromDegrees(36.46, 14.5, 1.5, 1.9)
1621
addRenderable(
17-
SurfaceImage(
18-
Sector.fromDegrees(37.46, 15.5, 0.5, 0.6),
19-
ImageSource.fromResource(MR.images.worldwind_logo)
20-
)
22+
TextureQuad(
23+
listOf(
24+
Position(sector2.minLatitude, sector2.minLongitude, 0.0),
25+
Position(sector2.minLatitude, sector2.maxLongitude, 0.0),
26+
Position(sector1.maxLatitude, sector1.maxLongitude, 0.0),
27+
Position(sector1.maxLatitude, sector1.minLongitude, 0.0),
28+
),
29+
ShapeAttributes().apply { interiorImageSource = ImageSource.fromUrlString("https://worldwind.arc.nasa.gov/android/tutorials/data/etna.jpg") }
30+
).apply {
31+
altitudeMode = AltitudeMode.CLAMP_TO_GROUND
32+
isFollowTerrain = true
33+
}
2134
)
2235

23-
// Configure a Surface Image to display a remote image showing Mount Etna erupting on July 13th, 2001.
24-
addRenderable(
25-
SurfaceImage(
26-
Sector.fromDegrees(37.46543388598137, 14.60128369746704, 0.45360804083528, 0.75704283995502),
27-
ImageSource.fromUrlString("https://worldwind.arc.nasa.gov/android/tutorials/data/etna.jpg")
28-
)
29-
)
36+
// addRenderable(
37+
// SurfaceImage(
38+
// Sector.fromDegrees(37.46, 15.5, 0.5, 0.6),
39+
// ImageSource.fromResource(MR.images.worldwind_logo)
40+
// )
41+
// )
42+
//
43+
// // Configure a Surface Image to display a remote image showing Mount Etna erupting on July 13th, 2001.
44+
// addRenderable(
45+
// SurfaceImage(
46+
// Sector.fromDegrees(37.46543388598137, 14.60128369746704, 0.45360804083528, 0.75704283995502),
47+
// ImageSource.fromUrlString("https://worldwind.arc.nasa.gov/android/tutorials/data/etna.jpg")
48+
// )
49+
// )
3050
}
3151

3252
override fun start() {
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package earth.worldwind.draw
2+
3+
import earth.worldwind.geom.Matrix3
4+
import earth.worldwind.geom.Matrix4
5+
import earth.worldwind.geom.Vec2
6+
import earth.worldwind.geom.Vec3
7+
import earth.worldwind.render.Color
8+
import earth.worldwind.render.Texture
9+
import earth.worldwind.render.buffer.BufferObject
10+
import earth.worldwind.render.program.AbstractShaderProgram
11+
12+
open class DrawQuadState internal constructor() {
13+
companion object {
14+
const val MAX_DRAW_ELEMENTS = 5
15+
}
16+
17+
var programDrawToTexture: AbstractShaderProgram? = null
18+
var programDrawTextureToTerrain: AbstractShaderProgram? = null
19+
var vertexBuffer: BufferObject? = null
20+
var elementBuffer: BufferObject? = null
21+
val vertexOrigin = Vec3()
22+
23+
var A = Vec2()
24+
var B = Vec2()
25+
var C = Vec2()
26+
var D = Vec2()
27+
var vertexStride = 0
28+
var enableCullFace = true
29+
var enableDepthTest = true
30+
var enableLighting = false
31+
var depthOffset = 0.0
32+
val color = Color()
33+
var opacity = 1.0f
34+
var texture: Texture? = null
35+
var textureLod = 0
36+
val texCoordMatrix = Matrix3()
37+
val texCoordAttrib = VertexAttrib()
38+
internal var primCount = 0
39+
internal val prims = Array(MAX_DRAW_ELEMENTS) { DrawElements() }
40+
41+
open fun reset() {
42+
programDrawToTexture = null
43+
programDrawTextureToTerrain = null
44+
vertexBuffer = null
45+
elementBuffer = null
46+
vertexOrigin.set(0.0, 0.0, 0.0)
47+
vertexStride = 0
48+
enableCullFace = true
49+
enableDepthTest = true
50+
enableLighting = false
51+
depthOffset = 0.0
52+
color.set(1f, 1f, 1f, 1f)
53+
opacity = 1.0f
54+
texture = null
55+
textureLod = 0
56+
texCoordMatrix.setToIdentity()
57+
texCoordAttrib.size = 0
58+
texCoordAttrib.offset = 0
59+
primCount = 0
60+
A.set(0.0, 0.0)
61+
B.set(0.0, 0.0)
62+
C.set(0.0, 0.0)
63+
D.set(0.0, 0.0)
64+
65+
for (idx in 0 until MAX_DRAW_ELEMENTS) prims[idx].texture = null
66+
}
67+
68+
open fun drawElements(mode: Int, count: Int, type: Int, offset: Int) {
69+
val prim = prims[primCount++]
70+
prim.mode = mode
71+
prim.count = count
72+
prim.type = type
73+
prim.offset = offset
74+
prim.color.copy(color)
75+
prim.opacity = opacity
76+
prim.depthOffset = depthOffset
77+
prim.texture = texture
78+
prim.textureLod = textureLod
79+
prim.texCoordMatrix.copy(texCoordMatrix)
80+
prim.texCoordAttrib.copy(texCoordAttrib)
81+
prim.A.copy(A)
82+
prim.B.copy(B)
83+
prim.C.copy(C)
84+
prim.D.copy(D)
85+
}
86+
87+
internal open class DrawElements {
88+
var mode = 0
89+
var count = 0
90+
var type = 0
91+
var offset = 0
92+
val color = Color()
93+
var opacity = 1.0f
94+
var depthOffset = 0.0
95+
var texture: Texture? = null
96+
var textureLod = 0
97+
val texCoordMatrix = Matrix3()
98+
val texCoordAttrib = VertexAttrib()
99+
100+
var A = Vec2()
101+
var B = Vec2()
102+
var C = Vec2()
103+
var D = Vec2()
104+
}
105+
106+
open class VertexAttrib {
107+
var size = 0
108+
var offset = 0
109+
110+
fun copy(attrib: VertexAttrib) {
111+
size = attrib.size
112+
offset = attrib.offset
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)