Jelajahi Sumber

Fix style errors (please don't make me do this)

jp9000 11 tahun lalu
induk
melakukan
0e9b13fcf9

+ 38 - 31
libobs-d3d11/d3d11-subsystem.cpp

@@ -959,7 +959,8 @@ void device_setcuberendertarget(device_t device, texture_t tex, int side,
 	device->context->OMSetRenderTargets(1, &rt, zstencil->view);
 }
 
-inline void gs_device::CopyTex(ID3D11Texture2D *dst, uint32_t dst_x, uint32_t dst_y,
+inline void gs_device::CopyTex(ID3D11Texture2D *dst,
+		uint32_t dst_x, uint32_t dst_y,
 		texture_t src, uint32_t src_x, uint32_t src_y,
 		uint32_t src_w, uint32_t src_h)
 {
@@ -968,22 +969,21 @@ inline void gs_device::CopyTex(ID3D11Texture2D *dst, uint32_t dst_x, uint32_t ds
 
 	gs_texture_2d *tex2d = static_cast<gs_texture_2d*>(src);
 
-	if(dst_x == 0 && dst_y == 0 && src_x == 0 && src_y == 0 && src_w == 0 && src_h == 0)
-	{
+	if (dst_x == 0 && dst_y == 0 &&
+	    src_x == 0 && src_y == 0 &&
+	    src_w == 0 && src_h == 0) {
 		context->CopyResource(dst, tex2d->texture);
-	}
-	else
-	{
+	} else {
 		D3D11_BOX sbox;
 
 		sbox.left = src_x;
-		if(src_w > 0)
+		if (src_w > 0)
 			sbox.right = src_x + src_w;
 		else
 			sbox.right = tex2d->width - 1;
 
 		sbox.top = src_y;
-		if(src_h > 0)
+		if (src_h > 0)
 			sbox.bottom = src_y + src_h;
 		else
 			sbox.bottom = tex2d->height - 1;
@@ -991,49 +991,56 @@ inline void gs_device::CopyTex(ID3D11Texture2D *dst, uint32_t dst_x, uint32_t ds
 		sbox.front = 0;
 		sbox.back = 1;
 
-		context->CopySubresourceRegion(dst, 0, dst_x, dst_y, 0, tex2d->texture, 0, &sbox);
+		context->CopySubresourceRegion(dst, 0, dst_x, dst_y, 0,
+				tex2d->texture, 0, &sbox);
 	}
 }
 
 void device_copy_texture_region(device_t device,
-	texture_t dst, uint32_t dst_x, uint32_t dst_y,
-	texture_t src, uint32_t src_x, uint32_t src_y,
-	uint32_t src_w, uint32_t src_h)
+		texture_t dst, uint32_t dst_x, uint32_t dst_y,
+		texture_t src, uint32_t src_x, uint32_t src_y,
+		uint32_t src_w, uint32_t src_h)
 {
-	try
-	{
+	try {
 		gs_texture_2d *src2d = static_cast<gs_texture_2d*>(src);
 		gs_texture_2d *dst2d = static_cast<gs_texture_2d*>(dst);
 
-		if(!src)
+		if (!src)
 			throw "Source texture is NULL";
-		if(!dst)
+		if (!dst)
 			throw "Destination texture is NULL";
-		if(src->type != GS_TEXTURE_2D || dst->type != GS_TEXTURE_2D)
+		if (src->type != GS_TEXTURE_2D || dst->type != GS_TEXTURE_2D)
 			throw "Source and destination textures must be a 2D "
-			"textures";
-		if(dst->format != src->format)
+			      "textures";
+		if (dst->format != src->format)
 			throw "Source and destination formats do not match";
 
-		uint32_t nw = (uint32_t)src_w ? (uint32_t)src_w : (src2d->width - src_x);
-		uint32_t nh = (uint32_t)src_h ? (uint32_t)src_h : (src2d->height - src_y);
+		/* apparently casting to the same type that the variable
+		 * already exists as is supposed to prevent some warning
+		 * when used with the conditional operator? */
+		uint32_t copyWidth = (uint32_t)src_w ?
+			(uint32_t)src_w : (src2d->width - src_x);
+		uint32_t copyHeight = (uint32_t)src_h ?
+			(uint32_t)src_h : (src2d->height - src_y);
 
-		if(dst2d->width - dst_x < nw || dst2d->height - dst_y < nh)
+		uint32_t dstWidth  = dst2d->width  - dst_x;
+		uint32_t dstHeight = dst2d->height - dst_y;
+
+		if (dstWidth < copyWidth || dstHeight < copyHeight)
 			throw "Destination texture region is not big "
 			      "enough to hold the source region";
 
-		if(dst_x == 0 && dst_y == 0 && src_x == 0 && src_y == 0 && src_w == 0 && src_h == 0)
-		{
-			nw = 0;
-			nh = 0;
+		if (dst_x == 0 && dst_y == 0 &&
+		    src_x == 0 && src_y == 0 &&
+		    src_w == 0 && src_h == 0) {
+			copyWidth  = 0;
+			copyHeight = 0;
 		}
 
-		gs_texture_2d *tex2d = static_cast<gs_texture_2d*>(dst);
-		device->CopyTex(tex2d->texture, dst_x, dst_y, src, src_x, src_y, nw, nh);
+		device->CopyTex(dst2d->texture, dst_x, dst_y,
+				src, src_x, src_y, copyWidth, copyHeight);
 
-	}
-	catch(const char *error)
-	{
+	} catch(const char *error) {
 		blog(LOG_ERROR, "device_copy_texture (D3D11): %s", error);
 	}
 }

+ 12 - 12
libobs-opengl/gl-helpers.c

@@ -43,6 +43,7 @@ bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
 
 		if (data)
 			data++;
+
 		size   /= 4;
 		width  /= 2;
 		height /= 2;
@@ -85,7 +86,8 @@ static bool gl_copy_fbo(struct gs_device *device,
 	if (!gl_success("glReadBuffer"))
 		goto fail;
 
-	glCopyTexSubImage2D(dst_target, 0, dst_x, dst_y, src_x, src_y, width, height);
+	glCopyTexSubImage2D(dst_target, 0, dst_x, dst_y, src_x, src_y,
+			width, height);
 	if (!gl_success("glCopyTexSubImage2D"))
 		goto fail;
 
@@ -101,31 +103,29 @@ fail:
 }
 
 bool gl_copy_texture(struct gs_device *device,
-					 GLuint dst, GLenum dst_target, uint32_t dst_x, uint32_t dst_y,
-					 GLuint src, GLenum src_target, uint32_t src_x, uint32_t src_y,
-                     uint32_t width, uint32_t height,
-                     enum gs_color_format format)
+		GLuint dst, GLenum dst_target, uint32_t dst_x, uint32_t dst_y,
+		GLuint src, GLenum src_target, uint32_t src_x, uint32_t src_y,
+		uint32_t width, uint32_t height, enum gs_color_format format)
 {
 	bool success = false;
 
 	if (device->copy_type == COPY_TYPE_ARB) {
 		glCopyImageSubData(src, src_target, 0, src_x, src_y, 0,
-						   dst, dst_target, 0, dst_x, dst_y, 0,
+		                   dst, dst_target, 0, dst_x, dst_y, 0,
 		                   width, height, 1);
 		success = gl_success("glCopyImageSubData");
 
 	} else if (device->copy_type == COPY_TYPE_NV) {
 		glCopyImageSubDataNV(src, src_target, 0, src_x, src_y, 0,
-							 dst, dst_target, 0, dst_x, dst_y, 0,
+		                     dst, dst_target, 0, dst_x, dst_y, 0,
 		                     width, height, 1);
 		success = gl_success("glCopyImageSubDataNV");
 
 	} else if (device->copy_type == COPY_TYPE_FBO_BLIT) {
-		if (gl_copy_fbo(device, dst, dst_target, dst_x, dst_y,
-					src, src_target, src_x, src_y,
-					width, height, format))
-			success = true;
-		else
+		success = gl_copy_fbo(device, dst, dst_target, dst_x, dst_y,
+		                              src, src_target, src_x, src_y,
+		                              width, height, format);
+		if (!success)
 			blog(LOG_ERROR, "gl_copy_texture failed");
 	}
 

+ 1 - 2
libobs-opengl/gl-subsystem.c

@@ -233,8 +233,7 @@ swapchain_t device_create_swapchain(device_t device, struct gs_init_data *info)
 		return NULL;
 	}
 
-	if(!gl_platform_init_swapchain(swap))
-	{
+	if (!gl_platform_init_swapchain(swap)) {
 		blog(LOG_ERROR, "gl_platform_init_swapchain  failed");
 		swapchain_destroy(swap);
 		return NULL;

+ 37 - 42
libobs-opengl/gl-x11.c

@@ -26,10 +26,10 @@
 static const int fb_attribs[] = {
 	/* Hardcoded for now... */
 	GLX_STENCIL_SIZE, 8,
-	GLX_DEPTH_SIZE, 24, 
+	GLX_DEPTH_SIZE, 24,
 	GLX_BUFFER_SIZE, 32, /* Color buffer depth */
-	GLX_DOUBLEBUFFER, True,
-	GLX_X_RENDERABLE, True,
+	GLX_DOUBLEBUFFER, true,
+	GLX_X_RENDERABLE, true,
 	GLX_RENDER_TYPE, GLX_RGBA_BIT,
 	None
 };
@@ -39,7 +39,7 @@ static const int ctx_attribs[] = {
 	GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
 #endif
 	GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
-	None, 
+	None,
 };
 
 struct gl_windowinfo {
@@ -69,7 +69,7 @@ extern struct gl_windowinfo *gl_windowinfo_create(struct gs_init_data *info)
 	return wi;
 }
 
-extern void gl_windowinfo_destroy(struct gl_windowinfo *wi) 
+extern void gl_windowinfo_destroy(struct gl_windowinfo *wi)
 {
 	bfree(wi);
 }
@@ -123,9 +123,8 @@ static bool handle_x_error(Display *disp, const char *error_string)
 {
 	XSync(disp, 0);
 
-	if(got_x_error)
-	{
-		if(error_string)
+	if (got_x_error) {
+		if (error_string)
 			blog(LOG_ERROR, "%s", error_string);
 
 		got_x_error = false;
@@ -145,6 +144,7 @@ struct gl_platform *gl_platform_create(device_t device,
 	GLXFBConfig* configs;
 	XWindowAttributes attrs;
 	int screen;
+	int major = 0, minor = 0;
 
 	print_info_stuff(info);
 
@@ -154,8 +154,7 @@ struct gl_platform *gl_platform_create(device_t device,
 		goto fail0;
 	}
 
-	if(!XGetWindowAttributes(display, info->window.id, &attrs))
-	{
+	if (!XGetWindowAttributes(display, info->window.id, &attrs)) {
 		blog(LOG_ERROR, "Failed getting window attributes");
 		goto fail0;
 	}
@@ -173,15 +172,12 @@ struct gl_platform *gl_platform_create(device_t device,
 	}
 
 	/* We require glX version 1.3 */
-	{
-		int major = 0, minor = 0;
-		
-		glXQueryVersion(display, &major, &minor);
-		if (major < 1 || (major == 1 && minor < 3)) {
-			blog(LOG_ERROR, "GLX version found: %i.%i\nRequired: "
-			                "1.3", major, minor);
-			goto fail0;
-		}
+
+	glXQueryVersion(display, &major, &minor);
+	if (major < 1 || (major == 1 && minor < 3)) {
+		blog(LOG_ERROR, "GLX version found: %i.%i\nRequired: "
+				"1.3", major, minor);
+		goto fail0;
 	}
 
 	if (!glx_ext_ARB_create_context) {
@@ -192,12 +188,12 @@ struct gl_platform *gl_platform_create(device_t device,
 	configs = glXChooseFBConfig(display, screen,
 			fb_attribs, &num_configs);
 
-	if(!configs) {
+	if (!configs) {
 		blog(LOG_ERROR, "Attribute list or screen is invalid.");
 		goto fail0;
 	}
 
-	if(num_configs == 0) {
+	if (num_configs == 0) {
 		XFree(configs);
 		blog(LOG_ERROR, "No framebuffer configurations found.");
 		goto fail0;
@@ -212,18 +208,18 @@ struct gl_platform *gl_platform_create(device_t device,
 	/* We just use the first configuration found... as it does everything
 	 * we want at the very least. */
 	plat->context = glXCreateContextAttribsARB(display, plat->fbcfg, NULL,
-			True, ctx_attribs);
-	if(!plat->context) {
+			true, ctx_attribs);
+	if (!plat->context) {
 		blog(LOG_ERROR, "Failed to create OpenGL context.");
 		goto fail0;
 	}
 
-	if(handle_x_error(display, "Failed to create OpenGL context."))
+	if (handle_x_error(display, "Failed to create OpenGL context."))
 		goto fail2;
 
 	device->plat = plat;
 
-	plat->swap.device = device;
+	plat->swap.device               = device;
 	plat->swap.info.window.id       = info->window.id;
 	plat->swap.info.window.display  = display;
 	plat->swap.info.format          = GS_RGBA;
@@ -234,10 +230,10 @@ struct gl_platform *gl_platform_create(device_t device,
 	plat->swap.info.cy              = attrs.height;
 	plat->swap.wi                   = gl_windowinfo_create(info);
 
-	if(!gl_platform_init_swapchain(&plat->swap))
+	if (!gl_platform_init_swapchain(&plat->swap))
 		goto fail2;
 
-	if(!glXMakeCurrent(display, plat->swap.wi->glxid, plat->context)) {
+	if (!glXMakeCurrent(display, plat->swap.wi->glxid, plat->context)) {
 		blog(LOG_ERROR, "Failed to make context current.");
 		goto fail2;
 	}
@@ -252,7 +248,7 @@ struct gl_platform *gl_platform_create(device_t device,
 	/* We assume later that cur_swap is already set. */
 	device->cur_swap = &plat->swap;
 
-	XSync(display, False);
+	XSync(display, false);
 
 	blog(LOG_INFO, "Created new platform data");
 
@@ -299,20 +295,19 @@ bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
 
 	gl_platform_cleanup_swapchain(swap);
 
-	if(!XGetWindowAttributes(display, info->id, &attrs))
-	{
+	if (!XGetWindowAttributes(display, info->id, &attrs)) {
 		blog(LOG_ERROR, "Failed getting window attributes");
 		goto fail;
 	}
 
 	vi = glXGetVisualFromFBConfig(display, plat->fbcfg);
 
-	if(handle_x_error(display, "Failed to get visual from fb config."))
+	if (handle_x_error(display, "Failed to get visual from fb config."))
 		goto fail;
 
 	cmap = XCreateColormap(display, info->id, vi->visual, AllocNone);
 
-	if(handle_x_error(display, "Failed creating colormap"))
+	if (handle_x_error(display, "Failed creating colormap"))
 		goto fail;
 
 	swa.colormap = cmap;
@@ -324,12 +319,12 @@ bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
 	                             CWBorderPixel|CWColormap, &swa);
 	XMapWindow(display, info->int_id);
 
-	if(handle_x_error(display, "Failed creating intermediate X window"))
+	if (handle_x_error(display, "Failed creating intermediate X window"))
 		goto fail;
 
 	info->glxid = glXCreateWindow(display, plat->fbcfg, info->int_id, 0);
 
-	if(handle_x_error(display, "Failed creating intermediate GLX window"))
+	if (handle_x_error(display, "Failed creating intermediate GLX window"))
 		goto fail;
 
 	XFreeColormap(display, cmap);
@@ -341,10 +336,10 @@ fail:
 
 	gl_platform_cleanup_swapchain(swap);
 
-	if(cmap)
+	if (cmap)
 		XFreeColormap(display, cmap);
 
-	if(vi)
+	if (vi)
 		XFree(vi);
 
 	XSetErrorHandler(phandler);
@@ -357,13 +352,13 @@ void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
 	Display *display = swap->wi->display;
 	struct gl_windowinfo *info = swap->wi;
 
-	if(!info)
+	if (!info)
 		return;
 
-	if(info->glxid)
+	if (info->glxid)
 		glXDestroyWindow(display, info->glxid);
 
-	if(info->int_id)
+	if (info->int_id)
 		XDestroyWindow(display, info->int_id);
 
 	info->glxid = 0;
@@ -385,7 +380,7 @@ void device_leavecontext(device_t device)
 {
 	Display *display = device->cur_swap->wi->display;
 
-	if(!glXMakeCurrent(display, None, NULL)) {
+	if (!glXMakeCurrent(display, None, NULL)) {
 		blog(LOG_ERROR, "Failed to reset current context.");
 	}
 }
@@ -396,12 +391,12 @@ void gl_update(device_t device)
 	XID window = device->cur_swap->wi->int_id;
 
 	XResizeWindow(display, window,
-				  device->cur_swap->info.cx, device->cur_swap->info.cy);
+			device->cur_swap->info.cx, device->cur_swap->info.cy);
 }
 
 void device_load_swapchain(device_t device, swapchain_t swap)
 {
-	if(!swap)
+	if (!swap)
 		swap = &device->plat->swap;
 
 	if (device->cur_swap == swap)