mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
graphicscommand: Move pixel->texel conversion to graphicscommand
This commit is contained in:
parent
915ed91f25
commit
70a38dc09a
@ -195,6 +195,14 @@ func (q *commandQueue) Flush() {
|
|||||||
for i := 0; i < q.nvertices/graphics.VertexFloatNum; i++ {
|
for i := 0; i < q.nvertices/graphics.VertexFloatNum; i++ {
|
||||||
s := q.srcSizes[i]
|
s := q.srcSizes[i]
|
||||||
|
|
||||||
|
// Convert pixels to texels.
|
||||||
|
vs[i*graphics.VertexFloatNum+2] /= s.width
|
||||||
|
vs[i*graphics.VertexFloatNum+3] /= s.height
|
||||||
|
vs[i*graphics.VertexFloatNum+4] /= s.width
|
||||||
|
vs[i*graphics.VertexFloatNum+5] /= s.height
|
||||||
|
vs[i*graphics.VertexFloatNum+6] /= s.width
|
||||||
|
vs[i*graphics.VertexFloatNum+7] /= s.height
|
||||||
|
|
||||||
// Adjust the destination position to avoid jaggy (#929).
|
// Adjust the destination position to avoid jaggy (#929).
|
||||||
// This is not a perfect solution since texels on a texture can take a position on borders
|
// This is not a perfect solution since texels on a texture can take a position on borders
|
||||||
// which can cause jaggy. But adjusting only edges should work in most cases.
|
// which can cause jaggy. But adjusting only edges should work in most cases.
|
||||||
|
@ -37,13 +37,11 @@ const (
|
|||||||
|
|
||||||
// Image represents an image that is implemented with OpenGL.
|
// Image represents an image that is implemented with OpenGL.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
image driver.Image
|
image driver.Image
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
internalWidth int
|
screen bool
|
||||||
internalHeight int
|
id int
|
||||||
screen bool
|
|
||||||
id int
|
|
||||||
|
|
||||||
lastCommand lastCommand
|
lastCommand lastCommand
|
||||||
}
|
}
|
||||||
@ -61,11 +59,9 @@ func genNextID() int {
|
|||||||
// Note that the image is not initialized yet.
|
// Note that the image is not initialized yet.
|
||||||
func NewImage(width, height int) *Image {
|
func NewImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
internalWidth: graphics.InternalImageSize(width),
|
id: genNextID(),
|
||||||
internalHeight: graphics.InternalImageSize(height),
|
|
||||||
id: genNextID(),
|
|
||||||
}
|
}
|
||||||
c := &newImageCommand{
|
c := &newImageCommand{
|
||||||
result: i,
|
result: i,
|
||||||
@ -78,12 +74,10 @@ func NewImage(width, height int) *Image {
|
|||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
internalWidth: graphics.InternalImageSize(width),
|
screen: true,
|
||||||
internalHeight: graphics.InternalImageSize(height),
|
id: genNextID(),
|
||||||
screen: true,
|
|
||||||
id: genNextID(),
|
|
||||||
}
|
}
|
||||||
c := &newScreenFramebufferImageCommand{
|
c := &newScreenFramebufferImageCommand{
|
||||||
result: i,
|
result: i,
|
||||||
@ -102,7 +96,7 @@ func (i *Image) Dispose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) InternalSize() (int, int) {
|
func (i *Image) InternalSize() (int, int) {
|
||||||
return i.internalWidth, i.internalHeight
|
return graphics.InternalImageSize(i.width), graphics.InternalImageSize(i.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawTriangles draws triangles with the given image.
|
// DrawTriangles draws triangles with the given image.
|
||||||
@ -111,12 +105,12 @@ func (i *Image) InternalSize() (int, int) {
|
|||||||
//
|
//
|
||||||
// 0: Destination X in pixels
|
// 0: Destination X in pixels
|
||||||
// 1: Destination Y in pixels
|
// 1: Destination Y in pixels
|
||||||
// 2: Source X in texels
|
// 2: Source X in pixels (not texels!)
|
||||||
// 3: Source Y in texels
|
// 3: Source Y in pixels
|
||||||
// 4: Bounds of the source min X in texels
|
// 4: Bounds of the source min X in pixels
|
||||||
// 5: Bounds of the source min Y in texels
|
// 5: Bounds of the source min Y in pixels
|
||||||
// 6: Bounds of the source max X in texels
|
// 6: Bounds of the source max X in pixels
|
||||||
// 7: Bounds of the source max Y in texels
|
// 7: Bounds of the source max Y in pixels
|
||||||
// 8: Color R [0.0-1.0]
|
// 8: Color R [0.0-1.0]
|
||||||
// 9: Color G
|
// 9: Color G
|
||||||
// 10: Color B
|
// 10: Color B
|
||||||
|
@ -206,12 +206,12 @@ func (i *Image) Clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// quadVertices returns vertices to render a quad. These values are passed to graphicscommand.Image.
|
// quadVertices returns vertices to render a quad. These values are passed to graphicscommand.Image.
|
||||||
func quadVertices(dx0, dy0, dx1, dy1, u0, v0, u1, v1, cr, cg, cb, ca float32) []float32 {
|
func quadVertices(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca float32) []float32 {
|
||||||
return []float32{
|
return []float32{
|
||||||
dx0, dy0, u0, v0, u0, v0, u1, v1, cr, cg, cb, ca,
|
dx0, dy0, sx0, sy0, sx0, sy0, sx1, sy1, cr, cg, cb, ca,
|
||||||
dx1, dy0, u1, v0, u0, v0, u1, v1, cr, cg, cb, ca,
|
dx1, dy0, sx1, sy0, sx0, sy0, sx1, sy1, cr, cg, cb, ca,
|
||||||
dx0, dy1, u0, v1, u0, v0, u1, v1, cr, cg, cb, ca,
|
dx0, dy1, sx0, sy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca,
|
||||||
dx1, dy1, u1, v1, u0, v0, u1, v1, cr, cg, cb, ca,
|
dx1, dy1, sx1, sy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +228,8 @@ func clearImage(img *graphicscommand.Image) {
|
|||||||
// The rendering target size needs to be its 'internal' size instead of the exposed size to avoid glitches on
|
// The rendering target size needs to be its 'internal' size instead of the exposed size to avoid glitches on
|
||||||
// mobile platforms (See the change 1e1f309a).
|
// mobile platforms (See the change 1e1f309a).
|
||||||
dw, dh := img.InternalSize()
|
dw, dh := img.InternalSize()
|
||||||
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, 1, 1, 0, 0, 0, 0)
|
sw, sh := emptyImage.image.InternalSize()
|
||||||
|
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, float32(sw), float32(sh), 0, 0, 0, 0)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
// The first DrawTriangles must be clear mode for initialization.
|
// The first DrawTriangles must be clear mode for initialization.
|
||||||
// TODO: Can the graphicscommand package hide this knowledge?
|
// TODO: Can the graphicscommand package hide this knowledge?
|
||||||
@ -281,7 +282,8 @@ func fillImage(i *graphicscommand.Image, clr color.RGBA) {
|
|||||||
|
|
||||||
// TODO: Integrate with clearColor
|
// TODO: Integrate with clearColor
|
||||||
dw, dh := i.InternalSize()
|
dw, dh := i.InternalSize()
|
||||||
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, 1, 1, rf, gf, bf, af)
|
sw, sh := emptyImage.image.InternalSize()
|
||||||
|
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, float32(sw), float32(sh), rf, gf, bf, af)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
i.DrawTriangles(emptyImage.image, vs, is, nil, compositemode, driver.FilterNearest, driver.AddressClampToZero)
|
i.DrawTriangles(emptyImage.image, vs, is, nil, compositemode, driver.FilterNearest, driver.AddressClampToZero)
|
||||||
@ -399,16 +401,6 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
|||||||
}
|
}
|
||||||
theImages.makeStaleIfDependingOn(i)
|
theImages.makeStaleIfDependingOn(i)
|
||||||
|
|
||||||
w, h := img.image.InternalSize()
|
|
||||||
for i := 0; i < len(vertices)/graphics.VertexFloatNum; i++ {
|
|
||||||
vertices[i*graphics.VertexFloatNum+2] /= float32(w)
|
|
||||||
vertices[i*graphics.VertexFloatNum+3] /= float32(h)
|
|
||||||
vertices[i*graphics.VertexFloatNum+4] /= float32(w)
|
|
||||||
vertices[i*graphics.VertexFloatNum+5] /= float32(h)
|
|
||||||
vertices[i*graphics.VertexFloatNum+6] /= float32(w)
|
|
||||||
vertices[i*graphics.VertexFloatNum+7] /= float32(h)
|
|
||||||
}
|
|
||||||
|
|
||||||
if img.stale || img.volatile || i.screen || !needsRestoring() || i.volatile {
|
if img.stale || img.volatile || i.screen || !needsRestoring() || i.volatile {
|
||||||
i.makeStale()
|
i.makeStale()
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user