2014-12-09 15:16:04 +01:00
|
|
|
/*
|
|
|
|
Copyright 2014 Hajime Hoshi
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-12-14 07:26:10 +01:00
|
|
|
package ebiten
|
2013-12-09 14:40:54 +01:00
|
|
|
|
2014-05-03 20:29:45 +02:00
|
|
|
import (
|
2014-12-06 07:47:48 +01:00
|
|
|
"github.com/go-gl/gl"
|
2014-12-14 07:26:10 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
2014-05-03 20:29:45 +02:00
|
|
|
)
|
2014-05-03 17:40:53 +02:00
|
|
|
|
2014-12-14 10:34:47 +01:00
|
|
|
func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsContext, error) {
|
2014-12-20 10:07:25 +01:00
|
|
|
r, err := opengl.NewZeroRenderTarget(screenWidth*screenScale, screenHeight*screenScale)
|
2014-12-19 21:22:10 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-12-09 14:40:54 +01:00
|
|
|
|
2014-12-22 02:36:42 +01:00
|
|
|
texture, err := opengl.NewTexture(screenWidth, screenHeight, gl.NEAREST)
|
2013-12-09 14:40:54 +01:00
|
|
|
if err != nil {
|
2014-12-07 20:22:50 +01:00
|
|
|
return nil, err
|
2013-12-09 14:40:54 +01:00
|
|
|
}
|
2014-12-22 02:36:42 +01:00
|
|
|
screen, err := newInnerImage(texture, gl.NEAREST)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-12-14 13:21:05 +01:00
|
|
|
c := &graphicsContext{
|
2014-12-22 02:36:42 +01:00
|
|
|
defaultR: &innerImage{r, nil},
|
2014-12-20 12:54:14 +01:00
|
|
|
screen: screen,
|
|
|
|
screenScale: screenScale,
|
2014-12-14 13:21:05 +01:00
|
|
|
}
|
2014-12-08 17:08:47 +01:00
|
|
|
return c, nil
|
2014-12-07 20:22:50 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 07:26:10 +01:00
|
|
|
type graphicsContext struct {
|
2014-12-22 02:36:42 +01:00
|
|
|
screen *innerImage
|
|
|
|
defaultR *innerImage
|
2014-12-20 12:54:14 +01:00
|
|
|
screenScale int
|
2014-12-07 16:07:36 +01:00
|
|
|
}
|
2014-01-11 03:18:55 +01:00
|
|
|
|
2014-12-14 07:26:10 +01:00
|
|
|
func (c *graphicsContext) dispose() {
|
2014-12-07 16:07:36 +01:00
|
|
|
// NOTE: Now this method is not used anywhere.
|
2014-12-22 03:14:44 +01:00
|
|
|
glRenderTarget := c.screen.renderTarget
|
|
|
|
glTexture := c.screen.texture
|
2014-12-17 14:50:44 +01:00
|
|
|
|
|
|
|
glRenderTarget.Dispose()
|
|
|
|
glTexture.Dispose()
|
2013-12-09 15:52:14 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 12:54:14 +01:00
|
|
|
func (c *graphicsContext) preUpdate() error {
|
|
|
|
return c.screen.Clear()
|
2013-12-09 14:40:54 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 12:54:14 +01:00
|
|
|
func (c *graphicsContext) postUpdate() error {
|
2014-12-20 11:11:06 +01:00
|
|
|
// We don't need to clear the default render target (framebuffer).
|
|
|
|
// For the default framebuffer, a special shader is used.
|
2014-12-07 16:07:36 +01:00
|
|
|
scale := float64(c.screenScale)
|
2014-12-20 07:55:13 +01:00
|
|
|
geo := ScaleGeometry(scale, scale)
|
2014-12-20 10:07:25 +01:00
|
|
|
clr := ColorMatrixI()
|
2014-12-22 02:36:42 +01:00
|
|
|
w, h := c.screen.size()
|
2014-12-20 18:42:55 +01:00
|
|
|
parts := []ImagePart{
|
2014-12-20 16:46:50 +01:00
|
|
|
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
|
|
|
}
|
2014-12-22 02:36:42 +01:00
|
|
|
if err := c.defaultR.drawImage(c.screen, parts, geo, clr); err != nil {
|
2014-12-20 12:54:14 +01:00
|
|
|
return err
|
|
|
|
}
|
2014-12-07 16:07:36 +01:00
|
|
|
|
|
|
|
gl.Flush()
|
2014-12-20 12:54:14 +01:00
|
|
|
return nil
|
2014-12-07 16:07:36 +01:00
|
|
|
}
|