func (s *openGLState) reset(context *context) error {
	if err := context.reset(); err != nil {
		return err
	}

	s.lastProgram = zeroProgram
	s.lastViewportWidth = 0
	s.lastViewportHeight = 0
	s.lastColorMatrix = nil
	s.lastColorMatrixTranslation = nil
	s.lastSourceWidth = 0
	s.lastSourceHeight = 0
	s.lastFilter = nil
	s.lastAddress = nil

	// When context lost happens, deleting programs or buffers is not necessary.
	// However, it is not assumed that reset is called only when context lost happens.
	// Let's delete them explicitly.
	if s.programs == nil {
		s.programs = map[programKey]program{}
	} else {
		for k, p := range s.programs {
			context.deleteProgram(p)
			delete(s.programs, k)
		}
	}

	// On browsers (at least Chrome), buffers are already detached from the context
	// and must not be deleted by DeleteBuffer.
	if !web.IsBrowser() {
		if s.arrayBuffer != zeroBuffer {
			context.deleteBuffer(s.arrayBuffer)
		}
		if s.elementArrayBuffer != zeroBuffer {
			context.deleteBuffer(s.elementArrayBuffer)
		}
	}

	shaderVertexModelviewNative, err := context.newShader(vertexShader, vertexShaderStr())
	if err != nil {
		panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
	}
	defer context.deleteShader(shaderVertexModelviewNative)

	for _, c := range []bool{false, true} {
		for _, a := range []graphics.Address{
			graphics.AddressClampToZero,
			graphics.AddressRepeat,
		} {
			for _, f := range []graphics.Filter{
				graphics.FilterNearest,
				graphics.FilterLinear,
				graphics.FilterScreen,
			} {
				shaderFragmentColorMatrixNative, err := context.newShader(fragmentShader, fragmentShaderStr(c, f, a))
				if err != nil {
					panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
				}
				defer context.deleteShader(shaderFragmentColorMatrixNative)

				program, err := context.newProgram([]shader{
					shaderVertexModelviewNative,
					shaderFragmentColorMatrixNative,
				}, theArrayBufferLayout.names())

				if err != nil {
					return err
				}

				s.programs[programKey{
					useColorM: c,
					filter:    f,
					address:   a,
				}] = program
			}
		}
	}

	s.arrayBuffer = theArrayBufferLayout.newArrayBuffer(context)

	// Note that the indices passed to NewElementArrayBuffer is not under GC management
	// in opengl package due to unsafe-way.
	// See NewElementArrayBuffer in context_mobile.go.
	s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesNum * 2)

	return nil
}
func (s *openGLState) reset(context *context) error {
	if err := context.reset(); err != nil {
		return err
	}

	s.lastProgram = zeroProgram
	s.lastViewportWidth = 0
	s.lastViewportHeight = 0
	s.lastColorMatrix = nil
	s.lastColorMatrixTranslation = nil
	s.lastSourceWidth = 0
	s.lastSourceHeight = 0
	s.lastFilter = nil
	s.lastAddress = nil

	
	
	
	if s.programs == nil {
		s.programs = map[programKey]program{}
	} else {
		for k, p := range s.programs {
			context.deleteProgram(p)
			delete(s.programs, k)
		}
	}

	
	
	if !web.IsBrowser() {
		if s.arrayBuffer != zeroBuffer {
			context.deleteBuffer(s.arrayBuffer)
		}
		if s.elementArrayBuffer != zeroBuffer {
			context.deleteBuffer(s.elementArrayBuffer)
		}
	}

	shaderVertexModelviewNative, err := context.newShader(vertexShader, vertexShaderStr())
	if err != nil {
		panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
	}
	defer context.deleteShader(shaderVertexModelviewNative)

	for _, c := range []bool{false, true} {
		for _, a := range []graphics.Address{
			graphics.AddressClampToZero,
			graphics.AddressRepeat,
		} {
			for _, f := range []graphics.Filter{
				graphics.FilterNearest,
				graphics.FilterLinear,
				graphics.FilterScreen,
			} {
				shaderFragmentColorMatrixNative, err := context.newShader(fragmentShader, fragmentShaderStr(c, f, a))
				if err != nil {
					panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
				}
				defer context.deleteShader(shaderFragmentColorMatrixNative)

				program, err := context.newProgram([]shader{
					shaderVertexModelviewNative,
					shaderFragmentColorMatrixNative,
				}, theArrayBufferLayout.names())

				if err != nil {
					return err
				}

				s.programs[programKey{
					useColorM: c,
					filter:    f,
					address:   a,
				}] = program
			}
		}
	}

	s.arrayBuffer = theArrayBufferLayout.newArrayBuffer(context)

	
	
	
	s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesNum * 2)

	return nil
}
func ( s * openGLState ) reset ( context * context ) error { if err := context . reset ( ) ; err != nil { return err } s . lastProgram = zeroProgram s . lastViewportWidth = 0 s . lastViewportHeight = 0 s . lastColorMatrix = nil s . lastColorMatrixTranslation = nil s . lastSourceWidth = 0 s . lastSourceHeight = 0 s . lastFilter = nil s . lastAddress = nil // When context lost happens, deleting programs or buffers is not necessary. // However, it is not assumed that reset is called only when context lost happens. // Let's delete them explicitly. if s . programs == nil { s . programs = map [ programKey ] program { } } else { for k , p := range s . programs { context . deleteProgram ( p ) delete ( s . programs , k ) } } // On browsers (at least Chrome), buffers are already detached from the context // and must not be deleted by DeleteBuffer. if ! web . IsBrowser ( ) { if s . arrayBuffer != zeroBuffer { context . deleteBuffer ( s . arrayBuffer ) } if s . elementArrayBuffer != zeroBuffer { context . deleteBuffer ( s . elementArrayBuffer ) } } shaderVertexModelviewNative , err := context . newShader ( vertexShader , vertexShaderStr ( ) ) if err != nil { panic ( fmt . Sprintf ( " \n " , err ) ) } defer context . deleteShader ( shaderVertexModelviewNative ) for _ , c := range [ ] bool { false , true } { for _ , a := range [ ] graphics . Address { graphics . AddressClampToZero , graphics . AddressRepeat , } { for _ , f := range [ ] graphics . Filter { graphics . FilterNearest , graphics . FilterLinear , graphics . FilterScreen , } { shaderFragmentColorMatrixNative , err := context . newShader ( fragmentShader , fragmentShaderStr ( c , f , a ) ) if err != nil { panic ( fmt . Sprintf ( " \n " , err ) ) } defer context . deleteShader ( shaderFragmentColorMatrixNative ) program , err := context . newProgram ( [ ] shader { shaderVertexModelviewNative , shaderFragmentColorMatrixNative , } , theArrayBufferLayout . names ( ) ) if err != nil { return err } s . programs [ programKey { useColorM : c , filter : f , address : a , } ] = program } } } s . arrayBuffer = theArrayBufferLayout . newArrayBuffer ( context ) // Note that the indices passed to NewElementArrayBuffer is not under GC management // in opengl package due to unsafe-way. // See NewElementArrayBuffer in context_mobile.go. s . elementArrayBuffer = context . newElementArrayBuffer ( graphics . IndicesNum * 2 ) return nil }
// reset resets or initializes the OpenGL state.
reset resets or initializes the OpenGL state .