Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
OpenGLRenderingScreen.inl.h
1 
2 
3 
4 extern void* globalGLContext;
5 extern void setCurrentGLContext(void* context);
6 
7 IMPLEMENT_CLASS_INFO(OpenGLRenderingScreen)
8 
9 OpenGLRenderingScreen::OpenGLRenderingScreen(const kstl::string& name, CLASS_NAME_TREE_ARG) : RenderingScreen(name, PASS_CLASS_NAME_TREE_ARG)
10 {
11  myContext = 0;
12  myBindedTexture = 0;
13  sBuffer = -1;
14 }
15 
16 OpenGLRenderingScreen::~OpenGLRenderingScreen()
17 {
18  if (!myIsOffScreen)
19  {
20  }
21 
22  if (sBuffer != 0xffffffff)
23  glDeleteBuffers(1, &sBuffer);
24 
25  // [myContext release];
26  myContext = 0;
27 }
28 
30 {
31  // return (__bridge void*)myContext;
32  // return myContext;
33  return 0;
34 }
35 
37 {
38  if (!myIsOffScreen)
39  {
40  kstl::set<CoreModifiable*> instances;
41  CoreModifiable::GetInstancesByName("Window", myParentWindowName, instances);
42 
43  if (instances.size())
44  {
45  Window* parentwindow = (Window*)(*instances.begin());
46  if (!parentwindow->IsInit())
47  {
48  KIGS_ERROR("A rendering screen needs a parent window", 1);
49  return;
50  }
51 
52  int sizeX, sizeY;
53  parentwindow->getValue("SizeX", sizeX);
54  parentwindow->getValue("SizeY", sizeY);
55 
56  mySizeX = (unsigned int)sizeX;
57  mySizeY = (unsigned int)sizeY;
58 
59  myContext = globalGLContext;
60 
61  }
62  }
63 
64 
65 
67  myIsInit = true;
68 
69  InitializeGL(mySizeX, mySizeY);
70 }
71 
72 void OpenGLRenderingScreen::InitializeGL(int width, int height)
73 {
74  mySizeX = (unsigned int)width;
75  mySizeY = (unsigned int)height;
76  glViewport(0, 0, width, height);
77 
78 }
79 
80 
81 void OpenGLRenderingScreen::Resize(kfloat sizeX, kfloat sizeY)
82 {
83  // before screen is init, only update sizeX and sizeY
84  if (!IsInit())
85  {
86  mySizeX = (unsigned int)sizeX;
87  mySizeY = (unsigned int)sizeY;
88  }
89  else
90  {
91  //When resizing an offscreen surface, we keep the big surface but we let the camera clip the scene
92  InitializeGL(sizeX, sizeY);
93  }
94 }
95 
96 void OpenGLRenderingScreen::Update(const Timer& timer, void* addParam)
97 {
98 
99  RendererOpenGL* renderer = (RendererOpenGL*)((ModuleRenderer*)KigsCore::Instance()->GetMainModuleInList(RendererModuleCoreIndex))->GetSpecificRenderer();
100 
101  renderer->SetClearColorValue(myBackDropColor[0], myBackDropColor[1], myBackDropColor[2], 0.0);
102  renderer->FlushState();
103  RenderingScreen::Update(timer, addParam);
104  // brightness (fade) effect here
105  ManageFade();
106 
107 
108  glFlush();
109  glFinish();
110 
111 }
112 
114 {
115  //KIGS_MESSAGE("SetScreen active");
117  setCurrentGLContext(myContext);
118 
119  if (myIsOffScreen)
120  {
121  if (myBindedTexture)
122  {
123  glBindTexture(GL_TEXTURE_2D, myBindedTexture->GetGLID());
124  }
125  }
126 
127  return true;
128 }
129 
131 {
132  if (myBindedTexture && myIsOffScreen)
133  {
134  glBindTexture(GL_TEXTURE_2D, myBindedTexture->GetGLID());
135  }
136 
137  KIGS_ASSERT(glGetError() == GL_NO_ERROR);
138 }
139 
140 void OpenGLRenderingScreen::BindTexture(Texture* texture)
141 {
142  myBindedTexture = (OpenGLTexture*)texture;
143 }
144 
145 
146 
147 void OpenGLRenderingScreen::FetchPixels(int x, int y, int width, int height, void *pRGBAPixels)
148 {
149  glFlush();
150  glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pRGBAPixels);
151 }
OpenGLRenderingScreen::GetContextHandle
void * GetContextHandle()
get the target window handle of the rendering.
Definition: OpenGL3RenderingScreen.inl.h:26
RenderingScreen::InitModifiable
void InitModifiable() override
default modifiable init : set all initparams to readonly and set initflag to true
Definition: RenderingScreen.cpp:61
OpenGLRenderingScreen
OpenGL implementation of RendereingScreen.
Definition: OpenGLRenderingScreen.h:9
KigsCore::Instance
static KigsCore * Instance()
return unique instance of KigsCore
Definition: Core.cpp:478
Texture
manage a texture.
Definition: Texture.h:28
RenderingScreen
Generic "draw surface".
Definition: RenderingScreen.h:28
OpenGLRenderingScreen::Release
void Release(TravState *state)
release the screen
Definition: OpenGLRenderingScreen.cpp:118
OpenGLRenderingScreen::SetActive
bool SetActive(TravState *state)
active the screen
Definition: OpenGLRenderingScreen.inl.h:113
OpenGLTexture
OpenGL implementation of Texture.
Definition: OpenGLTexture.h:17
Window
Base class for Window (rendering window).
Definition: Window.h:20
ModuleRenderer
Generic rendering module.
Definition: ModuleRenderer.h:366
OpenGLRenderingScreen::InitModifiable
virtual void InitModifiable()
default modifiable init : set all initparams to readonly and set initflag to true
Definition: OpenGLRenderingScreen.inl.h:16
OpenGLRenderingScreen::Resize
void Resize(kfloat sizeX, kfloat sizeY)
resize the screen
Definition: OpenGLRenderingScreen.inl.h:61
RenderingScreen::SetActive
virtual bool SetActive(TravState *state)
active the screen
Definition: RenderingScreen.cpp:200
TravState
Base class used to store current scene traversal state.
Definition: TravState.h:71
Timer
Definition: Timer.h:27
RendererOpenGL
OpenGL implementation of ModuleSpecificRenderer.
Definition: RendererOpenGL.h:111
RenderingScreen::IsInit
bool IsInit()
check if the screen has been initialized
Definition: RenderingScreen.h:92