diff options
author | Alexander Kuznetsov <kuzsasha@gmail.com> | 2012-08-10 04:40:10 +0400 |
---|---|---|
committer | Alexander Kuznetsov <kuzsasha@gmail.com> | 2012-08-10 04:40:10 +0400 |
commit | 56ec978863d7048b867dff7c05fa016636a17992 (patch) | |
tree | db90ec736ae89352e7c80a8da0ea96a5e7090019 | |
parent | 09d0f24f155cc91b19fc9e2ebf5486a98d18930e (diff) |
Adding gpu_view module.
It has functions like setting the viewport and clearing it.
Afaik it should be compatible with DirectX
We need gpuClear = glClear because calling color with depth clear is more efficent.
I will commit most conversions tomorrow.
It is much easier than doing REAL_GL_MODE to each viewport function.
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 14 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 7 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_view.c | 50 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_view.h | 63 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_view_gl.c | 90 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_view_gl.h | 45 |
6 files changed, 261 insertions, 8 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index e2c060383da..90af6bb0858 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -45,8 +45,8 @@ set(INC_SYS ) set(SRC - intern/gpu_aspect.c - intern/gpu_aspectfuncs.c + intern/gpu_aspect.c + intern/gpu_aspectfuncs.c intern/gpu_buffers.c intern/gpu_codegen.c intern/gpu_debug.c @@ -66,6 +66,8 @@ set(SRC intern/gpu_object_gles.c intern/gpu_object_gl11.c intern/gpu_functions.c + intern/gpu_view.c + intern/gpu_view_gl.c shaders/gpu_shader_material.glsl.c shaders/gpu_shader_vertex.glsl.c @@ -88,10 +90,10 @@ set(SRC GPU_fx.h intern/gpu_aspect.h - intern/gpu_aspectfuncs.h + intern/gpu_aspectfuncs.h intern/gpu_codegen.h intern/gpu_deprecated.h - intern/gpu_glew.h + intern/gpu_glew.h intern/gpu_immediate.h intern/gpu_immediate_inline.h intern/gpu_immediate_internal.h @@ -101,7 +103,9 @@ set(SRC intern/gpu_object_gles.h intern/gpu_object_gl11.h intern/gpu_primitives_inline.h - intern/gpu_safety.h + intern/gpu_safety.h + intern/gpu_view.h + intern/gpu_view_gl.h ) if(WITH_MOD_SMOKE) diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 6187a9a7abf..2e8964a5615 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -126,6 +126,7 @@ void GPU_extensions_init(void) glewInit(); GPU_func_comp_init(); + gpuInitializeViewFuncs(); GPU_codegen_init(); /* glewIsSupported("GL_VERSION_2_0") */ @@ -849,7 +850,7 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, i glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object); /* push matrices and set default viewport and matrix */ - glViewport(0, 0, w, h); + gpuViewport(0, 0, w, h); GG.currentfb = tex->fb->object; gpuMatrixMode(GL_PROJECTION); @@ -924,7 +925,7 @@ void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *b GPU_shader_bind(blur_shader); GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float*)scaleh); GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex); - glViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex)); + gpuViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex)); /* Peparing to draw quad */ gpuMatrixMode(GL_TEXTURE); @@ -949,7 +950,7 @@ void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *b /* Blurring vertically */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object); - glViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex)); + gpuViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex)); GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float*)scalev); GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex); GPU_texture_bind(blurtex, 0); diff --git a/source/blender/gpu/intern/gpu_view.c b/source/blender/gpu/intern/gpu_view.c new file mode 100644 index 00000000000..e998a27d990 --- /dev/null +++ b/source/blender/gpu/intern/gpu_view.c @@ -0,0 +1,50 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#define GPU_VIEW_INTERN +#include "gpu_view.h" +#include "gpu_view_gl.h" + + +void gpuInitializeViewFuncs(void) +{ + +gpuColorAndClear = gpuColorAndClear_gl; +gpuSetClearColor = gpuSetClearColor_gl; + +gpuColorAndClearvf = gpuColorAndClearvf_gl; +gpuSetClearColorvf = gpuSetClearColorvf_gl; + + +gpuViewport = gpuViewport_gl; +gpuScissor = gpuScissor_gl; +gpuViewportScissor = gpuViewportScissor_gl; +gpuGetScissorBox = gpuGetScissorBox_gl; + +gpuClear = gpuClear_gl; + +} diff --git a/source/blender/gpu/intern/gpu_view.h b/source/blender/gpu/intern/gpu_view.h new file mode 100644 index 00000000000..b90f4988c20 --- /dev/null +++ b/source/blender/gpu/intern/gpu_view.h @@ -0,0 +1,63 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#if !defined(GPU_VIEW_H) || defined(GPU_VIEW_INTERN) +#define GPU_VIEW_H + +#ifndef GPU_VIEW_INTERN +#define GPU_VIEW_FUNC extern +#else +#define GPU_VIEW_FUNC +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +void gpuInitializeViewFuncs(void); + +GPU_VIEW_FUNC void (* gpuColorAndClear)(float r, float g, float b, float a); +GPU_VIEW_FUNC void (* gpuSetClearColor)(float r, float g, float b, float a); + +GPU_VIEW_FUNC void (* gpuColorAndClearvf)(float c[3], float a); +GPU_VIEW_FUNC void (* gpuSetClearColorvf)(float c[3], float a); + +GPU_VIEW_FUNC void (* gpuClear)(int mask); + +GPU_VIEW_FUNC void (* gpuViewport)(int x, int y, unsigned int width, unsigned int height); +GPU_VIEW_FUNC void (* gpuScissor)(int x, int y, unsigned int width, unsigned int height); +GPU_VIEW_FUNC void (* gpuViewportScissor)(int x, int y, unsigned int width, unsigned int height); + +GPU_VIEW_FUNC void (*gpuGetScissorBox)(int *box); + +#ifdef __cplusplus +} +#endif + + +#endif
\ No newline at end of file diff --git a/source/blender/gpu/intern/gpu_view_gl.c b/source/blender/gpu/intern/gpu_view_gl.c new file mode 100644 index 00000000000..8346a98e06e --- /dev/null +++ b/source/blender/gpu/intern/gpu_view_gl.c @@ -0,0 +1,90 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "gpu_glew.h" +#include "gpu_view_gl.h" +#include REAL_GL_MODE +#include <stdlib.h> +void gpuColorAndClear_gl(float r, float g, float b, float a) +{ + gpuSetClearColor_gl(r, g, b, a); + glClear(GL_COLOR_BUFFER_BIT); + +} + +void gpuSetClearColor_gl(float r, float g, float b, float a) +{ + glClearColor(r, g, b, a); + //glClearColor((float)rand()/RAND_MAX,(float)rand()/RAND_MAX,(float)rand()/RAND_MAX,0); + +} + +void gpuColorAndClearvf_gl(float c[3], float a) +{ + gpuSetClearColorvf_gl(c, a); + glClear(GL_COLOR_BUFFER_BIT); +} + +void gpuSetClearColorvf_gl(float c[3], float a) +{ + glClearColor(c[0], c[1], c[2], a); + //glClearColor((float)rand()/RAND_MAX,(float)rand()/RAND_MAX,(float)rand()/RAND_MAX,0); + +} + + +void gpuViewport_gl(int x, int y, unsigned int width, unsigned int height) +{ + glViewport(x, y, width, height); + +} + + +void gpuScissor_gl(int x, int y, unsigned int width, unsigned int height) +{ +glEnable(GL_SCISSOR_TEST); + glScissor(x, y, width, height); + //gpuColorAndClear_gl((float)rand()/RAND_MAX,(float)rand()/RAND_MAX,(float)rand()/RAND_MAX,0); + //gpuSetClearColor_gl((float)rand()/RAND_MAX,(float)rand()/RAND_MAX,(float)rand()/RAND_MAX,0); +} + +void gpuGetScissorBox_gl(int *box) +{ + glGetIntegerv(GL_SCISSOR_BOX, box); +} + +void gpuViewportScissor_gl(int x, int y, unsigned int width, unsigned int height) +{ + gpuViewport_gl(x, y, width, height); + gpuScissor_gl(x, y, width, height); +} + + +void gpuClear_gl(int mask) +{ + glClear(mask); +} diff --git a/source/blender/gpu/intern/gpu_view_gl.h b/source/blender/gpu/intern/gpu_view_gl.h new file mode 100644 index 00000000000..c82b03bd823 --- /dev/null +++ b/source/blender/gpu/intern/gpu_view_gl.h @@ -0,0 +1,45 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov + * + * ***** END GPL LICENSE BLOCK ***** + */ + + +void gpuColorAndClear_gl(float r, float g, float b, float a); + +void gpuSetClearColor_gl(float r, float g, float b, float a); + +void gpuColorAndClearvf_gl(float c[3], float a); + +void gpuSetClearColorvf_gl(float c[3], float a); + +void gpuViewport_gl(int x, int y, unsigned int width, unsigned int height); + +void gpuScissor_gl(int x, int y, unsigned int width, unsigned int height); + +void gpuViewportScissor_gl(int x, int y, unsigned int width, unsigned int height); + +void gpuGetScissorBox_gl(int *box); + +void gpuClear_gl(int mask); |