Skip to content

Commit

Permalink
Fix Line Stipple texture rendering - WebGl 1.0 does not support REPEA…
Browse files Browse the repository at this point in the history
…T for NPOT textures.
  • Loading branch information
EMaksymenko committed Mar 5, 2025
1 parent c4884d4 commit e053a9f
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.icerock.moko.resources.ImageResource
import earth.worldwind.util.AbstractSource
import earth.worldwind.util.Logger.ERROR
import earth.worldwind.util.Logger.logMessage
import earth.worldwind.util.math.powerOfTwoCeiling
import kotlinx.browser.document
import org.khronos.webgl.TexImageSource
import org.w3c.dom.CanvasRenderingContext2D
Expand Down Expand Up @@ -192,6 +193,8 @@ actual open class ImageSource protected constructor(source: Any): AbstractSource

protected open class LineStippleImageFactory(protected val factor: Int, protected val pattern: Short): ImageFactory {
override fun createImage(): TexImageSource {
// https://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support
val factor = powerOfTwoCeiling(factor) // WebGl 1.0 does not support REPEAT for NPOT textures
val canvas = document.createElement("canvas") as HTMLCanvasElement
canvas.width = if (factor <= 0) 16 else factor * 16
canvas.height = 1
Expand Down

0 comments on commit e053a9f

Please # to comment.