mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/graphicsdriver/playstation5: improve error handlings
Updates #2799
This commit is contained in:
parent
7f396f72de
commit
00e67b8419
@ -18,23 +18,23 @@
|
|||||||
|
|
||||||
#include "graphics_playstation5.h"
|
#include "graphics_playstation5.h"
|
||||||
|
|
||||||
extern "C" int ebitengine_InitializeGraphics(void) {
|
extern "C" ebitengine_Error ebitengine_InitializeGraphics(void) {
|
||||||
return 0;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int ebitengine_NewImage(int* image, int width, int height) {
|
extern "C" ebitengine_Error ebitengine_NewImage(int* image, int width, int height) {
|
||||||
return 0;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int ebitengine_NewScreenFramebufferImage(int* image, int width, int height) {
|
extern "C" ebitengine_Error ebitengine_NewScreenFramebufferImage(int* image, int width, int height) {
|
||||||
return 0;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void ebitengine_DisposeImage(int id) {
|
extern "C" void ebitengine_DisposeImage(int id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int ebitengine_NewShader(int* shader, const char* source) {
|
extern "C" ebitengine_Error ebitengine_NewShader(int* shader, const char* source) {
|
||||||
return 0;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void ebitengine_DisposeShader(int id) {
|
extern "C" void ebitengine_DisposeShader(int id) {
|
||||||
|
@ -29,11 +29,20 @@ import (
|
|||||||
|
|
||||||
type playstation5Error struct {
|
type playstation5Error struct {
|
||||||
name string
|
name string
|
||||||
code C.int
|
code int
|
||||||
|
message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPlaystation5Error(name string, err C.ebitengine_Error) *playstation5Error {
|
||||||
|
return &playstation5Error{
|
||||||
|
name: name,
|
||||||
|
code: int(err.code),
|
||||||
|
message: C.GoString(err.message),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *playstation5Error) Error() string {
|
func (e *playstation5Error) Error() string {
|
||||||
return fmt.Sprintf("playstation5: error at %s, code: %d", e.name, e.code)
|
return fmt.Sprintf("playstation5: error at %s, code: %d, message: %s", e.name, e.code, e.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Graphics struct {
|
type Graphics struct {
|
||||||
@ -44,11 +53,8 @@ func NewGraphics() (*Graphics, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) Initialize() error {
|
func (g *Graphics) Initialize() error {
|
||||||
if errCode := C.ebitengine_InitializeGraphics(); errCode != 0 {
|
if err := C.ebitengine_InitializeGraphics(); err.code != 0 {
|
||||||
return &playstation5Error{
|
return newPlaystation5Error("(*playstation5.Graphics).Initialize", err)
|
||||||
name: "(*playstation5.Graphics).Initialize",
|
|
||||||
code: errCode,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -70,11 +76,8 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint32) error {
|
|||||||
|
|
||||||
func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
|
func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
|
||||||
var id C.int
|
var id C.int
|
||||||
if errCode := C.ebitengine_NewImage(&id, C.int(width), C.int(height)); errCode != 0 {
|
if err := C.ebitengine_NewImage(&id, C.int(width), C.int(height)); err.code != 0 {
|
||||||
return nil, &playstation5Error{
|
return nil, newPlaystation5Error("(*playstation5.Graphics).NewImage", err)
|
||||||
name: "(*playstation5.Graphics).NewImage",
|
|
||||||
code: errCode,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &Image{
|
return &Image{
|
||||||
id: graphicsdriver.ImageID(id),
|
id: graphicsdriver.ImageID(id),
|
||||||
@ -83,11 +86,8 @@ func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
|
|||||||
|
|
||||||
func (g *Graphics) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) {
|
func (g *Graphics) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) {
|
||||||
var id C.int
|
var id C.int
|
||||||
if errCode := C.ebitengine_NewScreenFramebufferImage(&id, C.int(width), C.int(height)); errCode != 0 {
|
if err := C.ebitengine_NewScreenFramebufferImage(&id, C.int(width), C.int(height)); err.code != 0 {
|
||||||
return nil, &playstation5Error{
|
return nil, newPlaystation5Error("(*playstation5.Graphics).NewScreenFramebufferImage", err)
|
||||||
name: "(*playstation5.Graphics).NewScreenFramebufferImage",
|
|
||||||
code: errCode,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &Image{
|
return &Image{
|
||||||
id: graphicsdriver.ImageID(id),
|
id: graphicsdriver.ImageID(id),
|
||||||
@ -108,11 +108,8 @@ func (g *Graphics) MaxImageSize() int {
|
|||||||
func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader, error) {
|
func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader, error) {
|
||||||
var id C.int
|
var id C.int
|
||||||
// TODO: Give a source code.
|
// TODO: Give a source code.
|
||||||
if errCode := C.ebitengine_NewShader(&id, nil); errCode != 0 {
|
if err := C.ebitengine_NewShader(&id, nil); err.code != 0 {
|
||||||
return nil, &playstation5Error{
|
return nil, newPlaystation5Error("(*playstation5.Graphics).NewShader", err)
|
||||||
name: "(*playstation5.Graphics).NewShader",
|
|
||||||
code: errCode,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &Shader{
|
return &Shader{
|
||||||
id: graphicsdriver.ShaderID(id),
|
id: graphicsdriver.ShaderID(id),
|
||||||
|
@ -18,12 +18,17 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ebitengine_InitializeGraphics(void);
|
typedef struct ebitengine_Error {
|
||||||
int ebitengine_NewImage(int* image, int width, int height);
|
const char* message;
|
||||||
int ebitengine_NewScreenFramebufferImage(int* image, int width, int height);
|
int code;
|
||||||
|
} ebitengine_Error;
|
||||||
|
|
||||||
|
ebitengine_Error ebitengine_InitializeGraphics(void);
|
||||||
|
ebitengine_Error ebitengine_NewImage(int* image, int width, int height);
|
||||||
|
ebitengine_Error ebitengine_NewScreenFramebufferImage(int* image, int width, int height);
|
||||||
void ebitengine_DisposeImage(int id);
|
void ebitengine_DisposeImage(int id);
|
||||||
|
|
||||||
int ebitengine_NewShader(int* shader, const char* source);
|
ebitengine_Error ebitengine_NewShader(int* shader, const char* source);
|
||||||
void ebitengine_DisposeShader(int id);
|
void ebitengine_DisposeShader(int id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user