Example #1
0
	def __Invalidate(self, checkComplete: bool):
		if self._id:
			self.Delete(False)

		self._id = GLHelper.CreateFramebuffer()

		for idx, attachmentSpec in enumerate(self.colorAttachmentSpecs):
			texture = self.__CreateFramebufferAttachment(attachmentSpec)
			self.__AttachFramebufferTexture(texture, idx, False)
			self.colorAttachments.append(texture)
		 
		if self.depthAttachmentSpec.textureFormat:
			texture = self.__CreateFramebufferAttachment(self.depthAttachmentSpec)
			self.__AttachFramebufferTexture(texture, 0, True)
			self.depthAttachment = texture
		
		if len(self.colorAttachments) > 1:
			if len(self.colorAttachments) > 4:
				raise GraphicsException("Cannot use more than 4 framebuffer texture attachments.")
			
			drawBuffers = [GL.GL_COLOR_ATTACHMENT0, GL.GL_COLOR_ATTACHMENT1, GL.GL_COLOR_ATTACHMENT2, GL.GL_COLOR_ATTACHMENT3]
			GL.glNamedFramebufferDrawBuffers(self._id, len(self.colorAttachments), drawBuffers)
		elif len(self.colorAttachments) == 0:
			GL.glNamedFramebufferDrawBuffer(self._id, GL.GL_NONE)
		else: #means we have only one color attachment
			GL.glNamedFramebufferDrawBuffer(self._id, GL.GL_COLOR_ATTACHMENT0) #assume we use 0th index for our attachment
		
		if checkComplete:
			status = GL.glCheckNamedFramebufferStatus(self._id, GL.GL_FRAMEBUFFER)
			if status != GL.GL_FRAMEBUFFER_COMPLETE:
				raise GraphicsException(f"Framebuffer incomplete: {_GL_FB_ERROR_CODE_NAMES_MAP[status]}.")