1// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Surface.h: Defines the Surface class, representing a drawing surface
16// such as the client area of a window, including any back buffers.
17
18#ifndef INCLUDE_SURFACE_H_
19#define INCLUDE_SURFACE_H_
20
21#include "Main/FrameBuffer.hpp"
22
23#define _GDI32_
24#include <windows.h>
25#include <GL/GL.h>
26#include <GL/glext.h>
27
28#if defined(_WIN32)
29typedef HDC     NativeDisplayType;
30typedef HBITMAP NativePixmapType;
31typedef HWND    NativeWindowType;
32#else
33#error
34#endif
35
36namespace gl
37{
38class Image;
39class Display;
40
41class Surface
42{
43public:
44	Surface(Display *display, NativeWindowType window);
45	Surface(Display *display, GLint width, GLint height, GLenum textureFormat, GLenum textureTarget);
46
47	virtual ~Surface();
48
49	bool initialize();
50	void swap();
51
52	virtual Image *getRenderTarget();
53	virtual Image *getDepthStencil();
54
55	void setSwapInterval(GLint interval);
56
57	virtual GLint getWidth() const;
58	virtual GLint getHeight() const;
59	virtual GLenum getTextureFormat() const;
60	virtual GLenum getTextureTarget() const;
61
62	bool checkForResize();   // Returns true if surface changed due to resize
63
64private:
65	void release();
66	bool reset();
67
68	Display *const mDisplay;
69	Image *mDepthStencil;
70	sw::FrameBuffer *frameBuffer;
71	Image *backBuffer;
72
73	bool reset(int backbufferWidth, int backbufferHeight);
74
75	const NativeWindowType mWindow;   // Window that the surface is created for.
76	bool mWindowSubclassed;           // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking
77	GLint mWidth;                     // Width of surface
78	GLint mHeight;                    // Height of surface
79	GLenum mTextureFormat;            // Format of texture: RGB, RGBA, or no texture
80	GLenum mTextureTarget;            // Type of texture: 2D or no texture
81	GLint mSwapInterval;
82};
83}
84
85#endif   // INCLUDE_SURFACE_H_
86