Skip to content

Commit

Permalink
Merge pull request #37 from thara/add_undefined_filter
Browse files Browse the repository at this point in the history
Add undefined magFilter/magFilter values for sampler
  • Loading branch information
qmuntal committed Mar 13, 2021
2 parents beab0a2 + 62bfb20 commit 58807b5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
8 changes: 6 additions & 2 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ func (a *AlphaMode) MarshalJSON() ([]byte, error) {
type MagFilter uint16

const (
// MagUndefined indicates to not specified any magnification filters.
MagUndefined MagFilter = iota
// MagLinear corresponds to a linear magnification filter.
MagLinear MagFilter = iota
MagLinear
// MagNearest corresponds to a nearest magnification filter.
MagNearest
)
Expand Down Expand Up @@ -291,8 +293,10 @@ func (m *MagFilter) MarshalJSON() ([]byte, error) {
type MinFilter uint16

const (
// MinUndefined indicates to not specified any minification filters.
MinUndefined MinFilter = iota
// MinLinear corresponds to a linear minification filter.
MinLinear MinFilter = iota
MinLinear
// MinNearestMipMapLinear corresponds to a nearest mipmap linear minification filter.
MinNearestMipMapLinear
// MinNearest corresponds to a nearest minification filter.
Expand Down
30 changes: 30 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gltf

import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"reflect"
Expand Down Expand Up @@ -285,3 +286,32 @@ func TestDecoder_validateDocumentQuotas(t *testing.T) {
})
}
}

func TestSampler_Decode(t *testing.T) {

tests := []struct {
name string
s []byte
want *Sampler
wantErr bool
}{
{"empty", []byte(`{}`), &Sampler{}, false},
{"nondefault",
[]byte(`{"minFilter":9728,"wrapT":33071}`),
&Sampler{MagFilter: MagUndefined, MinFilter: MinNearest, WrapS: WrapRepeat, WrapT: WrapClampToEdge},
false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got Sampler
err := json.Unmarshal(tt.s, &got)
if (err != nil) != tt.wantErr {
t.Errorf("Unmarshaling Sampler error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(&got, tt.want) {
t.Errorf("Unmarshaling Sampler = %v, want %v", string(tt.s), tt.want)
}
})
}
}
27 changes: 27 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,33 @@ func TestCamera_MarshalJSON(t *testing.T) {
}
}

func TestSampler_Encode(t *testing.T) {
tests := []struct {
name string
s *Sampler
want []byte
wantErr bool
}{
{"default", &Sampler{MagFilter: 0, MinFilter: 0, WrapS: 0, WrapT: 0}, []byte(`{}`), false},
{"empty", &Sampler{}, []byte(`{}`), false},
{"nondefault",
&Sampler{MagFilter: MagLinear, MinFilter: MinNearest, WrapS: WrapRepeat, WrapT: WrapClampToEdge},
[]byte(`{"magFilter":9729,"minFilter":9728,"wrapT":33071}`), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := json.Marshal(tt.s)
if (err != nil) != tt.wantErr {
t.Errorf("Material.MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Material.MarshalJSON() = %v, want %v", string(got), string(tt.want))
}
})
}
}

type fakeExt struct {
A int `json:"a"`
}
Expand Down

0 comments on commit 58807b5

Please sign in to comment.