void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(GLenum target, GLenum attachment)
{
    ASSERT(isBound(target));
    if (!m_object)
        return;

    WebGLAttachment* attachmentObject = getAttachment(attachment);
    if (attachmentObject) {
        attachmentObject->onDetached(context()->contextGL());
        m_attachments.remove(attachment);
        drawBuffersIfNecessary(false);
        switch (attachment) {
        case GL_DEPTH_STENCIL_ATTACHMENT:
            attach(target, GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT);
            attach(target, GL_STENCIL_ATTACHMENT, GL_STENCIL_ATTACHMENT);
            break;
        case GL_DEPTH_ATTACHMENT:
        case GL_STENCIL_ATTACHMENT:
            attach(target, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH_STENCIL_ATTACHMENT);
            break;
        }
    }
}
void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(GLenum target, WebGLSharedObject* attachment)
{
    ASSERT(isBound(target));
    if (!m_object)
        return;
    if (!attachment)
        return;

    bool checkMore = true;
    while (checkMore) {
        checkMore = false;
        for (const auto& it : m_attachments) {
            WebGLAttachment* attachmentObject = it.value.get();
            if (attachmentObject->isSharedObject(attachment)) {
                GLenum attachmentType = it.key;
                attachmentObject->unattach(context()->webContext(), target, attachmentType);
                removeAttachmentFromBoundFramebuffer(target, attachmentType);
                checkMore = true;
                break;
            }
        }
    }
}
bool PosixSslServerSocket::bindToPort( void ) {
    struct addrinfo hints;
    struct addrinfo * serverInfo;
    std::string portString;
    bool bound;
    int fd;

    if( isBound() ) {
        bound = true;
    } else {
        bound = false;
        memset(&hints,0,sizeof hints);
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_flags = AI_PASSIVE;
        portString = std::to_string(getPort());
        if( getaddrinfo(nullptr,portString.c_str(),&hints,&serverInfo) == 0 ) {
            fd = socket(serverInfo->ai_family,serverInfo->ai_socktype,
                        serverInfo->ai_protocol);
            if( fd >= 0 ) {
                int yes = 1;

                setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof yes);
                if( bind(fd,serverInfo->ai_addr,serverInfo->ai_addrlen) == 0 &&
                    listen(fd,256) == 0 ) {
                    bound = true;
                    FD_ZERO(&mRfds);
                    FD_SET(fd,&mRfds);
                    setFileDescriptor(fd);
                }
            }
            freeaddrinfo(serverInfo);
        }
    }

    return ( bound );
}
Socket * PosixSslServerSocket::acceptSocket( const std::time_t seconds ) {
    struct sockaddr addr;
    socklen_t addrLength;
    timeval tv;
    Socket * socket;
    int fd;

    socket = nullptr;
    tv.tv_sec = seconds;
    tv.tv_usec = 0;
    FD_ZERO(&mRfds);
    FD_SET(mFileDescriptor,&mRfds);
    if( isBound() &&
        select(mFileDescriptor + 1,&mRfds,nullptr,nullptr,&tv) > 0 ) {
        memset(&addr,0,sizeof addr);
        memset(&addrLength,0,sizeof addrLength);
        fd = accept(mFileDescriptor,&addr,&addrLength);
        if( fd >= 0 ) {
            socket = allocateSocket(fd);
        }
    }

    return ( socket );
}
Exemple #5
0
bool 
SocketWrapper::bind(
    const struct sockaddr *saddr, 
    socklen_t addrlen)
{
    if (!saddr) {
        return false;
    }

    if (isBound()) {
        HAGGLE_ERR("Already bound.\n");
        return false;
    }

    if (::bind(sock, saddr, addrlen) == SOCKET_ERROR) {
        HAGGLE_ERR("Could not bind socket: %s\n", 
                    STRERROR(ERRNO));
        return false;
    }

    setBound(true);

    return true;
}
  //go throught the list of objects that need to be rendered and render them
  void Engine::Render()
  { //int probug = 0; //pConsole->Log(_T("DRAW %d"),C_NORMAL,probug++); //3

    pRenderer->ClearBuffer(); //clear the screen

    pRenderer->EnableBlendMode();
    pRenderer->BlendMode(BM_ALPHA);

    //pRenderer->CamTranslate(0,0,1);

    //pRenderer->Begin3D();
    //pRenderer->DrawCube(Vertex3(0,0,-8),r,10);
    //r+=0.15f;

    //  pRenderer->Begin2D();

    //DRAW FRAME TIME
    //  pRenderer->DrawText(Vertex2(10,20,Color(0,1,0)),"RenderTime: %4.2f: Frame Number: %d",fps,nFrameCount);

    //Mouse look
    //pRenderer->CamRotate(camrotx,1.0,0.0,0.0);
    //pRenderer->CamRotate(camroty,0.0,1.0,0.0);
    //WASD Movement
    pRenderer->CamTranslate(-camx,-camy,-camz);

    //TEST

    //3D
    /*
    for(int i = 0;i<1000;i++){
      for (int j = 0; j < 60; j+=4){
        pRenderer->DrawCube(Vertex3(i * 2,0,j,Color(1.0f,1.0f,0.0f)),0,0,Color(1, (i - 1) % 2, (i - 1) % 2));
        pRenderer->DrawCube(Vertex3(i * 2,0,j + 2,Color(1.0f,1.0f,0.0f)),0,0,Color(1, i % 2, i % 2));
      }
    }
    */
    pRenderer->DrawCube(Vertex3(16,10,13,Color(1.0f,1.0f,0.0f)),0,0,Color(1,1,0));
    pRenderer->DrawCube(Vertex3(13,10,16,Color(1.0f,1.0f,0.0f)),0,0,Color(1,0,1));
    pRenderer->DrawCube(Vertex3(16,10,16,Color(1.0f,1.0f,0.0f)),0,0,Color(0,0,1));

    float fvViewMatrix[ 16 ]; 
   // glGetFloatv( GL_MODELVIEW_MATRIX, fvViewMatrix );



    /*
    auto vbo = pResourceMan->Aquire<VBO>("razuleVBO",L"C:\\untitled.obj");
    if (! vbo->HasBeenCreated()){
      pRenderer->BuildVBO(vbo, VBO::STATIC_DRAW);
    }
    pRenderer->DrawVBO(vbo, Vertex3());
    */


    pRenderer->Push2D();

    pEntityMan->Draw(pRenderer);

    auto id = pResourceMan->Aquire<Texture>("testkey",L"C:\\test.png");
    if (!id->isBound()) pRenderer->BuildTexture(id);

   // pRenderer->DrawTexture2D(id,Vertex2(x,y));


    pRenderer->DrawText(Vertex2(10,20,Color(0,1,0)),_T("FPS: %3.0f"),fps);

    //for (int i = 0; i < 16; i+=4)
    //  pRenderer->DrawText(Vertex2(10,40 + i * 8,Color(0,1,0)),_T("%.3f,%.3f,%.3f,%.3f"),fvViewMatrix[i],fvViewMatrix[i + 1],fvViewMatrix[i + 2],fvViewMatrix[i + 3]);


    //DRAW SPRITES

    //2D (no Z buffer)
    //	for (int i=0; i < 200000; i++)
    //	pRenderer->DrawTriangle(Vertex2(i,100,Color(.0f,1.0f,0.0f)),
    //							Vertex2(200+i,200+fps,Color(1.0f,0.0f,0.0f)),
    //							Vertex2(100+i,0,Color(0.0f,0.0f,1.0f)));

    if (id != 0)
      pRenderer->BeginTexture(id);

    if (input[32]){
      pRenderer->DrawRectangle(
        Vertex2(100,100,Color(1)),
        Vertex2(410,100,Color(0)),
        Vertex2(410,410,Color(1)),
        Vertex2(100,410,Color(0)));
    }

    pRenderer->EndTexture();
    pRenderer->DrawLine(Vertex2(0,600,Color(0.0f,1.0f,0.0f)),
      Vertex2(1280,600,Color(1.0f,1.0f,0.0f))
      );

    //  pRenderer->DrawTexture2D(sp->GetNextSprite(),Vertex2(640,360));
    // pRenderer->DrawTexture2D(pTextureMan->Texture(_T("data\\textures\\Kumori.tga")),Vertex2(200 + nFrameCount % 60,200));

    // pRenderer->DrawTexture2D(pTextureMan->Texture("icephoenix.tga"),Vertex2(150,100));


    //END TEST


    //DRAW CONSOLE
    pConsole->Draw(pRenderer);

    pRenderer->Pop2D();

    pRenderer->DisableBlendMode();
    pRenderer->SwapBuffer(); //update buffers
  }
CNode* CGraphPrim::getBoundFrame( CParentNode *parent )
{
	return (isBound() && parent) ? parent->GetChild( GetBindToFrame() - 1 ) : 0;
}
Exemple #8
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void Texture::setupTextureParamsFromSampler(OpenGLContext* oglContext, const Sampler& sampler) const
{
    CVF_ASSERT(oglContext);
    CVF_ASSERT(isBound(oglContext));

    cvfGLint oglWrapS = GL_CLAMP_TO_EDGE;
    cvfGLint oglWrapT = GL_CLAMP_TO_EDGE;
    cvfGLint oglMinFilter = GL_NEAREST;
    cvfGLint oglMagFilter = GL_NEAREST;

    switch(sampler.wrapModeS())
    {
        case Sampler::CLAMP_TO_EDGE:             oglWrapS = GL_CLAMP_TO_EDGE; break;
        case Sampler::REPEAT:                    oglWrapS = GL_REPEAT; break;
        case Sampler::CLAMP_TO_BORDER:
#ifdef CVF_OPENGL_ES
                                                 CVF_FAIL_MSG("CLAMP_TO_BORDER not supported"); break;
#else            
                                                 oglWrapS = GL_CLAMP_TO_BORDER; break;
#endif
        case Sampler::MIRRORED_REPEAT:           oglWrapS = GL_MIRRORED_REPEAT; break;
    }

    switch(sampler.wrapModeT())
    {
        case Sampler::CLAMP_TO_EDGE:             oglWrapT = GL_CLAMP_TO_EDGE; break;
        case Sampler::REPEAT:                    oglWrapT = GL_REPEAT; break;
#ifdef CVF_OPENGL_ES
        case Sampler::CLAMP_TO_BORDER:           CVF_FAIL_MSG("CLAMP_TO_BORDER not supported"); break;
#else            
        case Sampler::CLAMP_TO_BORDER:           oglWrapT = GL_CLAMP_TO_BORDER; break;
#endif
        case Sampler::MIRRORED_REPEAT:           oglWrapT = GL_MIRRORED_REPEAT; break;
    }

    switch(sampler.minFilter())
    {
        case Sampler::NEAREST:                   oglMinFilter = GL_NEAREST; break;
        case Sampler::LINEAR:                    oglMinFilter = GL_LINEAR; break;
        case Sampler::NEAREST_MIPMAP_NEAREST:    oglMinFilter = GL_NEAREST_MIPMAP_NEAREST; break;
        case Sampler::NEAREST_MIPMAP_LINEAR:     oglMinFilter = GL_NEAREST_MIPMAP_LINEAR; break;
        case Sampler::LINEAR_MIPMAP_NEAREST:     oglMinFilter = GL_LINEAR_MIPMAP_NEAREST; break;
        case Sampler::LINEAR_MIPMAP_LINEAR:      oglMinFilter = GL_LINEAR_MIPMAP_LINEAR; break;
    }

    switch(sampler.magFilter())
    {
        case Sampler::NEAREST:                   oglMagFilter = GL_NEAREST; break;
        case Sampler::LINEAR:                    oglMagFilter = GL_LINEAR; break;
        case Sampler::NEAREST_MIPMAP_NEAREST:    
        case Sampler::NEAREST_MIPMAP_LINEAR:     
        case Sampler::LINEAR_MIPMAP_NEAREST:     
        case Sampler::LINEAR_MIPMAP_LINEAR:      CVF_FAIL_MSG("Illegal mag format"); break;
    }

    cvfGLenum textureType = textureTypeOpenGL();
    glTexParameteri(textureType, GL_TEXTURE_WRAP_S, oglWrapS);
    glTexParameteri(textureType, GL_TEXTURE_WRAP_T, oglWrapT);
    glTexParameteri(textureType, GL_TEXTURE_MIN_FILTER, oglMinFilter);
    glTexParameteri(textureType, GL_TEXTURE_MAG_FILTER, oglMagFilter);

    // HACK
#ifndef CVF_OPENGL_ES
    if (m_internalFormat == DEPTH_COMPONENT16 || m_internalFormat == DEPTH_COMPONENT24 || m_internalFormat == DEPTH_COMPONENT32)
    {
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
    }
#endif

    // Set these to openGL 
    //  TODO  TEXTURE_WRAP_R, TEXTURE_BORDER_COLOR, TEXTURE_MIN_LOD, TEXTURE_MAX_LOD, TEXTURE_LOD_BIAS, 
    //   TEXTURE_COMPARE_MODE, TEXTURE_COMPARE_FUNC

    CVF_CHECK_OGL(oglContext);
}
void PosixTcpServerSocket::stopListening( void ) {
    if( isBound() ) {
        close(mFileDescriptor);
        setFileDescriptor(-1);
    }
}
//==============================================================================
// PlainDatagramSocketImpl::send
//
//==============================================================================
void PlainDatagramSocketImpl::send(const DatagramPacket& p)
{
	testSocketIsValid();

	int flags = 0;
	struct sockaddr* to=0;
	struct sockaddr_in sa;

	if(isConnected())
	{
		if(p.getAddress() && !(m_rpRemoteAddr->equals(*(p.getAddress()))))
		{
			throw IllegalArgumentException(QC_T("Address in datagram packet does not match connected address"));
		}
		if(p.getPort()!= -1 && p.getPort()!=m_remotePort)
		{
			throw IllegalArgumentException(QC_T("Port in datagram packet does not match connected port"));
		}
	}
	else
	{
		//
		// If the socket is not connected, then the passed datagram packet must contain
		// valid information.
		//
		if(!p.getAddress() || p.getPort()==-1)
		{
			throw IllegalArgumentException(QC_T("datagram packet does not contain required address/port information"));
		}
		//
		// Use the InetAddress and port contained in the packet to 
		// create and initialize a sockaddr_in structure.
		//
		::memset(&sa, 0, sizeof(sa));
		sa.sin_family = AF_INET;
		sa.sin_port = htons(p.getPort()); // convert port to network byte order 
		::memcpy(&sa.sin_addr, p.getAddress()->getAddress(), p.getAddress()->getAddressLength());
		to = reinterpret_cast<struct sockaddr*>(&sa);
	}

	if(Tracer::IsEnabled())
	{
		Tracer::TraceBytes(Tracer::Net, Tracer::Low, QC_T("Datagram send:"), p.getData(), p.getLength());
	}

	int rc = ::sendto(m_rpSocketDescriptor->getFD(),
	                  (const char*) p.getData(),
	                  p.getLength(),
	                  flags,
	                  to,
	                  to ? sizeof(struct sockaddr_in) : 0);

	if(rc<0)
	{
		static const String err(QC_T("error calling sendto "));
		String errMsg = err + NetUtils::GetSocketErrorString();
		throw SocketException(errMsg);
	}

	//
	// When an unbound datagram socket is used to send data, the system will allocate
	// it an address and ephemeral port.  Let's see what weve been given!
	//
	if(!isBound())
	{
	}
}
bool InputFilter::acceptButton (lua_State *L, const std::string &ev)
{
    ensureAlive();
    char kind = ev[0];
    std::string button = &ev[1];

    if (kind == '+') {

        std::vector<Combo> found;
        for (unsigned i=0 ; i<8 ; ++i) {
            const Combo &c = combos[i];
            // ignore prefixes that do not apply given current modifier status
            if (c.ctrl && !input_filter_pressed("Ctrl")) continue;
            if (c.alt && !input_filter_pressed("Alt")) continue;
            if (c.shift && !input_filter_pressed("Shift")) continue;
            if (isBound(c.prefix + button)) found.push_back(c);
        }
        // if no bindings match, fall through
        if (found.size() == 0) return false;

        // should not already be down
        APP_ASSERT(!isButtonPressed(button));

        const Combo &c = found[0];
        
        down[button] = c.prefix;

        std::string bind = c.prefix + button;

        const Callback &cb = buttonCallbacks.find(bind)->second;
        
        const LuaPtr &func = cb.down;

        if (!func.isNil()) {
            triggerFunc(L, bind, func);
        }

    } else if (kind == '-' || kind == '=') {

        ButtonStatus::iterator earlier = down.find(button);

        // Maybe some lower filter has it bound with fewer modifiers.
        if (earlier == down.end()) return false;

        const std::string &prefix = earlier->second;

        std::string bind = prefix + button;

        // If it's down, there must be a callback for it
        const Callback &cb = buttonCallbacks.find(bind)->second;

        if (kind == '-') {
            down.erase(button);
        }

        const LuaPtr &func = kind == '-' ? cb.up : cb.repeat;
        if (!func.isNil()) {
            triggerFunc(L, bind, func);
        }

    } else if (kind == ':') {

        // Potentially let these go to the HUD.
        return false;
    } else {
        CERR << "Unrecognized kind: \"" << std::string(1, kind) << "\"" << std::endl;
    }

    return true;
}
Exemple #12
0
sp<InetSocketAddress> ServerSocket::getLocalSocketAddress() const {
    if (!isBound()) {
        return nullptr;
    }
    return new InetSocketAddress(mLocalAddress, getLocalPort());
}
Exemple #13
0
int32_t ServerSocket::getLocalPort() const {
    if (!isBound()) {
        return -1;
    }
    return mLocalPort;
}
Exemple #14
0
sp<InetAddress> ServerSocket::getInetAddress() const {
    if (!isBound()) {
        return nullptr;
    }
    return mLocalAddress;
}