internal/graphicsdriver/playstation5: add ebitengine_IsErrorNil

This commit is contained in:
Hajime Hoshi 2024-01-21 23:54:02 +09:00
parent e0ccd013ac
commit f0509096f8
2 changed files with 10 additions and 4 deletions

View File

@ -53,7 +53,7 @@ func NewGraphics() (*Graphics, error) {
}
func (g *Graphics) Initialize() error {
if err := C.ebitengine_InitializeGraphics(); err.message != nil {
if err := C.ebitengine_InitializeGraphics(); !C.ebitengine_IsErrorNil(&err) {
return newPlaystation5Error("(*playstation5.Graphics).Initialize", err)
}
return nil
@ -76,7 +76,7 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint32) error {
func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
var id C.int
if err := C.ebitengine_NewImage(&id, C.int(width), C.int(height)); err.message != nil {
if err := C.ebitengine_NewImage(&id, C.int(width), C.int(height)); !C.ebitengine_IsErrorNil(&err) {
return nil, newPlaystation5Error("(*playstation5.Graphics).NewImage", err)
}
return &Image{
@ -86,7 +86,7 @@ func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
func (g *Graphics) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) {
var id C.int
if err := C.ebitengine_NewScreenFramebufferImage(&id, C.int(width), C.int(height)); err.message != nil {
if err := C.ebitengine_NewScreenFramebufferImage(&id, C.int(width), C.int(height)); !C.ebitengine_IsErrorNil(&err) {
return nil, newPlaystation5Error("(*playstation5.Graphics).NewScreenFramebufferImage", err)
}
return &Image{
@ -108,7 +108,7 @@ func (g *Graphics) MaxImageSize() int {
func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader, error) {
var id C.int
// TODO: Give a source code.
if err := C.ebitengine_NewShader(&id, nil); err.message != nil {
if err := C.ebitengine_NewShader(&id, nil); !C.ebitengine_IsErrorNil(&err) {
return nil, newPlaystation5Error("(*playstation5.Graphics).NewShader", err)
}
return &Shader{

View File

@ -14,6 +14,8 @@
//go:build playstation5
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -23,6 +25,10 @@ typedef struct ebitengine_Error {
int code;
} ebitengine_Error;
bool ebitengine_IsErrorNil(ebitengine_Error* err) {
return err->message == NULL && err->code == 0;
}
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);