Merge branch 'master' of github.com:hrydgard/native

This commit is contained in:
Henrik Rydgard 2012-11-27 16:38:59 +01:00
commit 390f9b93de
24 changed files with 342 additions and 130 deletions

View File

@ -38,6 +38,7 @@ LOCAL_SRC_FILES :=\
net/resolve.cpp \
profiler/profiler.cpp \
gfx_es2/glsl_program.cpp \
gfx_es2/gl_state.cpp \
gfx_es2/draw_buffer.cpp.arm \
gfx_es2/vertex_format.cpp \
gfx_es2/fbo.cpp \
@ -54,7 +55,7 @@ LOCAL_SRC_FILES :=\
util/random/perlin.cpp
LOCAL_CFLAGS := -O2 -DGL_GLEXT_PROTOTYPES -fsigned-char -fno-strict-aliasing
LOCAL_CFLAGS := -O2 -DGL_GLEXT_PROTOTYPES -DARM -DUSING_GLES2 -fsigned-char -fno-strict-aliasing
LOCAL_CPPFLAGS := -fno-exceptions -fno-rtti -std=gnu++0x
LOCAL_LDLIBS := -lz
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ext/libzip

View File

@ -13,10 +13,10 @@
#include <string>
#include "SDL/SDL.h"
#include "SDL/SDL_timer.h"
#include "SDL/SDL_audio.h"
#include "SDL/SDL_video.h"
#include "SDL.h"
#include "SDL_timer.h"
#include "SDL_audio.h"
#include "SDL_video.h"
#include "base/display.h"
#include "base/logging.h"

View File

@ -22,7 +22,7 @@ inline void Crash() { __asm { int 3 }; }
#else
#if defined(ANDROID) || defined(BLACKBERRY)
#if defined(ARM)
#undef Crash
inline void Crash() {

View File

@ -17,7 +17,7 @@
#include "base/basictypes.h"
#include "file/file_util.h"
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__APPLE__)
#define stat64 stat
#endif

22
gfx/gl_common.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _GL_COMMON_H
#define _GL_COMMON_H
#if defined(USING_GLES2)
#if defined(IOS)
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
typedef char GLchar;
#else
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif
#else // OpenGL
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#endif //_GL_COMMON_H

View File

@ -1,16 +1,4 @@
#if defined(ANDROID) || defined(BLACKBERRY)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
typedef char GLchar;
#else
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#include "gfx/gl_common.h"
#include "base/logging.h"
void glCheckzor(const char *file, int line) {
@ -20,7 +8,7 @@ void glCheckzor(const char *file, int line) {
}
}
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
#if 0
void log_callback(GLenum source, GLenum type,
GLuint id,
@ -56,7 +44,7 @@ void log_callback(GLenum source, GLenum type,
#endif
void gl_log_enable() {
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
#if 0
glEnable(DEBUG_OUTPUT_SYNCHRONOUS_ARB); // TODO: Look into disabling, for more perf
glDebugMessageCallback(&log_callback, 0);

View File

@ -6,7 +6,7 @@
void gl_log_enable();
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
//#define DEBUG_OPENGL
#endif

View File

@ -1,30 +1,19 @@
#if defined(ANDROID) || defined(BLACKBERRY)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
#include "image/png_load.h"
#include "ext/etcpack/etcdec.h"
#endif
#include "image/zim_load.h"
#include "base/logging.h"
#include "texture.h"
#include "gfx/texture.h"
#include "gfx/texture_gen.h"
#include "gfx/gl_debug_log.h"
#include "gfx/gl_lost_manager.h"
#include "gfx/gl_common.h"
Texture::Texture() : id_(0) {
register_gl_resource_holder(this);
@ -76,7 +65,7 @@ bool Texture::Load(const char *filename) {
glBindTexture(GL_TEXTURE_2D, id_);
if (bpp == 1) {
#if defined(ANDROID) || defined(BLACKBERRY)
#if defined(USING_GLES2)
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
#else
glTexImage2D(GL_TEXTURE_2D, 0, 1, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
@ -118,7 +107,7 @@ bool Texture::Load(const char *filename) {
const char *name = fn;
if (zim && 0==memcmp(name, "Media/textures/", strlen("Media/textures"))) name += strlen("Media/textures/");
len = strlen(name);
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
if (!strcmp("png", &name[len-3]) ||
!strcmp("PNG", &name[len-3])) {
if (!LoadPNG(fn)) {
@ -141,7 +130,7 @@ bool Texture::Load(const char *filename) {
return false;
}
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
bool Texture::LoadPNG(const char *filename) {
unsigned char *image_data;
if (1 != pngLoad(filename, &width_, &height_, &image_data, false)) {
@ -184,7 +173,7 @@ bool Texture::LoadXOR() {
}
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
// Allocates using new[], doesn't free.
uint8_t *ETC1ToRGBA(uint8_t *etc1, int width, int height) {
@ -244,7 +233,7 @@ bool Texture::LoadZIM(const char *filename) {
int data_h = height[l];
if (data_w < 4) data_w = 4;
if (data_h < 4) data_h = 4;
#if defined(ANDROID) || defined(BLACKBERRY)
#if defined(USING_GLES2)
int compressed_image_bytes = data_w * data_h / 2;
glCompressedTexImage2D(GL_TEXTURE_2D, l, GL_ETC1_RGB8_OES, width[l], height[l], 0, compressed_image_bytes, image_data[l]);
GL_CHECK();
@ -255,7 +244,7 @@ bool Texture::LoadZIM(const char *filename) {
#endif
}
GL_CHECK();
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, num_levels - 2);
#endif
} else {

View File

@ -14,7 +14,7 @@ public:
~Texture();
bool LoadZIM(const char *filename);
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
bool LoadPNG(const char *filename);
#endif
bool LoadXOR(); // Loads a placeholder texture.

View File

@ -1,23 +1,18 @@
// WIP, please ignore
#include "gfx/texture.h"
#include <d3d11_1.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
#include "image/png_load.h"
#include "ext/etcpack/etcdec.h"
#endif
#include "image/zim_load.h"
#include "base/logging.h"
#include "texture.h"
#include "gfx/texture.h"
#include "gfx/texture_gen.h"
#include "gfx/gl_debug_log.h"
#include "gfx/gl_lost_manager.h"
@ -98,7 +93,7 @@ bool Texture::Load(const char *filename) {
const char *name = fn;
if (zim && 0 == memcmp(name, "Media/textures/", strlen("Media/textures"))) name += strlen("Media/textures/");
len = strlen(name);
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
if (!strcmp("png", &name[len-3]) ||
!strcmp("PNG", &name[len-3])) {
if (!LoadPNG(fn)) {
@ -122,7 +117,7 @@ bool Texture::Load(const char *filename) {
}
#ifndef METRO
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
bool Texture::LoadPNG(const char *filename) {
unsigned char *image_data;
if (1 != pngLoad(filename, &width_, &height_, &image_data, false)) {
@ -176,7 +171,7 @@ bool Texture::LoadXOR() {
}
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
// Allocates using new[], doesn't free.
uint8_t *ETC1ToRGBA(uint8_t *etc1, int width, int height) {
@ -236,7 +231,7 @@ bool Texture::LoadZIM(const char *filename) {
int data_h = height[l];
if (data_w < 4) data_w = 4;
if (data_h < 4) data_h = 4;
#if defined(ANDROID) || defined(BLACKBERRY)
#if defined(USING_GLES2)
int compressed_image_bytes = data_w * data_h / 2;
glCompressedTexImage2D(GL_TEXTURE_2D, l, GL_ETC1_RGB8_OES, width[l], height[l], 0, compressed_image_bytes, image_data[l]);
GL_CHECK();
@ -247,7 +242,7 @@ bool Texture::LoadZIM(const char *filename) {
#endif
}
GL_CHECK();
#if !defined(ANDROID) && !defined(BLACKBERRY)
#if !defined(USING_GLES2)
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, num_levels - 2);
#endif
} else {

View File

@ -2,6 +2,7 @@ set(SRCS
draw_buffer.cpp
fbo.cpp
glsl_program.cpp
gl_state.cpp
vertex_format.cpp)
set(SRCS ${SRCS})

View File

@ -1,15 +1,3 @@
#if defined(ANDROID) || defined(BLACKBERRY)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#include <algorithm>
#include <cmath>
@ -18,8 +6,10 @@
#include "math/math_util.h"
#include "gfx_es2/draw_buffer.h"
#include "gfx_es2/glsl_program.h"
#include "gfx_es2/gl_state.h"
#include "gfx/texture_atlas.h"
#include "gfx/gl_debug_log.h"
#include "gfx/gl_common.h"
enum {
// Enough?
@ -50,8 +40,8 @@ void DrawBuffer::Flush(const GLSLProgram *program, bool set_blend_state) {
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
if (set_blend_state) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glstate.blend.enable();
glstate.blendFunc.set(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glUniform1i(program->sampler0, 0);
glEnableVertexAttribArray(program->a_position);
@ -357,23 +347,18 @@ void DrawBuffer::DrawText(int font, const char *text, float x, float y, Color co
}
void DrawBuffer::EnableBlend(bool enable) {
if (enable)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
glDisable(GL_BLEND);
glstate.blend.set(enable);
glstate.blendFunc.set(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void DrawBuffer::SetClipRect(float x, float y, float w, float h)
{
// Sigh, OpenGL is upside down.
glScissor(x, dp_yres - y, w, h);
glEnable(GL_SCISSOR_TEST);
glstate.scissorTest.enable();
}
void DrawBuffer::NoClip()
{
glDisable(GL_SCISSOR_TEST);
glstate.scissorTest.disable();
}

View File

@ -1,40 +1,70 @@
#if defined(ANDROID) || defined(BLACKBERRY)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <string.h>
#include "base/logging.h"
#include "gfx_es2/fbo.h"
#include "gfx/gl_common.h"
#if defined(USING_GLES2)
#define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
#define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER
#define GL_RGBA8 GL_RGBA
#ifndef GL_DEPTH_COMPONENT24
#define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
#endif
#else
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#include "base/logging.h"
#include "gfx_es2/fbo.h"
// TODO: Breakout this GL extension checker in its own file.
struct GLExtensions {
bool OES_depth24;
bool OES_packed_depth_stencil;
bool OES_depth_texture;
};
GLExtensions gl_extensions;
void CheckExtensions() {
static bool done = false;
if (done)
return;
done = true;
memset(&gl_extensions, 0, sizeof(gl_extensions));
const char *extString = (const char *)glGetString(GL_EXTENSIONS);
gl_extensions.OES_packed_depth_stencil = strstr(extString, "GL_OES_packed_depth_stencil");
gl_extensions.OES_depth24 = strstr(extString, "GL_OES_depth24");
gl_extensions.OES_depth_texture = strstr(extString, "GL_OES_depth_texture");
}
struct FBO {
GLuint handle;
GLuint color_texture;
GLuint z_stencil_buffer;
GLuint z_stencil_buffer; // Either this is set, or the two below.
GLuint z_buffer;
GLuint stencil_buffer;
int width;
int height;
};
// On PC, we always use GL_DEPTH24_STENCIL8.
// On Android, we try to use what's available.
FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil) {
CheckExtensions();
FBO *fbo = new FBO();
fbo->width = width;
fbo->height = height;
// Color texture is same everywhere
glGenFramebuffers(1, &fbo->handle);
glGenTextures(1, &fbo->color_texture);
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
// Create the surfaces.
glBindTexture(GL_TEXTURE_2D, fbo->color_texture);
@ -42,15 +72,65 @@ FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// TODO: We could opt to only create 16-bit render targets on slow devices. For later.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#ifdef USING_GLES2
if (gl_extensions.OES_packed_depth_stencil) {
ILOG("Creating FBO using DEPTH24_STENCIL8");
// Standard method
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil combined
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
// Bind it all together
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
} else {
ILOG("Creating FBO using separate stencil");
// TEGRA
fbo->z_stencil_buffer = 0;
// 16-bit Z, separate 8-bit stencil
glGenRenderbuffers(1, &fbo->z_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
// 8-bit stencil buffer
glGenRenderbuffers(1, &fbo->stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
// Bind it all together
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_buffer);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->stencil_buffer);
}
#else
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
// Bind it all together
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
#endif
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch(status) {
@ -58,7 +138,10 @@ FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil) {
ILOG("Framebuffer verified complete.");
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
ELOG("Framebuffer format not supported");
ELOG("GL_FRAMEBUFFER_UNSUPPORTED");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
ELOG("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ");
break;
default:
FLOG("Other framebuffer error: %i", status);

View File

@ -9,6 +9,8 @@ struct FBO;
// No mipmap support.
// num_color_textures must be 1 for now.
// you lose bound texture state.
// On some hardware, you might get a 24-bit depth buffer even though you only wanted a 16-bit one.
FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil);
// These functions should be self explanatory.

24
gfx_es2/gl_state.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "gl_state.h"
OpenGLState glstate;
void OpenGLState::Initialize() {
if(initialized) return;
Restore();
initialized = true;
}
void OpenGLState::Restore() {
blend.restore();
blendEquation.restore();
blendFunc.restore();
cullFace.restore();
cullFaceMode.restore();
depthTest.restore();
depthRange.restore();
depthFunc.restore();
}

134
gfx_es2/gl_state.h Normal file
View File

@ -0,0 +1,134 @@
#pragma once
#include <functional>
#include <string.h>
#include "gfx/gl_common.h"
// OpenGL state cache. Should convert all code to use this instead of directly calling glEnable etc,
// as GL state changes can be expensive on some hardware.
class OpenGLState
{
private:
template<GLenum cap, bool init>
class BoolState {
bool _value;
public:
BoolState() : _value(init) {}
inline void set(bool value) {
if(value && value != _value) {
_value = value;
glEnable(cap);
}
if(!value && value != _value) {
_value = value;
glDisable(cap);
}
}
inline void enable() {
set(true);
}
inline void disable() {
set(false);
}
operator bool() const {
return isset();
}
inline bool isset() {
return _value;
}
void restore() {
if(_value)
glEnable(cap);
else
glDisable(cap);
}
};
#define STATE1(func, p1type, p1def) \
class SavedState1_##func { \
p1type p1; \
public: \
SavedState1_##func() : p1(p1def) {}; \
void set(p1type newp1) { \
if(newp1 != p1) { \
p1 = newp1; \
func(p1); \
} \
} \
void restore() { \
func(p1); \
} \
}
#define STATE2(func, p1type, p2type, p1def, p2def) \
class SavedState2_##func { \
p1type p1; \
p2type p2; \
public: \
SavedState2_##func() : p1(p1def), p2(p2def) {}; \
inline void set(p1type newp1, p2type newp2) { \
if(newp1 != p1 || newp2 != p2) { \
p1 = newp1; \
p2 = newp2; \
func(p1, p2); \
} \
} \
inline void restore() { \
func(p1, p2); \
} \
}
#define STATEFLOAT4(func, def) \
class SavedState4_##func { \
float p[4]; \
public: \
SavedState4_##func() { \
for (int i = 0; i < 4; i++) {p[i] = def;} \
}; \
inline void set(const float v[4]) { \
if(memcmp(p,v,sizeof(float)*4)) { \
memcpy(p,v,sizeof(float)*4); \
func(p[0], p[1], p[2], p[3]); \
} \
} \
inline void restore() { \
func(p[0], p[1], p[2], p[3]); \
} \
}
bool initialized;
public:
OpenGLState() : initialized(false) {}
void Initialize();
void Restore();
BoolState<GL_BLEND, false> blend;
STATE2(glBlendFunc, GLenum, GLenum, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blendFunc;
STATE1(glBlendEquation, GLenum, GL_FUNC_ADD) blendEquation;
STATEFLOAT4(glBlendColor, 1.0f) blendColor;
BoolState<GL_SCISSOR_TEST, false> scissorTest;
BoolState<GL_CULL_FACE, false> cullFace;
STATE1(glCullFace, GLenum, GL_FRONT) cullFaceMode;
STATE1(glFrontFace, GLenum, GL_CCW) frontFace;
BoolState<GL_DEPTH_TEST, false> depthTest;
STATE1(glDepthFunc, GLenum, GL_LESS) depthFunc;
STATE1(glDepthMask, GLboolean, GL_TRUE) depthWrite;
#if defined(USING_GLES2)
STATE2(glDepthRangef, float, float, 0.f, 1.f) depthRange;
#else
STATE2(glDepthRange, double, double, 0.0, 1.0) depthRange;
#endif
};
#undef STATE1
#undef STATE2
extern OpenGLState glstate;

View File

@ -1,16 +1,3 @@
#if defined(ANDROID) || defined(BLACKBERRY)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
typedef char GLchar;
#else
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#include <set>
#include <stdio.h>
@ -19,7 +6,7 @@ typedef char GLchar;
#include "base/logging.h"
#include "file/vfs.h"
#include "gfx_es2/glsl_program.h"
#include "glsl_program.h"
static std::set<GLSLProgram *> active_programs;
@ -37,7 +24,7 @@ bool CompileShader(const char *source, GLuint shader, const char *filename) {
ELOG("Error in shader compilation of %s!\n", filename);
ELOG("Info log: %s\n", infoLog);
ELOG("Shader source:\n%s\n", (const char *)source);
#if defined(ANDROID) || defined(BLACKBERRY)
#if defined(ARM)
exit(1);
#endif
return false;

View File

@ -4,22 +4,11 @@
#ifndef _RENDER_UTIL
#define _RENDER_UTIL
#if defined(ANDROID) || defined(BLACKBERRY)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
#include <map>
#include <time.h>
#include "gfx/gl_lost_manager.h"
#include "gfx/gl_common.h"
// Represent a compiled and linked vshader/fshader pair.
// A just-constructed object is valid but cannot be used as a shader program, meaning that

View File

@ -17,7 +17,7 @@ unsigned int GenerateRandomNumber() {
#include <math.h>
#if defined(ANDROID) || defined(BLACKBERRY)
#if defined(ARM)
void EnableFZ()
{

View File

@ -221,6 +221,7 @@
<ClInclude Include="gfx_es2\draw_buffer.h" />
<ClInclude Include="gfx_es2\fbo.h" />
<ClInclude Include="gfx_es2\glsl_program.h" />
<ClInclude Include="gfx_es2\gl_state.h" />
<ClInclude Include="gfx_es2\vertex_format.h" />
<ClInclude Include="image\png_load.h" />
<ClInclude Include="image\zim_load.h" />
@ -310,6 +311,7 @@
<ClCompile Include="gfx_es2\draw_buffer.cpp" />
<ClCompile Include="gfx_es2\fbo.cpp" />
<ClCompile Include="gfx_es2\glsl_program.cpp" />
<ClCompile Include="gfx_es2\gl_state.cpp" />
<ClCompile Include="gfx_es2\vertex_format.cpp" />
<ClCompile Include="image\png_load.cpp" />
<ClCompile Include="image\zim_load.cpp" />

View File

@ -230,6 +230,9 @@
<ClInclude Include="ext\stb_vorbis\stb_vorbis.h">
<Filter>ext</Filter>
</ClInclude>
<ClInclude Include="gfx_es2\gl_state.h">
<Filter>gfx</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="gfx\gl_debug_log.cpp">
@ -405,6 +408,12 @@
<ClCompile Include="ext\stb_vorbis\stb_vorbis.c">
<Filter>ext</Filter>
</ClCompile>
<ClCompile Include="base\BlackberryMain.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="gfx_es2\gl_state.cpp">
<Filter>gfx</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="gfx">
@ -465,4 +474,4 @@
<UniqueIdentifier>{4515306f-4664-46bf-a89b-abfec5520a15}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
</Project>

View File

@ -96,7 +96,7 @@
<Project>{f761046e-6c38-4428-a5f1-38391a37bb34}</Project>
</ProjectReference>
<ProjectReference Include="..\..\native.vcxproj">
<Project>{e8b58922-9827-493d-81e0-4b6e6bd77171}</Project>
<Project>{C4DF647E-80EA-4111-A0A8-218B1B711E18}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -94,7 +94,7 @@
<Project>{f761046e-6c38-4428-a5f1-38391a37bb34}</Project>
</ProjectReference>
<ProjectReference Include="..\..\native.vcxproj">
<Project>{e8b58922-9827-493d-81e0-4b6e6bd77171}</Project>
<Project>{C4DF647E-80EA-4111-A0A8-218B1B711E18}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -3,13 +3,14 @@
#include "gfx/texture.h"
#include "gfx_es2/draw_buffer.h"
#include "gfx_es2/glsl_program.h"
#include "gfx_es2/gl_state.h"
void UIContext::Begin()
{
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glstate.blend.enable();
glstate.blendFunc.set(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glstate.cullFace.disable();
glstate.depthTest.disable();
if (uishader_)
glsl_bind(uishader_);
if (uitexture_)