summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles1/rasterizer_gles1.cpp8
-rw-r--r--drivers/gles1/rasterizer_gles1.h3
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp43
-rw-r--r--drivers/gles2/rasterizer_gles2.h6
-rw-r--r--drivers/gles2/shaders/copy.glsl7
-rw-r--r--drivers/openssl/stream_peer_ssl.cpp168
-rw-r--r--drivers/openssl/stream_peer_ssl.h37
7 files changed, 163 insertions, 109 deletions
diff --git a/drivers/gles1/rasterizer_gles1.cpp b/drivers/gles1/rasterizer_gles1.cpp
index da2b6801e5..3ffebd4703 100644
--- a/drivers/gles1/rasterizer_gles1.cpp
+++ b/drivers/gles1/rasterizer_gles1.cpp
@@ -2885,7 +2885,7 @@ void RasterizerGLES1::set_viewport(const VS::ViewportRect& p_viewport) {
glViewport( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
}
-void RasterizerGLES1::set_render_target(RID p_render_target) {
+void RasterizerGLES1::set_render_target(RID p_render_target, bool p_transparent_bg, bool p_vflip) {
}
@@ -4602,6 +4602,12 @@ void RasterizerGLES1::canvas_begin() {
}
+
+void RasterizerGLES1::canvas_disable_blending() {
+
+ glDisable(GL_BLEND);
+}
+
void RasterizerGLES1::canvas_set_opacity(float p_opacity) {
canvas_opacity = p_opacity;
diff --git a/drivers/gles1/rasterizer_gles1.h b/drivers/gles1/rasterizer_gles1.h
index cb0a3271ed..e7e3200bbc 100644
--- a/drivers/gles1/rasterizer_gles1.h
+++ b/drivers/gles1/rasterizer_gles1.h
@@ -1101,7 +1101,7 @@ public:
virtual void begin_frame();
virtual void set_viewport(const VS::ViewportRect& p_viewport);
- virtual void set_render_target(RID p_render_target);
+ virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false);
virtual void clear_viewport(const Color& p_color);
virtual void capture_viewport(Image* r_capture);
@@ -1126,6 +1126,7 @@ public:
/* CANVAS API */
virtual void canvas_begin();
+ virtual void canvas_disable_blending();
virtual void canvas_set_opacity(float p_opacity);
virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode);
virtual void canvas_begin_rect(const Matrix32& p_transform);
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index 5be6045d50..58abb71a12 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -3290,6 +3290,7 @@ RID RasterizerGLES2::render_target_create(){
texture->active=false;
texture->total_data_size=0;
texture->render_target=rt;
+ texture->ignore_mipmaps=true;
rt->texture_ptr=texture;
rt->texture=texture_owner.make_rid( texture );
rt->texture_ptr->active=false;
@@ -3320,6 +3321,7 @@ void RasterizerGLES2::render_target_set_size(RID p_render_target,int p_width,int
if (p_width==0 || p_height==0)
return;
+
rt->width=p_width;
rt->height=p_height;
@@ -3560,11 +3562,14 @@ void RasterizerGLES2::clear_viewport(const Color& p_color) {
};
-void RasterizerGLES2::set_render_target(RID p_render_target) {
+void RasterizerGLES2::set_render_target(RID p_render_target, bool p_transparent_bg, bool p_vflip) {
+
+
if (!p_render_target.is_valid()) {
glBindFramebuffer(GL_FRAMEBUFFER,base_framebuffer);
current_rt=NULL;
+ current_rt_vflip=false;
} else {
RenderTarget *rt = render_target_owner.get(p_render_target);
@@ -3572,6 +3577,8 @@ void RasterizerGLES2::set_render_target(RID p_render_target) {
ERR_FAIL_COND(rt->fbo==0);
glBindFramebuffer(GL_FRAMEBUFFER,rt->fbo);
current_rt=rt;
+ current_rt_transparent=p_transparent_bg;
+ current_rt_vflip=!p_vflip;
}
}
@@ -3637,6 +3644,9 @@ void RasterizerGLES2::begin_shadow_map( RID p_light_instance, int p_shadow_pass
void RasterizerGLES2::set_camera(const Transform& p_world,const CameraMatrix& p_projection) {
camera_transform=p_world;
+ if (current_rt && current_rt_vflip) {
+ camera_transform.basis.set_axis(1,-camera_transform.basis.get_axis(1));
+ }
camera_transform_inverse=camera_transform.inverse();
camera_projection=p_projection;
camera_plane = Plane( camera_transform.origin, camera_transform.basis.get_axis(2) );
@@ -3741,7 +3751,7 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
}
//print_line("compiled fragment: "+fragment_code);
- //print_line("compiled fragment globals: "+fragment_globals);
+ // ("compiled fragment globals: "+fragment_globals);
//print_line("UCF: "+itos(p_shader->uniforms.size()));
@@ -5090,6 +5100,12 @@ void RasterizerGLES2::_setup_skeleton(const Skeleton *p_skeleton) {
void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Transform& p_view_transform, const Transform& p_view_transform_inverse,const CameraMatrix& p_projection,bool p_reverse_cull,bool p_fragment_light,bool p_alpha_pass) {
+ if (current_rt && current_rt_vflip) {
+ p_reverse_cull=!p_reverse_cull;
+ glFrontFace(GL_CCW);
+
+ }
+
const Material *prev_material=NULL;
uint16_t prev_light=0x777E;
const Geometry *prev_geometry_cmp=NULL;
@@ -5349,6 +5365,9 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
//print_line("shaderchanges: "+itos(p_alpha_pass)+": "+itos(_rinfo.shader_change_count));
+ if (current_rt && current_rt_vflip) {
+ glFrontFace(GL_CW);
+ }
};
@@ -5755,6 +5774,10 @@ void RasterizerGLES2::end_scene() {
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ } else if (current_rt && current_rt_transparent) {
+
+ glClearColor(0,0,0,0);
+ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
} else if (current_env) {
@@ -5889,6 +5912,7 @@ void RasterizerGLES2::end_scene() {
copy_shader.set_conditional(CopyShaderGLES2::USE_GAMMA,current_env && current_env->fx_enabled[VS::ENV_FX_GAMMA]);
copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW,current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]);
copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,current_env && current_env->fx_enabled[VS::ENV_FX_HDR]);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_NO_ALPHA,true);
copy_shader.bind();
//copy_shader.set_uniform(CopyShaderGLES2::SOURCE,0);
@@ -5932,6 +5956,8 @@ void RasterizerGLES2::end_scene() {
copy_shader.set_conditional(CopyShaderGLES2::USE_GAMMA,false);
copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW,false);
copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,false);
+ copy_shader.set_conditional(CopyShaderGLES2::USE_NO_ALPHA,false);
+
material_shader.set_conditional(MaterialShaderGLES2::USE_HDR,false);
@@ -6266,17 +6292,26 @@ void RasterizerGLES2::canvas_begin() {
_set_color_attrib(Color(1,1,1));
Transform canvas_transform;
canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
- canvas_transform.scale( Vector3( 2.0f / viewport.width, -2.0f / viewport.height, 1.0f ) );
+ float csy = 1.0;
+ if (current_rt && current_rt_vflip)
+ csy = -1.0;
+
+ canvas_transform.scale( Vector3( 2.0f / viewport.width, csy * -2.0f / viewport.height, 1.0f ) );
canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,Matrix32());
canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32());
canvas_opacity=1.0;
-
canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
}
+
+void RasterizerGLES2::canvas_disable_blending() {
+
+ glDisable(GL_BLEND);
+}
+
void RasterizerGLES2::canvas_set_opacity(float p_opacity) {
canvas_opacity = p_opacity;
diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h
index 52c4c8d681..f18bdd1ff7 100644
--- a/drivers/gles2/rasterizer_gles2.h
+++ b/drivers/gles2/rasterizer_gles2.h
@@ -1047,6 +1047,8 @@ class RasterizerGLES2 : public Rasterizer {
RenderTarget *current_rt;
+ bool current_rt_transparent;
+ bool current_rt_vflip;
ViewportData *current_vd;
@@ -1344,7 +1346,7 @@ public:
virtual void set_viewport(const VS::ViewportRect& p_viewport);
- virtual void set_render_target(RID p_render_target);
+ virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false);
virtual void clear_viewport(const Color& p_color);
virtual void capture_viewport(Image* r_capture);
@@ -1371,6 +1373,8 @@ public:
/* CANVAS API */
virtual void canvas_begin();
+ virtual void canvas_disable_blending();
+
virtual void canvas_set_opacity(float p_opacity);
virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode);
virtual void canvas_begin_rect(const Matrix32& p_transform);
diff --git a/drivers/gles2/shaders/copy.glsl b/drivers/gles2/shaders/copy.glsl
index 2ed19cbd65..d4b0c31b7d 100644
--- a/drivers/gles2/shaders/copy.glsl
+++ b/drivers/gles2/shaders/copy.glsl
@@ -248,6 +248,11 @@ void main() {
#ifdef USE_ENERGY
color.rgb*=energy;
#endif
- gl_FragColor = color;
+
+#ifdef USE_NO_ALPHA
+ color.a=1.0;
+#endif
+
+ gl_FragColor = color;
}
diff --git a/drivers/openssl/stream_peer_ssl.cpp b/drivers/openssl/stream_peer_ssl.cpp
index aaedd7dde9..19a17ea0cd 100644
--- a/drivers/openssl/stream_peer_ssl.cpp
+++ b/drivers/openssl/stream_peer_ssl.cpp
@@ -1,111 +1,97 @@
#include "stream_peer_ssl.h"
-int StreamPeerSSL::bio_create( BIO *b ) {
- b->init = 1;
- b->num = 0;
- b->ptr = NULL;
- b->flags = 0;
- return 1;
-}
-
-int StreamPeerSSL::bio_destroy( BIO *b ) {
-
- if ( b == NULL ) return 0;
- b->ptr = NULL; /* sb_tls_remove() will free it */
- b->init = 0;
- b->flags = 0;
- return 1;
-}
-
-int StreamPeerSSL::bio_read( BIO *b, char *buf, int len ) {
-
- if ( buf == NULL || len <= 0 ) return 0;
-
- StreamPeerSSL * sp = (StreamPeerSSL*)b->ptr;
+Error StreamPeerSSL::connect(const String &p_host,int p_port,int p_flags) {
- if (sp->base.is_null())
- return 0;
-
-
-
- BIO_clear_retry_flags( b );
-
- Error err;
- int ret=0;
- if (sp->block) {
- err = sp->base->get_data((const uint8_t*)buf,len);
- if (err==OK)
- ret=len;
- } else {
-
- err = sp->base->get_partial_data((const uint8_t*)buf,len,ret);
- if (err==OK && ret!=len) {
- BIO_set_retry_write( b );
- }
+ // Set up a SSL_CTX object, which will tell our BIO object how to do its work
+ ctx = SSL_CTX_new(SSLv23_client_method());
+ // Create our BIO object for SSL connections.
+ BIO* bio = BIO_new_ssl_connect(ctx);
+ // Failure?
+ if (bio == NULL) {
+ // We need to free up the SSL_CTX before we leave.
+ ERR_FAIL_COND_V(bio==NULL,ERR_CANT_CREATE);
+ }
+ // Makes ssl point to bio's SSL object.
+ BIO_get_ssl(bio, &ssl);
+ // Set the SSL to automatically retry on failure.
+ SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
+ // We're connection to google.com on port 443.
+ BIO_set_conn_hostname(bio, (p_host+":"+itos(p_port)).utf8().get_data());
+
+ // Same as before, try to connect.
+ if (BIO_do_connect(bio) <= 0) {
+
+ ERR_EXPLAIN("Failed to connect to '"+p_host+"'' port "+itos(p_port));
+ BIO_free_all(bio);
+ SSL_CTX_free(ctx);
+ ERR_FAIL_V(ERR_CANT_CONNECT);
}
- return ret;
-}
-
-int StreamPeerSSL::bio_write( BIO *b, const char *buf, int len ) {
-
- if ( buf == NULL || len <= 0 ) return 0;
-
- StreamPeerSSL * sp = (StreamPeerSSL*)b->ptr;
-
- if (sp->base.is_null())
- return 0;
-
- BIO_clear_retry_flags( b );
+ // Now we need to do the SSL handshake, so we can communicate.
+ if (BIO_do_handshake(bio) <= 0) {
+ ERR_EXPLAIN("Failed to handshake to '"+p_host+"'' port "+itos(p_port));
+ BIO_free_all(bio);
+ SSL_CTX_free(ctx);
+ ERR_FAIL_V(ERR_CANT_CONNECT);
+ }
- Error err;
- int wrote=0;
- if (sp->block) {
- err = sp->base->put_data((const uint8_t*)buf,len);
- if (err==OK)
- wrote=len;
- } else {
- err = sp->base->put_partial_data((const uint8_t*)buf,len,wrote);
- if (err==OK && wrote!=len) {
- BIO_set_retry_write( b );
+ // Create a buffer for grabbing information from the page.
+ char buf[1024];
+ memset(buf, 0, sizeof(buf));
+ // Create a buffer for the reqest we'll send to the server
+ char send[1024];
+ memset(send, 0, sizeof(send));
+ // Create our GET request.
+ strcat(send, "GET / HTTP/1.1\nHost:google.com\nUser Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\nConnection: Close\n\n");
+ // BIO_puts sends a null-terminated string to the server. In this case it's our GET request.
+ BIO_puts(bio, send);
+ // Loop while there's information to be read.
+ while (1) {
+ // BIO_read() reads data from the server into a buffer. It returns the number of characters read in.
+ int x = BIO_read(bio, buf, sizeof(buf) - 1);
+ // If we haven't read in anything, assume there's nothing more to be sent since we used Connection: Close.
+ if (x == 0) {
+ break;
+ }
+ // If BIO_read() returns a negative number, there was an error
+ else if (x < 0) {
+ // BIO_should_retry lets us know if we should keep trying to read data or not.
+ if (!BIO_should_retry(bio)) {
+ printf("\nRead Failed!\n");
+ BIO_free_all(bio);
+ SSL_CTX_free(ctx);
+ return;
+ }
+ }
+ // We actually got some data, without errors!
+ else {
+ // Null-terminate our buffer, just in case
+ buf[x] = 0;
+ // Echo what the server sent to the screen
+ printf("%s", buf);
}
-
}
+ // Free up that BIO object we created.
+ BIO_free_all(bio);
+ // Remember, we also need to free up that SSL_CTX object!
+ SSL_CTX_free(ctx);
+ // Return.
- return wrote;
}
-long StreamPeerSSL::bio_ctrl( BIO *b, int cmd, long num, void *ptr ) {
- if ( cmd == BIO_CTRL_FLUSH ) {
- /* The OpenSSL library needs this */
- return 1;
- }
- return 0;
-}
+void StreamPeerSSL::initialize_ssl() {
-int StreamPeerSSL::bio_gets( BIO *b, char *buf, int len ) {
- return -1;
+ CRYPTO_malloc_init(); // Initialize malloc, free, etc for OpenSSL's use
+ SSL_library_init(); // Initialize OpenSSL's SSL libraries
+ SSL_load_error_strings(); // Load SSL error strings
+ ERR_load_BIO_strings(); // Load BIO error strings
+ OpenSSL_add_all_algorithms(); // Load all available encryption algorithms
}
-int StreamPeerSSL::bio_puts( BIO *b, const char *str ) {
- return StreamPeerSSL::bio_write( b, str, strlen( str ) );
-}
+void StreamPeerSSL::finalize_ssl(){
-BIO_METHOD StreamPeerSSL::bio_methods =
-{
- ( 100 | 0x400 ), /* it's a source/sink BIO */
- "sockbuf glue",
- StreamPeerSSL::bio_write,
- StreamPeerSSL::bio_read,
- StreamPeerSSL::bio_puts,
- StreamPeerSSL::bio_gets,
- StreamPeerSSL::bio_ctrl,
- StreamPeerSSL::bio_create,
- StreamPeerSSL::bio_destroy
-};
-StreamPeerSSL::StreamPeerSSL() {
}
diff --git a/drivers/openssl/stream_peer_ssl.h b/drivers/openssl/stream_peer_ssl.h
index a126f6122c..74866c2da4 100644
--- a/drivers/openssl/stream_peer_ssl.h
+++ b/drivers/openssl/stream_peer_ssl.h
@@ -1,26 +1,43 @@
#ifndef STREAM_PEER_SSL_H
#define STREAM_PEER_SSL_H
+#ifdef OPENSSL_ENABLED
+
#include "io/stream_peer.h"
+#include <openssl/applink.c> // To prevent crashing (see the OpenSSL FAQ)
+#include <openssl/bio.h> // BIO objects for I/O
+#include <openssl/ssl.h> // SSL and SSL_CTX for SSL connections
+#include <openssl/err.h> // Error reporting
+#include <stdio.h> // If you don't know what this is for stop reading now.
class StreamPeerSSL : public StreamPeer {
OBJ_TYPE(StreamPeerSSL,StreamPeer);
+public:
+
+ enum ConnectFlags {
+
+ CONNECT_FLAG_BUG_WORKAROUNDS=1,
+ CONNECT_FLAG_NO_SSLV2=2,
+ CONNECT_FLAG_NO_SSLV3=4,
+ CONNECT_FLAG_NO_TLSV1=8,
+ CONNECT_FLAG_NO_COMPRESSION=16,
+ };
- Ref<StreamPeer> base;
- bool block;
- static BIO_METHOD bio_methods;
+ SSL_CTX* ctx;
+ SSL* ssl;
+ BIO* bio;
- static int bio_create( BIO *b );
- static int bio_destroy( BIO *b );
- static int bio_read( BIO *b, char *buf, int len );
- static int bio_write( BIO *b, const char *buf, int len );
- static long bio_ctrl( BIO *b, int cmd, long num, void *ptr );
- static int bio_gets( BIO *b, char *buf, int len );
- static int bio_puts( BIO *b, const char *str );
public:
+
+
+ Error connect(const String &p_host,int p_port);
+ static void initialize_ssl();
+ static void finalize_ssl();
+
StreamPeerSSL();
};
+#endif
#endif // STREAM_PEER_SSL_H