Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
OpenGL3RenderingScreen.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 
14 }
15 
16 OpenGLRenderingScreen::~OpenGLRenderingScreen()
17 {
18  if (!myIsOffScreen)
19  {
20  }
21 
22  // [myContext release];
23  myContext = 0;
24 }
25 
27 {
28  // return (__bridge void*)myContext;
29  // return myContext;
30  return 0;
31 }
32 
34 {
36  RendererOpenGL* renderer = reinterpret_cast<RendererOpenGL*>(ModuleRenderer::theGlobalRenderer);
37  if (!myIsOffScreen)
38  {
39  kstl::set<CoreModifiable*> instances;
40  CoreModifiable::GetInstancesByName("Window", myParentWindowName, instances);
41 
42  if (instances.size())
43  {
44  Window* parentwindow = (Window*)(*instances.begin());
45  if (!parentwindow->IsInit())
46  {
47  KIGS_ERROR("A rendering screen needs a parent window", 1);
48  return;
49  }
50 
51  int sizeX, sizeY;
52  parentwindow->getValue("SizeX", sizeX);
53  parentwindow->getValue("SizeY", sizeY);
54 
55  mySizeX = (unsigned int)sizeX;
56  mySizeY = (unsigned int)sizeY;
57 
58  myContext = globalGLContext;
59 
60  }
61  }
62 
63 
64 
65 
66  myIsInit = true;
67 
68  InitializeGL(mySizeX, mySizeY);
69 
70  renderer->InitHardwareState();
71 }
72 
73 void OpenGLRenderingScreen::InitializeGL(int width, int height)
74 {
75  mySizeX = (unsigned int)width;
76  mySizeY = (unsigned int)height;
77  glViewport(0, 0, width, height);
78 
79 }
80 
81 
82 void OpenGLRenderingScreen::Resize(kfloat sizeX, kfloat sizeY)
83 {
84  // before screen is init, only update sizeX and sizeY
85  if (!IsInit())
86  {
87  mySizeX = (unsigned int)sizeX;
88  mySizeY = (unsigned int)sizeY;
89  }
90  else
91  {
92  //When resizing an offscreen surface, we keep the big surface but we let the camera clip the scene
93  InitializeGL(sizeX, sizeY);
94  }
95 }
96 
97 void OpenGLRenderingScreen::Update(const Timer& timer, void* addParam)
98 {
99 
100  RendererOpenGL* renderer = (RendererOpenGL*)((ModuleRenderer*)Core::Instance()->GetMainModuleInList(RendererModuleCoreIndex))->GetSpecificRenderer();
101 
102  renderer->SetClearColorValue(myBackDropColor[0], myBackDropColor[1], myBackDropColor[2], 0.0);
103  renderer->FlushState();
104  RenderingScreen::Update(timer, addParam);
105  // brightness (fade) effect here
106  ManageFade();
107 
108 
109  glFlush();
110  glFinish();
111 
112 }
113 
115 {
116  //KIGS_MESSAGE("SetScreen active");
118  setCurrentGLContext(myContext);
119 
120  if (myIsOffScreen)
121  {
122  if (myBindedTexture)
123  {
124  glBindTexture(GL_TEXTURE_2D, myBindedTexture->GetGLID());
125  }
126  }
127 
128  return true;
129 }
130 
132 {
133  if (myBindedTexture && myIsOffScreen)
134  {
135  glBindTexture(GL_TEXTURE_2D, myBindedTexture->GetGLID());
136  }
137 
138  KIGS_ASSERT(glGetError() == GL_NO_ERROR);
139 }
140 
141 void OpenGLRenderingScreen::BindTexture(Texture* texture)
142 {
143  myBindedTexture = (OpenGLTexture*)texture;
144 }
145 
146 
147 
148 void OpenGLRenderingScreen::FetchPixels(int x, int y, int width, int height, void *pRGBAPixels)
149 {
150  glFlush();
151  glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pRGBAPixels);
152 }
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
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
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