mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-20 16:54:25 +00:00
* Follow Go standard for naming constants * Use reformatted pixFormats for Libretro cores * Use OpenGL 2.1 Core profile bindings for render instead 4.1 * Cleanup the code * SDL attributes should be set before the sdl.Init call * Use simple vertical frame flip function instead imaging lib with OpenGL renderer * Use the separate control flow for the macOS OpenGL context handling * Add OpenGL pixel type/format switch based on cores callback * Use unified log instead of fmt * Clean code * Remove unnecessary SDL init flag * Printout errors with SDL / OpenGL functions * Add CGO Libretro logging output * Use main thread lock for windows and OpenGL context * Remove Darwin OS switch * Add extended OpenGL version info print * Update Libretro cores info print * Add game library module (#232) * Add game library * Add missing local game lib files * Add missing return statement * Use v2 suffix * Bump the dependencies * Update Libretro modules to support headless test runners * Port old savestates tests as example for Libretro cores runner testing * Add n64 core example game and a test * Update room tests for various games * Add frame dump support for CI builds * Add frame rendering to image output for core testing * Update ROM frame exporter in tests * Disable Docker image publishing * Add frame rendering output for non-gl cores for CI * Add auto GL context override for headless, gpu-less machines (e.g. Github CI Xeon) * Add Windows CI headless cores frame render config * Add missing Mesa OpenGL drivers to Ubuntu CI * Add mupen n64 core download into CI tests * Add Linux, macOS, Windows core frame render tests into CI * Remove unnecessary var * Add some comments * Revert Y flip * Move OpenGL into a separate package * Add SDL package * Update modules
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package image
|
|
|
|
import (
|
|
"image"
|
|
)
|
|
|
|
type imageCache struct {
|
|
image *image.RGBA
|
|
w int
|
|
h int
|
|
}
|
|
|
|
var canvas = imageCache{
|
|
image.NewRGBA(image.Rectangle{}),
|
|
0,
|
|
0,
|
|
}
|
|
|
|
func DrawRgbaImage(pixFormat Format, rotationFn Rotate, scaleType int, flipV bool, w, h, packedW, bpp int, data []byte, dest *image.RGBA) {
|
|
if pixFormat == nil {
|
|
dest = nil
|
|
}
|
|
|
|
// !to implement own image interfaces img.Pix = bytes[]
|
|
ww, hh := w, h
|
|
if rotationFn.IsEven {
|
|
ww, hh = hh, ww
|
|
}
|
|
src := getCanvas(ww, hh)
|
|
|
|
drawImage(pixFormat, w, h, packedW, bpp, flipV, rotationFn, data, src)
|
|
Resize(scaleType, src, dest)
|
|
}
|
|
|
|
func drawImage(toRGBA Format, w, h, packedW, bpp int, flipV bool, rotationFn Rotate, data []byte, image *image.RGBA) {
|
|
for y := 0; y < h; y++ {
|
|
yy := y
|
|
if flipV {
|
|
yy = (h - 1) - y
|
|
}
|
|
for x := 0; x < w; x++ {
|
|
src := toRGBA(data, (x+y*packedW)*bpp)
|
|
dx, dy := rotationFn.Call(x, yy, w, h)
|
|
i := dx*4 + dy*image.Stride
|
|
dst := image.Pix[i : i+4 : i+4]
|
|
dst[0] = src.R
|
|
dst[1] = src.G
|
|
dst[2] = src.B
|
|
dst[3] = src.A
|
|
}
|
|
}
|
|
}
|
|
|
|
func getCanvas(w, h int) *image.RGBA {
|
|
if canvas.w == w && canvas.h == h {
|
|
return canvas.image
|
|
}
|
|
|
|
canvas.w, canvas.h = w, h
|
|
canvas.image = image.NewRGBA(image.Rect(0, 0, w, h))
|
|
|
|
return canvas.image
|
|
}
|