Browse Source

video : Added SetAlphaBlend() SetFaceCulling() SetCustomSize()

FrameBuffer : Added GetSize() & tweaked Bind()/Unbind() with size update for correct rendering.
legacy
Benjamin ‘Touky’ Huet touky 11 years ago
parent
commit
23f9299a59
5 changed files with 92 additions and 11 deletions
  1. +9
    -0
      src/gpu/framebuffer.cpp
  2. +0
    -2
      src/gpu/vertexbuffer.cpp
  3. +1
    -0
      src/lol/gpu/framebuffer.h
  4. +76
    -9
      src/video.cpp
  5. +6
    -0
      src/video.h

+ 9
- 0
src/gpu/framebuffer.cpp View File

@@ -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


+ 0
- 2
src/gpu/vertexbuffer.cpp View File

@@ -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)


+ 1
- 0
src/lol/gpu/framebuffer.h View File

@@ -28,6 +28,7 @@ public:
~FrameBuffer();

ShaderTexture GetTexture() const;
ivec2 GetSize() const;

void Bind();
void Unbind();


+ 76
- 9
src/video.cpp View File

@@ -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*)&current_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*)&current_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


+ 6
- 0
src/video.h View File

@@ -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);


Loading…
Cancel
Save