1 | #include <iostream>
|
---|
2 | #include "FrameBufferObject.h"
|
---|
3 | #include "glInterface.h"
|
---|
4 |
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 |
|
---|
12 | void PrintFBOStatus(GLenum status)
|
---|
13 | {
|
---|
14 | switch(status)
|
---|
15 | {
|
---|
16 | case GL_FRAMEBUFFER_COMPLETE_EXT:
|
---|
17 | cout << "frame buffer object created successfully" << endl;
|
---|
18 | break;
|
---|
19 | case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
---|
20 | cerr << "incomplete attachment" << endl;
|
---|
21 | break;
|
---|
22 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
---|
23 | cerr << "missing attachment" << endl;
|
---|
24 | break;
|
---|
25 | case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
---|
26 | cerr << "incomplete dimensions" << endl;
|
---|
27 | break;
|
---|
28 | case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
---|
29 | cerr << "incomplete formats" << endl;
|
---|
30 | break;
|
---|
31 | case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
---|
32 | cerr << "incomplete draw buffer" << endl;
|
---|
33 | break;
|
---|
34 | case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
---|
35 | cerr << "incomplete read buffer" << endl;
|
---|
36 | break;
|
---|
37 | case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
---|
38 | cerr << "framebuffer unsupported" << endl;
|
---|
39 | break;
|
---|
40 | default:
|
---|
41 | cerr << "unknown status code " << status << endl;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | ColorBufferObject::ColorBufferObject(int w, int h,
|
---|
47 | COLOR_FORMAT c,
|
---|
48 | int wrapType,
|
---|
49 | int filterType,
|
---|
50 | bool useMipMap,
|
---|
51 | bool useMultiSampling)
|
---|
52 | {
|
---|
53 | /*
|
---|
54 | glGenRenderbuffersEXT(1, &normalsBuffer);
|
---|
55 | glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, normalsBuffer);
|
---|
56 | glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight);
|
---|
57 |
|
---|
58 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, normalsBuffer);
|
---|
59 |
|
---|
60 | glGenTextures(1, &normalsTex);
|
---|
61 | glBindTexture(GL_TEXTURE_2D, normalsTex);
|
---|
62 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
---|
63 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0);
|
---|
64 |
|
---|
65 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
66 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
67 |
|
---|
68 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
69 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
70 |
|
---|
71 | PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
|
---|
72 | */
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | FrameBufferObject::FrameBufferObject(int w, int h, bool useDepth, DEPTH_FORMAT d)
|
---|
77 | : mWidth(w), mHeight(h)
|
---|
78 | {
|
---|
79 | glGenFramebuffersEXT(1, &mId);
|
---|
80 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mId);
|
---|
81 |
|
---|
82 |
|
---|
83 | ///////////
|
---|
84 | //-- create depth buffer
|
---|
85 |
|
---|
86 | if (useDepth)
|
---|
87 | {
|
---|
88 | glGenRenderbuffersEXT(1, &mDepthId);
|
---|
89 | glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepthId);
|
---|
90 |
|
---|
91 | GLuint depthFormat;
|
---|
92 |
|
---|
93 | switch (d)
|
---|
94 | {
|
---|
95 | case DEPTH_16:
|
---|
96 | depthFormat = GL_DEPTH_COMPONENT16; break;
|
---|
97 | case DEPTH_24:
|
---|
98 | depthFormat = GL_DEPTH_COMPONENT24; break;
|
---|
99 | case DEPTH_32:
|
---|
100 | depthFormat = GL_DEPTH_COMPONENT32; break;
|
---|
101 | }
|
---|
102 |
|
---|
103 | glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat, mWidth, mHeight);
|
---|
104 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepthId);
|
---|
105 |
|
---|
106 | PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | } // namespace
|
---|