diff --git a/src/gpu/framebuffer.cpp b/src/gpu/framebuffer.cpp index 5a068ef1..74b78d17 100644 --- a/src/gpu/framebuffer.cpp +++ b/src/gpu/framebuffer.cpp @@ -177,6 +177,11 @@ ShaderTexture FrameBuffer::GetTexture() const return ret; } +ivec2 FrameBuffer::GetSize() const +{ + return m_data->m_size; +} + void FrameBuffer::Bind() { #if defined USE_D3D9 || defined _XBOX @@ -190,6 +195,8 @@ void FrameBuffer::Bind() # else glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_data->m_fbo); # endif + //change viewport draw size + Video::SetCustomSize(m_data->m_size); #endif } @@ -208,6 +215,8 @@ void FrameBuffer::Unbind() Abort(); m_data->m_back_surface->Release(); #else + //Restore viewport draw size + Video::RestoreSize(); # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 glBindFramebuffer(GL_FRAMEBUFFER, 0); # else diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp index 03608e0a..25d42f54 100644 --- a/src/gpu/vertexbuffer.cpp +++ b/src/gpu/vertexbuffer.cpp @@ -163,7 +163,6 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) #else /* FIXME: this has nothing to do here! */ glFrontFace(GL_CCW); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); switch (type) @@ -234,7 +233,6 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, #else /* FIXME: this has nothing to do here! */ glFrontFace(GL_CCW); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); switch (type) diff --git a/src/lol/gpu/framebuffer.h b/src/lol/gpu/framebuffer.h index 403792a9..ceca74e4 100644 --- a/src/lol/gpu/framebuffer.h +++ b/src/lol/gpu/framebuffer.h @@ -28,6 +28,7 @@ public: ~FrameBuffer(); ShaderTexture GetTexture() const; + ivec2 GetSize() const; void Bind(); void Unbind(); diff --git a/src/video.cpp b/src/video.cpp index 5012356d..c543cf2e 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -53,6 +53,7 @@ private: static ivec2 saved_viewport; static DebugRenderMode render_mode; static bool face_culling; + static bool alpha_blend; #if defined USE_D3D9 || defined _XBOX # if defined USE_D3D9 static IDirect3D9 *d3d_ctx; @@ -69,7 +70,8 @@ private: mat4 VideoData::proj_matrix; ivec2 VideoData::saved_viewport(0, 0); DebugRenderMode VideoData::render_mode = DebugRenderMode::Default; -bool VideoData::face_culling; +bool VideoData::face_culling = true; +bool VideoData::alpha_blend = true; #if defined USE_D3D9 || defined _XBOX # if defined USE_D3D9 @@ -157,9 +159,38 @@ void Video::Setup(ivec2 size) /* Initialise reasonable scene default properties */ SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f)); SetClearDepth(1.f); + SetAlphaBlend(true); SetDebugRenderMode(DebugRenderMode::Default); } +void Video::SetCustomSize(ivec2 size) +{ + ivec4 current_size(0); +#if defined USE_D3D9 || defined _XBOX +# define STR0(x) #x +# define STR(x) STR0(x) +# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetSize() not implemented") +#else + glGetIntegerv(GL_VIEWPORT, (GLint*)¤t_size); + if (current_size.zw != size) + glViewport(0, 0, size.x, size.y); +#endif +} + +void Video::RestoreSize() +{ + ivec4 current_size(0); +#if defined USE_D3D9 || defined _XBOX +# define STR0(x) #x +# define STR(x) STR0(x) +# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetSize() not implemented") +#else + glGetIntegerv(GL_VIEWPORT, (GLint*)¤t_size); + if (current_size.zw != VideoData::saved_viewport) + glViewport(0, 0, VideoData::saved_viewport.x, VideoData::saved_viewport.y); +#endif +} + void Video::SetFov(float theta) { vec2 size = GetSize(); @@ -215,6 +246,46 @@ void Video::SetDepth(bool set) #endif } +void Video::SetFaceCulling(bool set) +{ +#if defined USE_D3D9 || defined _XBOX +# define STR0(x) #x +# define STR(x) STR0(x) +# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetFaceCulling() not implemented") +#else + VideoData::face_culling = set; + if (set) + glEnable(GL_CULL_FACE); + else + glDisable(GL_CULL_FACE); +#endif +} + +bool Video::HasFaceCulling() +{ + return VideoData::face_culling; +} + +void Video::SetAlphaBlend(bool set) +{ +#if defined USE_D3D9 || defined _XBOX +# define STR0(x) #x +# define STR(x) STR0(x) +# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetAlphaBlend() not implemented") +#else + VideoData::alpha_blend = set; + if (set) + glEnable(GL_BLEND); + else + glDisable(GL_BLEND); +#endif +} + +bool Video::HasAlphaBlend() +{ + return VideoData::alpha_blend; +} + void Video::SetClearColor(vec4 color) { #if defined USE_D3D9 || defined _XBOX @@ -252,9 +323,9 @@ void Video::SetDebugRenderMode(DebugRenderMode d) glEnable(GL_CULL_FACE); #else if (VideoData::render_mode == d && glIsEnabled(GL_CULL_FACE) == GL_TRUE) - glDisable(GL_CULL_FACE); + SetFaceCulling(false); else - glEnable(GL_CULL_FACE); + SetFaceCulling(true); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); #endif break; @@ -265,18 +336,14 @@ void Video::SetDebugRenderMode(DebugRenderMode d) { #if defined USE_D3D9 || defined _XBOX #else - VideoData::face_culling = !VideoData::face_culling; - if (VideoData::face_culling) - glEnable(GL_CULL_FACE); - else - glDisable(GL_CULL_FACE); + SetFaceCulling(!VideoData::face_culling); #endif } else { #if defined USE_D3D9 || defined _XBOX #else - glDisable(GL_CULL_FACE); + SetFaceCulling(false); #endif } #if defined USE_D3D9 || defined _XBOX diff --git a/src/video.h b/src/video.h index 0469ad92..99e0e9e9 100644 --- a/src/video.h +++ b/src/video.h @@ -66,9 +66,15 @@ class Video { public: static void Setup(ivec2 size); + static void SetCustomSize(ivec2 size); + static void RestoreSize(); static void Destroy(); static void SetFov(float theta); static void SetDepth(bool set); + static void SetFaceCulling(bool set); + static bool HasFaceCulling(); + static void SetAlphaBlend(bool set); + static bool HasAlphaBlend(); static void SetClearColor(vec4 color); static void SetClearDepth(float f); static void SetDebugRenderMode(DebugRenderMode d);